Question: Use nano vim editor, create a Go program that will read monthly rainfall levels for a city, prints those values out in a table, and
Use nano vim editor, 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:
- 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 placeColumn headings should print out above the table
- 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.
NOTES:
All programs must have a comment block at the top of the program.
Constants must used wherever appropriate (hint: the number 12 will appear exactly once in your program)
A comment block should appear at the top of each function.
Additional comments throughout the program should be included where appropriate.
Please show output as well!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
