Write a program that lets the user enter the total rainfall for each of 12 months into a vector of doubles. The program will also have a vector of 12 strings to hold the names of the months. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Part 1 Write main(). In main do the following: (a) Declare a vector of doubles and a vector of strings. Suggested variable name for vector of doubles is rainfall. Suggested variable name for vector of strings is monthNames (b) Store the months in your string vector in the following order: January, February, March, April, May, June, July, August, September, October, November, December. Make sure you write out the month names fully (do not use abbreviations). (c) Get input for 12 doubles from the user to place into the vector of doubles. Each double will be the amount of rain for the month parallel to the string vector of month names. (d) Display the month names and rainfall for the month in a table. You should display the rainfall amounts to two decimal places. At the top of main before you output the table, you should write the following line of code cout << setprecision(2) << fixed << showpoint; For example if the user input was: 2.05 1.17 1.08 4.26 2.98 2.19 1.01 0.79 1.57 3.02 2.90 1.78 then the output would be MONTHLY RAINFALL AMOUNTS January 2.05 February 1.17 March 1.08 April 4.26 May 2.98 June 2.19 July 1.01 August 0.79 September 1.57 October 3.02 November 2.90 December 1.78 Hint: In order to get this table, I used setw(11) and left in the cout stream before inserting the month name. I then used right in the cout stream before inserting the rainfall amount. Also, do not forget to #include Part 2 (a) Write a function called getAverage that takes as a parameter a vector of doubles for the rainfall amounts. The function should calculate the average rainfall for the elements in the vector and return the value. For the above data, the value returned would be 2.07 The header for the function should be: double getAverage(const vector& amounts) (b) Call this function from main to get the average. Display the average after the table of rainfall. There should be one blank line between the rainfall table and the average rainfall information. For the above data, the output should be AVERAGE RAINFALL FOR THE YEAR Average: 2.07 Part 3 (a) Write a function called getMinimum that takes as a parameter a vector of doubles for the rainfall amounts. The function should find the minimum value in the vector and return the index for that value. For the above date, the value return would be 7 The header for the function should be: int getMinimum(const vector& amounts) (b) Call this function from main to get the index of the minimum value. Display the both the month name and amount for the minimum rainfall after the information for the average. There should be one blank line between the average rainfall information and the minimum information. For the above data, the output should be MONTH AND AMOUNT FOR MINIMUM RAINFALL FOR THE YEAR August 0.79 Part 4 (a) Write a function called getMaximum that takes as a parameter a vector of doubles for the rainfall amounts. The function should find the maximum value in the vector and return the index for that value. For the above date, the value return would be 3 The header for the function should be: int getMaximum(const vector& amounts) (b) Call this function from main to get the index of the maximum value. Display the both the month name and amount for the maximum rainfall after the information for the minimum value. There should be one blank line between the minimum rainfall information and the maximum information. For the above data, the output should be MONTH AND AMOUNT FOR MAXIMUM RAINFALL FOR THE YEAR April 4.26
Write a program that lets the user enter the total rainfall for each of 12 months into a
Part 1
Write main(). In main do the following:
(a) Declare a vector of doubles and a vector of strings.
Suggested variable name for vector of doubles is rainfall. Suggested variable name for vector of strings is monthNames
(b) Store the months in your string vector in the following order: January, February, March, April, May, June, July, August, September, October, November, December. Make sure you write out the month names fully (do not use abbreviations).
(c) Get input for 12 doubles from the user to place into the vector of doubles. Each double will be the amount of rain for the month parallel to the string vector of month names.
(d) Display the month names and rainfall for the month in a table.
You should display the rainfall amounts to two decimal places. At the top of main before you output the table, you should write the following line of code
cout << setprecision(2) << fixed << showpoint;
For example if the user input was:
2.05 1.17 1.08 4.26 2.98 2.19 1.01 0.79 1.57 3.02 2.90 1.78
then the output would be
MONTHLY RAINFALL AMOUNTS January 2.05 February 1.17 March 1.08 April 4.26 May 2.98 June 2.19 July 1.01 August 0.79 September 1.57 October 3.02 November 2.90 December 1.78
Hint: In order to get this table, I used setw(11) and left in the cout stream before inserting the month name. I then used right in the cout stream before inserting the rainfall amount.
Also, do not forget to #include <iomanip>
Part 2
(a) Write a function called getAverage that takes as a parameter a vector of doubles for the rainfall amounts. The function should calculate the average rainfall for the elements in the vector and return the value. For the above data, the value returned would be 2.07
The header for the function should be:
double getAverage(const vector<double>& amounts)
(b) Call this function from main to get the average. Display the average after the table of rainfall. There should be one blank line between the rainfall table and the average rainfall information.
For the above data, the output should be
AVERAGE RAINFALL FOR THE YEAR Average: 2.07
Part 3
(a) Write a function called getMinimum that takes as a parameter a vector of doubles for the rainfall amounts. The function should find the minimum value in the vector and return the index for that value. For the above date, the value return would be 7
The header for the function should be:
int getMinimum(const vector<double>& amounts)
(b) Call this function from main to get the index of the minimum value. Display the both the month name and amount for the minimum rainfall after the information for the average. There should be one blank line between the average rainfall information and the minimum information.
For the above data, the output should be
MONTH AND AMOUNT FOR MINIMUM RAINFALL FOR THE YEAR August 0.79
Part 4
(a) Write a function called getMaximum that takes as a parameter a vector of doubles for the rainfall amounts. The function should find the maximum value in the vector and return the index for that value. For the above date, the value return would be 3
The header for the function should be:
int getMaximum(const vector<double>& amounts)
(b) Call this function from main to get the index of the maximum value. Display the both the month name and amount for the maximum rainfall after the information for the minimum value. There should be one blank line between the minimum rainfall information and the maximum information.
For the above data, the output should be
MONTH AND AMOUNT FOR MAXIMUM RAINFALL FOR THE YEAR April 4.26
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Write a program that lets the user enter the total rainfall for each of 12 months into a
Part 1
Write main(). In main do the following:
(a) Declare a vector of doubles and a vector of strings.
Suggested variable name for vector of doubles is rainfall. Suggested variable name for vector of strings is monthNames
(b) Store the months in your string vector in the following order: January, February, March, April, May, June, July, August, September, October, November, December. Make sure you write out the month names fully (do not use abbreviations).
(c) Get input for 12 doubles from the user to place into the vector of doubles. Each double will be the amount of rain for the month parallel to the string vector of month names.
(d) Display the month names and rainfall for the month in a table.
You should display the rainfall amounts to two decimal places. At the top of main before you output the table, you should write the following line of code
cout << setprecision(2) << fixed << showpoint;
For example if the user input was:
2.05 1.17 1.08 4.26 2.98 2.19 1.01 0.79 1.57 3.02 2.90 1.78
then the output would be
MONTHLY RAINFALL AMOUNTS January 2.05 February 1.17 March 1.08 April 4.26 May 2.98 June 2.19 July 1.01 August 0.79 September 1.57 October 3.02 November 2.90 December 1.78
Hint: In order to get this table, I used setw(11) and left in the cout stream before inserting the month name. I then used right in the cout stream before inserting the rainfall amount.
Also, do not forget to #include <iomanip>
Part 2
(a) Write a function called getAverage that takes as a parameter a vector of doubles for the rainfall amounts. The function should calculate the average rainfall for the elements in the vector and return the value. For the above data, the value returned would be 2.07
The header for the function should be:
double getAverage(const vector<double>& amounts)
(b) Call this function from main to get the average. Display the average after the table of rainfall. There should be one blank line between the rainfall table and the average rainfall information.
For the above data, the output should be
AVERAGE RAINFALL FOR THE YEAR Average: 2.07
Part 3
(a) Write a function called getMinimum that takes as a parameter a vector of doubles for the rainfall amounts. The function should find the minimum value in the vector and return the index for that value. For the above date, the value return would be 7
The header for the function should be:
int getMinimum(const vector<double>& amounts)
(b) Call this function from main to get the index of the minimum value. Display the both the month name and amount for the minimum rainfall after the information for the average. There should be one blank line between the average rainfall information and the minimum information.
For the above data, the output should be
MONTH AND AMOUNT FOR MINIMUM RAINFALL FOR THE YEAR August 0.79
Part 4
(a) Write a function called getMaximum that takes as a parameter a vector of doubles for the rainfall amounts. The function should find the maximum value in the vector and return the index for that value. For the above date, the value return would be 3
The header for the function should be:
int getMaximum(const vector<double>& amounts)
(b) Call this function from main to get the index of the maximum value. Display the both the month name and amount for the maximum rainfall after the information for the minimum value. There should be one blank line between the minimum rainfall information and the maximum information.
For the above data, the output should be
MONTH AND AMOUNT FOR MAXIMUM RAINFALL FOR THE YEAR April 4.26
I am struggling to correct the code to produce this ourput:
MONTHLY RAINFALL AMOUNTS
January 2.25
February 1.14
March 1.08
April 4.46
May 2.98
June 2.19
July 1.01
August 0.97
September 1.57
October 3.02
November 2.91
December 1.38
AVERAGE RAINFALL FOR THE YEAR
Average: 2.08