Answered step by step
Verified Expert Solution
Question
1 Approved Answer
create a Go program that will read monthly rainfall levels for a city, prints those values out in a table, and then prints some statistics.
create a Go program that will read monthly rainfall levels for a city, prints those values out in a table, and then prints some statistics. Specifically, your program should include three functions in addition to main:
(1) Reading the data from a file
- The input data file will be named rainfall.txt and will consist of 12 lines, each containing a floating point number
- The function will have no parameters. It will return an array of 12 floats and an error.
- The function should have 5 separate checks for errors: (1) opening the file, (2) parsing to a float, (3) wrong number of data items in file, (4) closing the file, and (5) scanner error
- In all 5 error cases, the function should return a data array along with the error
- If no errors occur, the function should return the array of 12 items read from the file along with nil
(2) Printing the rainfall table
- This function will have 2 parameters, the array of 12 data items and an array of 12 month names
- The function should print a table of 2 columns, the month followed by the rainfall for that month
- The month column should be left-aligned. The rainfall column should be right-aligned displaying 1 decimal place
- Column headings should print out above the table
(3) Computing some rainfall statistics
- This function will have 1 parameter, the array of 12 data items
- It will return 3 values, the index of the smallest value, the index of the largest value, the monthly average
The main function
- The main function should call each of the 3 functions
- After the table is printed by the second function, main should display the minimum value along with its month name, the maximum value along with its month name, and the average value. All values should be displayed using 1 decimal place.
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