? Do not change the file names. Otherwise, it will not be graded.
? Filenames
? weatherFunctions.h
? weatherFunctions.cpp
? weather.cpp
? We won’t actually grade this, but you can use main to debug.
You are writing a program that analyzes rainfall data collected from weather stations in different cities over a range of days.
? 0 inches
? 0.5 inches
? 2.8 inches
? 1 inch
? 2023 inches
? 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 in this course. There are other approaches that you might find online, but they are not guaranteed to work with our test cases.
To support automated grading of your program, as you implement functions
? If you need an integer, use an int? .?
? If you need an index or a size type, use a size_t ? or? unsigned int? .?
? Do not use 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 exam?
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
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
(?cities1.txt?) into ?add_cities_from_file? ?returns
Table
2.0 |
0 |
0.4 |
0 |
3.2 |
8 |
With Other changes
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
Using this table for the following:
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.
You are required to provide these functions, but you may add additional helper functions that support the required functions.
<number of cities as a positive integer>
<number of days of rainfall data as a positive integer>
<a space-separated list of floating-point rainfall for city 1> …
<a space-separated list of floating-point rainfall for city n>
? create the table
? Else
? resize the table and add the new data
? std::invalid_argument? (hereafter “invalid argument”)
? if unable to open the file
? If the number of days in the input file is not equal to the number of days in the existing table
Return
Other changes
? Invalid argument
? If number of cities is zero
Return
Other changes
? 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 index < index of start day)
Return
? 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)
Return
Other changes
? invalid argument
? Invalid table (table is nullptr)
? Invalid number of cities (zero cities)
? Invalid Day index (index >= number of days)
Return
? invalid argument
? Invalid table (table is nullptr)
? Invalid number of days (zero days)
? Invalid index of city (index >= number of cities)
*main.cpp file*/
#include <iostream>
#include <fstream>
#include <string>
/* #include <weather Functions.h"
//using std::ifstream, std::string; */
using namespace std;
/* cityNum = row/height, dayNum = col/width */
void destroy_table(double** table, unsigned int& cityNum)
{
if (cityNum == 0)
{
throw ...