Question: Program must be done in C++ 1) Write a program that reads data from a text file that contains information about the rainfall amounts during

Program must be done in C++

1) Write a program that reads data from a text file that contains information about the rainfall amounts during a specific period and reports the total and average rainfall for the specified period. The text file will have the year, start month, and end month of the period in the first three lines of the file and then the rainfalls amounts in that period. Hint: First read the year, start and end months from the text file. Then you need a while loop to read the rainfall amounts.

A sample text file data content may look like below.

2016

March

May

1.34

1.02

1.51

0.30

Then, your program should produce a report similar to below and print the report to the screen as well as to an output text file

During March-May 2016

total rainfall was: 3.17

average rainfall was: 0.79

2) Update your program in (1) above by adding two functions to your program such that you have

i) one function to read data from the input text file and calculate the total and the average

ii) and another function to write (save) data to an output text file.

The prototypes of the functions will look like below. Your job is to write the body of these functions and use (call) these function in your main program to complete the required task.

// this function will read the data from input text file referred by inFile

// and calculate the total and average rainfalls

// and save the data read from the text file in the

// reference parameters (total, average, year, startMonth, endMonth) void readData(ifstream &inFile, double &total, double &average, int &year, string &startMonth, string &endMonth);

// this function will save the report to an output text file referred by outFile void saveData(ofstream &outFile, double total, double average, int year, string startMonth, string endMonth);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!