C++ program veryvery urrgent

Aryanp26
LabExam2_Remote3.pdf

CSCE 1030.R03 Lab Exam 2 Fall 2020

When finished, let your TA know you are done as you must check out with your TA before leaving or your work will not be graded and you may receive a 0 for this exam!

1

1. (21 Points) Write a complete, working C++ program called euidA.cpp (where “euid” is

your EUID) that does the following:

• Declare and initialize a global constant named SIZE with the value 50.

• Write a void function called count that accepts two parameters-- a C-string called str

representing a C-string passed to the function and an array of integers called

alphabets to store the count of the letters of the C-string.

• Note that the alphabets array stores 26 counters – one for each letter of the alphabet. Use the same counter for lowercase and uppercase characters. The first element is the counter

for ‘A’ or ‘a’, the second element is the counter for ‘B’ or ‘b’ and so on.

• Inside your function,

o Using a loop of your choice, process one character at a time.

o Test whether the character is an alphabet.

▪ If it is an alphabet, convert the alphabet to uppercase and find its ascii value.

▪ Increment the appropriate counter of the alphabets array.

• Subtract 65 from the ascii value of the character to obtain the index of the array to increment the correct counter.

• Inside your main function:

o Declare a C-string named str and use SIZE as the size of the C-string.

o Declare an array of integers called alphabets of size 26 and initialize all

values with 0.

o Using a suitable message, get the C-string from the user. The user may enter multiple words.

o Call function count and pass the appropriate arguments.

o Inside a loop of your choice, process each element of the alphabets array, one at time.

▪ If the count is non-zero, display the corresponding uppercase characters as well as the counts.

• Due to time constraints, no comments are required in this code.

SAMPLE OUTPUT

$ ./a.out

Enter a C-string:This is a long string

A:1

G:2

H:1

I:3

L:1

N:2

O:1

R:1

S:3

CSCE 1030.R03 Lab Exam 2 Fall 2020

When finished, let your TA know you are done as you must check out with your TA before leaving or your work will not be graded and you may receive a 0 for this exam!

2

T:2

$ ./a.out

Enter a C-string:small string

A:1

G:1

I:1

L:2

M:1

N:1

R:1

S:2

T:1

$ ./a.out

Enter a C-string:test

E:1

S:1

T:2

2. (29 Points) Write a complete, working C++ program called euidB.cpp (where “euid” is

your EUID) that does the following:

• Declare a global constant named NUM_SALES and initialize it with the value of 10.

• Declare and define a function called getHistory of void return type that accepts two

parameters-- a two dimensional array of integers named sales (use NUM_SALES as the

column size), and an integer named days representing the number of days to obtain sales

history for. Note that both the function prototype and function definition are needed.

Inside your function:

o Using a suitable message, ask the user for the number of days to generate sales history for. Assume the maximum number of days is limited to 10 and the user will

enter an appropriate value.

o Using a suitable nested loop, generate seeded random sales values for each sale for each day between 1000 and 2000, inclusive and store the randomly generated sales

in the two-dimensional array.

• Declare and define a function called getAverage of double return type that accepts

two parameters-- a two-dimensional array of integers named sales (use NUM_SALES

as the column size) and an integer named days representing the number of days. Note

that both the function prototype and function definition are needed. Inside your function:

o Compute the average sales across all sales made i.e. across all rows and columns.

o Return the computed average sales.

• Inside your main function

CSCE 1030.R03 Lab Exam 2 Fall 2020

When finished, let your TA know you are done as you must check out with your TA before leaving or your work will not be graded and you may receive a 0 for this exam!

3

o Declare a two-dimensional array of integer type named sales. Use 10 for the

row size and NUM_SALES for the column size.

o Declare an integer named sales_today to store the number of sales made

today.

o Using a loop of your choice, obtain the value of as well as compute the sum of the sales made today.

▪ You do not need to store all the sales made today, so you don’t need an array. Just keep track of the sum.

o Compute the average of the sales made today.

o Call function getHistory with appropriate arguments.

o Call function average to obtain the average sales and compare the returned

value with the average sales computed today.

▪ If the average sales made today is greater than the returned value, display the message

Today, average sales is better than last X days.

▪ Otherwise, display the message.

Today, average sales is not better than last X days.

▪ Here X is replaced by the number of days you computed the history for.

• Due to time constraints, no comments are required in this code.

SAMPLE OUTPUT

$ ./a.out

How many sales made today?3

Enter today's sales:3000 2500 4500

How many days of sales?4

Today, average sales is better than last 4 days.

$ ./a.out

How many sales made today?4

Enter today's sales:100 200 250 400

How many days of sales?6

Today, average sales is not better than last 6 days.

Note that your values may be different due to the randomization in the program.