Instructions 1. Download the starter code from Mimir ○ Do not change the file names. Otherwise, i t will not be graded. ○ Filenames ■ weatherFunctions.h ■ weatherFunctions.cpp ■ weather.cpp 2. Get...

Programming assignment


Instructions 1. Download the starter code from Mimir ○ Do not change the file names. Otherwise, i t will not be graded. ○ Filenames ■ weatherFunctions.h ■ weatherFunctions.cpp ■ weather.cpp 2. Get started 3. Submit early, submit often on Mimir. Problem Overview You are writing a program that analyzes rainfall data collected from weather stations in different cities over a range of days. ● You will load and analyze rainfall data for different cities for a period of days. ○ Examples of rainfall on a day are ■ 0 inches ■ 0.5 inches ■ 2.8 inches ■ 1 inch ■ 2023 inches ● You will read the data from a file into a table (i.e. a two-dimensional array). ○ Each row corresponds to a city. ○ Each column corresponds to a day. ○ The element in the 2D array at the row r and column c denotes the amount of rain in the city r on day c. ○ Your 2D array must be structured as we have done i n this course. There are other approaches that you might find online, but they are not guaranteed to work with our test cases. ● You will write functions that analyze the data to find averages and maximum values. To support automated grading of your program, as you implement functions ● You must maintain the ordering of the parameters presented. ○ You’ll have to figure out the datatype, etc. for each parameter. ● You must keep the exact function name. ● You must ensure that the function signature (i.e. parameters) results in the function operating as indicated. ● Use data types that match the description. ○ If you need a floating-point number, use a double. ○ If you need an integer, use an int. ○ If you need an index or a size type, use a size_t or unsigned int. ○ If you need a string, use the C++ string class. Allowed Includes: use of an “illegal” header file will result in a zero (0) on the assignment ● iostream ● fstream ● string ● weatherFunctions.h You may assume that the data/input has no errors unless indicated otherwise. It is recommended to use the following compiler flags when testing locally: g ++ -std=c++17 -Wall -Wextra -pedantic-errors To check for memory leaks, add the Address Sanitization flag: g ++ -std=c++17 -Wall -Wextra -pedantic-errors - fsanitize=address,undefined Example This is an example that illustrates the use of the functions you will write. See the detailed function requirements after the example. Start by assigning Table to the null pointer (nullptr) Number of cities to 0 Number of days to 0 Given a file containing the following data (cities1.txt) : 2 3 2.0 0 0.4 0 3.2 8 Passing the values of the table, number of cities, number of days, and the name of that file(c ities1.txt) into add_cities_from_file returns Table 2.0 0 0.4 0 3.2 8 With Other changes ● Number of cities - 2 ● Number of days - 3 Given a file containing the following data (cities2.txt) : 3 3 1.2 0.25 0.3 0 0 0.1 2.3 2.9 4.25 Passing the values of the table (which currently has 2 rows and 3 columns), number of cities (currently 2), number of days (currently 3), and the name of that file (cities.2.txt) into add_cities_from_file returns Table 2.0 0 0.4 0 3.2 8 1.2 0.25 0.3 0 0 0.1 2.3 2.9 4.25 With Other changes ● Number of cities - 5 ● Number of days – 3 Using this table for the following: ● Calling get_average_rainfall_between_days_given_city with start day 1, end day 2, and city index 1 returns 5.6. ● Calling get_average_rainfall_between_days_all_cities with start day 0 and end day 1 returns 1.185. ● Calling get_max_rainfall_all_cities_given_day with day 1 returns 3.2. ● Calling get_max_rainfall_given_city with city index 4 returns 4.25. Calling destroy_table with arguments table and number of cities (5) results in all of the memory for the table being freed/destroyed/deleted/deallocated from the heap. Required Functions You are required to provide these functions, but you may add additional helper functions that support the required functions. add_cities_from_file Input Parameters ● Pointer to a table (i.e. a two-dimensional array) ● number of cities ● number of days ● the filename (as a string) of a file with data in the following format ○ You can assume the data is valid. File Format




Return ● pointer to a new table (i.e. two-dimensional array) on the heap with the new data added ○ If the table is the null pointer ■ create the table ○ Else ■ resize the table and add the new data ● Remember that resizing includes deallocating the old array Other changes ● updates number of cities ● updates number of days Throws ● std::invalid_argument (hereafter “invalid argument”) ○ if unable to open the file ○ If the number of days in the input file i s not equal to the number of days in the existing table destroy_table Input Parameters ● pointer to a table (i.e. two-dimensional array) ● number of cities Return ● None (void) Other changes ● Deallocates table from the heap Throws ● Invalid argument ○ If number of cities is zero get_average_rainfall_between_days_given_city Input Parameters ● pointer to a table (i.e. two-dimensional array) ● number of cities ● number of days ● index of start day ● index of end day ● index of city for which to find the average rainfall Return ● Average rainfall for given city from start day to end day (inclusive) Other changes ● none Throws ● invalid argument ○ Invalid table (table is nullptr) ○ Invalid Index of city (index >= number of cities) ○ Invalid Start Day index (index >= number of days) ○ Invalid End Day index (index >= number of days or i ndex < i="" ndex="" of="" start="" day)="" get_average_rainfall_between_days_all_cities="" input="" parameters="" ●="" pointer="" to="" a="" table="" (i.e.="" two-dimensional="" array)="" ●="" number="" of="" cities="" ●="" number="" of="" days="" ●="" index="" of="" start="" day="" ●="" index="" of="" end="" day="" return="" ●="" average="" rainfall="" for="" all="" cities="" between="" start="" day="" and="" end="" day="" (inclusive)="" other="" changes="" ●="" none="" throws="" ●="" invalid="" argument="" ○="" invalid="" table="" (table="" is="" nullptr)="" ○="" invalid="" start="" day="" index="" (index="">= number of days) ○ Invalid End Day index (index >= number of days or index < index="" of="" start="" day)="" get_max_rainfall_all_cities_given_day="" input="" parameters="" ●="" pointer="" to="" a="" table="" (i.e.="" two-dimensional="" array)="" ●="" number="" of="" cities="" ●="" number="" of="" days="" ●="" index="" of="" the="" day="" for="" which="" to="" find="" the="" maximum="" rainfall="" return="" ●="" maximum="" rainfall="" for="" all="" cities="" for="" the="" given="" day="" other="" changes="" ●="" none="" throws="" ●="" invalid="" argument="" ○="" invalid="" table="" (table="" is="" nullptr)="" ○="" invalid="" number="" of="" cities="" (zero="" cities)="" ○="" invalid="" day="" index="" (index="">= number of days) get_max_rainfall_given_city Input Parameters ● pointer to a table (i.e. two-dimensional array) ● number of cities ● number of days ● index of the city for which to find the maximum rainfall Return ● Maximum rainfall for the specified city for all days Other changes ● none Throws ● invalid argument ○ Invalid table (table is nullptr) ○ Invalid number of days (zero days) ○ Invalid index of city (index >= number of cities)
Oct 28, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here