Question
Write all answers in a Word document and upload the file using the upload option below this question. Be sure to number your question properly.
Write all answers in a Word document and upload the file using the upload option below this question. Be sure to number your question properly.
You are asked to write a program using functions that will read in twelve integers (all between 0 and 49 inclusive) which are monthly rainfall figures of some imaginary place. You will need to read these figures into an array of integers.
Example: For the following sample rainfall figures:-
12 30 10 5 17 15 22 12 11 16 0 21
the histogram drawn will be:-
************
******************************
**********
*****
*****************
***************
**********************
************
***********
****************
*********************
made up of a series of '*'s.
Structure of main() as follows:-
const int ARRAYSIZE = 12; int main() { int rain[ARRAYSIZE], max, min, sum;
TellUser(); //tell the user what the program does GetRainFall(Rain); DrawHistogram(Rain); sum = Calc_Total_Rain(Rain); cout << "Total rainfall for the year is: " << sum << endl; Find_Max_Min(Rain, max, min); cout << "Maximum rainfall: " << max << endl;
cout << "Lowest rainfall: " << min << endl;
return 0; }
Answer the following questions:-
a) Write the function definition for GetRainFall, that should read in twelve values from the user and store in the array Rain. [3 Points]
b) The function DrawHistogram accepts the array Rain as a parameter, goes through all items in array and draws the histogram.
Example to draw through each item in the array, the loop is:-
for (int i = 0; i < ARRAYSIZE; i++) { //missing code
}
And to draw a line of n asterisks, the code is:-
for (int i = 0; i < n; i++) { cout << 'x';
}
where n takes on the value for each of the rainfall figures. Complete this function. [5 Points]
Hint:- You'll have to implement the second loop inside the first.
c) Calc_Total_Rain receives array Rain as parameter and returns the total of the rainfall figures. Write this function. [3 Points]
Note: Variable sum is not initialized in main().
d) Finally, complete the Find_Max_Min function which accepts the array Rain as the first parameter and variables max and min as pass by reference parameters. This function should go through the array elements and determine the maximum and minimum values. [5 Points]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started