Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello can you help me to do this program by C++. each version should be separate

ID: 669967 • Letter: H

Question

Hello can you help me to do this program by C++. each version should be separated.also, without a graph. Thank you

Version 1 (all interactive). Write a program that reads in the average

monthly rainfall for a city for each month of the year and then reads in

the actual monthly rainfall for each of the previous 12 months. The

program then prints out a nicely formatted table showing the rainfall for

each of the previous 12 months as well as how much above or below

average the rainfall was for each month. The average monthly rainfall is

given for the months January, February, and so forth, in order. To obtain

the actual rainfall for the previous 12 months, the program first asks what

the current month is and then asks for the rainfall figures for the previous

12 months. The output should correctly label the months.

There are a variety of ways to deal with the month names. One

straightforward method is to code the months as integers and then do

a conversion before doing the output. A large switch statement is

acceptable in an output function. The month input can be handled in

any manner you wish, as long as it is relatively easy and pleasant for

the user.

After you have completed this program, produce an enhanced version

that also outputs a graph showing the average rainfall and the actual

rainfall for each of the previous 12 months. The graph should be similar

to the one shown in Display 7.8, except that there should be two bar

graphs for each month and they should be labeled as the average rainfall

and the rainfall for the most recent month. Your program should ask the

user whether she or he wants to see the table or the bar graph and then

should display whichever format is requested. Include a loop that allows

the user to see either format as often as the user wishes until the user

requests that the program end.

Version 2 (combines interactive and file output). For a more elaborate

version, also allow the user to request that the table and graph be output

to a file. The file name is entered by the user. This program does

everything that the Version 1 program does, but has this added feature. To

read a file name, you must use material presented in the optional section

of Chapter 5 entitled “File Names as Input.”

Version 3 (all I/O with files). This version is like Version 1 except that

input is taken from a file and the output is sent to a file. Since there is

no user to interact with, there is no loop to allow repeating the

display; both the table and the graph are output to the same file. If this

is a class assignment, ask your instructor for instructions on what file

names to use.

Explanation / Answer

#include <iostream.h>
#include <iomanip.h>
void printMonth(int month);
// PRECONDITION: month holds an integer 1-12
// POSTCONDITION: the corresponding month (Jan, Feb, ..., Dec) has been printed to the standard output.
int main()
{
double rainfall[12]; //this year's rainfall for each month
double averages[12]; //average rainfalls for each month
int currentMonth; //what month is it? 1-based
// Get the average rainfall for each month, Jan-Dec
cout << "Please enter average rainfall for each month" << endl;
for (int i=0; i<12; i++)
{
printMonth(i);
cout << ": ";
cin >> averages[i];
}
// Get the actual rainfall for the previous year; first have to ask what month it is to know what month to start with.
cout << "What is the number of the current month? Jan=1, Feb=2, etc." << endl;
cin >> currentMonth;
cout << "Please enter the rainfall for each month in the previous year" << endl;
int count = 0;
for (int month=currentMonth-1; count < 12; month=(month+1)%12, count++)
{ printMonth(month);
cout << ": ";
cin >> rainfall[month];
}
// Print table showing avgs, actual rainfalls, and deviations from avg for previous 12 months.

void print_month(std::string name, double rainfall,double averages,int currentMonth) {
std::cout.setf(std::ios_base::left);
std::cout << setw(20) << name << setw(20)<< rainfall << setw(20) << averages << setw(20)<< currentMonth
std::endl;
}

} void printMonth(int month)
{
cout.width(8);
switch(month)
{
case 0:
cout << "Jan";
break;
case 1:
cout << "Feb";
break;
case 2:
cout << "March";
break;
case 3:
cout << "April";
break;
case 4:
cout << "May";
break;
case 5:
cout << "June";
break;
case 6:
cout << "July";
break;
case 7:
cout << "Aug";
break;
case 8:
cout << "Sept";
break;
case 9:
cout << "Oct";
break;
case 10:
cout << "Nov";
break;
case 11:
cout << "Dec";
break;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote