Using Files, Total And Average Rainfall Write A Program That

Using Files Total and Average Rainfall Write a Program That Reads In Fr

Create a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. Data for the program can be found in the Rainfall.txt file, which includes the start month, end month, and the rainfall amounts for the months in between.

After reading in the month names, the program will need to read all subsequent rainfall data until EOF (end of file), counting the number of data pieces read in. Using this information, the program should calculate and display the total rainfall for the specified period and the average monthly rainfall.

For example, if the file contains: June September 2.35 1.15 2.03 1.41, the program should output:

During the months of June September the total rainfall was 7.32 inches and the average monthly rainfall was 1.83 inches.

Paper For Above instruction

The objective of this assignment is to develop a program that reads rainfall data from a file, processes the data to compute total and average rainfall over a specified period, and outputs the results in a clear, formatted manner. This task involves file handling, string processing, looping structures, and basic arithmetic operations to facilitate data aggregation and analysis.

Initially, the program should prompt or read from a file the start month and end month names, along with the corresponding monthly rainfall data for the period. The rainfall data is stored in a plain text file (Rainfall.txt), with a structure that begins with the two month names followed by the rainfall figures for each month within that range. An example input might be: June September 2.35 1.15 2.03 1.41. It is essential that the program accurately reads these values, storing the months and subsequent rainfall data in appropriate variables or data structures.

After successfully reading the start and end months, the program should then read all subsequent rainfall data until the end of the file. During this process, it should keep a running total of rainfall amounts and count the number of data entries. This approach ensures that the total rainfall is accurately accumulated regardless of the number of data points, which could vary depending on the months involved.

Once the data reading is complete, the program calculates the average rainfall by dividing the total by the count of data points. It then outputs a statement that clearly indicates the period (from the start month to the end month), the total rainfall, and the average rainfall per month, formatted to display two decimal places for clarity and professionalism.

The implementation of this program demonstrates essential skills in file input/output, string handling, loops, and arithmetic calculations. Proper error handling is also advisable to manage potential issues such as missing or malformed data files, invalid month names, or non-numeric rainfall entries, although explicit requirements on error handling are not specified in this prompt.

By completing this program, the user gains practical experience in file processing, data aggregation, and output formatting, important skills in many programming tasks related to data analysis and reporting.

References

  • Deitel, P. J., & Deitel, H. M. (2017). Java: How to Program. Pearson.
  • Gaddis, T. (2018). Starting Out with Programming Logic and Design. Pearson.
  • Laudon, K. C., & Traver, C. G. (2021). Management Information Systems. Pearson.
  • Knuth, D. E. (1998). The Art of Computer Programming, Volume 1: Fundamental Algorithms. Addison-Wesley.
  • Stroustrup, B. (2013). The C++ Programming Language. Addison-Wesley.
  • Konrad, F. (2019). File Handling in Python. Real Python. https://realpython.com/working-with-files-in-python/
  • O'Neil, P. (2014). Data Analysis and Visualization with Python. DataCamp. https://www.datacamp.com/
  • Gibson, M. (2020). Data Processing in C++. Cplusplus.com. https://www.cplusplus.com/doc/tutorial/
  • Lutz, M. (2013). Learning Python. O'Reilly Media.
  • Montgomery, D. C., & Runger, G. C. (2014). Applied Statistics and Probability for Engineers. Wiley.