Question
https://maryash.github.io/135/labs/lab_03.html Help with Task C Please Data on Ashokan water levels In this lab, we will be studying the Ashokan water levels for the year
https://maryash.github.io/135/labs/lab_03.html
Help with Task C Please Data on Ashokan water levels
In this lab, we will be studying the Ashokan water levels for the year 2018. It is available from NYC Open Data. Please follow these instructions to download the dataset:
- Follow the link NYC Open Data Current Reservoir Levels.
- Choose the View Data menu option (it will reload the page).
- Filter data including only the year 2018. To do that:
- Click the blue button Filter
- In its submenu Filter, click Add a New Filter Condition
- Choose Date is between January 1, 2018 and December 31, 2018
- Sort entries by Date in the Ascending order.
- Export the data:
- Click the light blue button Export
- Choose TSV for Excel (it will produce a plain text data file in tab-separated valuesformat).
- Save obtained file Current_Reservoir_Levels.tsv on your hard drive.
Data format
Dont open the datafile in Excel (that can mess up its formatting). Instead, you can open it with your text editor (gedit).
The datafile is a plain text file whose first line is a header followed by rows of data. The entries in each row are separated by the tab symbol, hence the name of the file format: TSV (tab-separated-values). It is the most convenient format for reading by our C++ program.
Each row has five fields: Date, Storage (in billions of gallons) and Elevation (in feet) for the East basin and for the West basin of the reservoir:
Date EastStorage EastElevation WestStorage WestElevation 01/01/2018 59.94 574 32.67 574.33 01/02/2018 59.89 573.99 32.57 574.29 01/03/2018 59.89 573.97 32.44 574.24 01/04/2018 59.9 573.97 32.22 574.07 ...
To read the datafile, we have to open an input file stream (represented by an object of type ifstream, here we called it fin):
ifstream fin("Current_Reservoir_Levels.tsv"); if (fin.fail()) { cerrRemember that the first line in the file is a header line. We have to skip it before we get to process the actual data. We can do that by reading that line into a temporary variable that we can call junk:
string junk; // new string variable getline(fin, junk); // read one line from the fileAfter that, the file can be read line by line. The most idiomatic C++ way to read such well-formatted file until the end would be the following:
while(fin >> date >> eastSt >> eastEl >> westSt >> westEl) { // this loop reads the file line-by-line // extracting 5 values on each iteration fin.ignore(INT_MAX, ' '); //skips to the end of line, //ignorring the remaining columns // for example, to print the date and East basin storage: coutHere, variable date can be of type string, and the others are numeric variables of type double extracting the storage and elevation in East and West basins.
After you are done reading the file, close the stream:
fin.close();Need to include additional header files
The above code is using a new function exit and a stream class ifstream. To make them work, we have to include two new headers at the beginning of the program:
#include #include #include***Task C. Comparing elevations***
Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing East or West, or print Equal if both basins are at the same level.
Example:
$ ./compare Enter starting date: 09/13/2018 Enter ending date: 09/17/2018 09/13/2018 West 09/14/2018 West 09/15/2018 West 09/16/2018 West 09/17/2018 WestExplanation:
Date | East (ft) | West (ft) | |
---|---|---|---|
09/13/2018 | 581.94 | 582.66 | West is higher |
09/14/2018 | 581.8 | 582.32 | West is higher |
09/15/2018 | 581.62 | 581.94 | West is higher |
09/16/2018 | 581.42 | 581.55 | West is higher |
09/17/2018 | 581.16 | 581.2 | West is higher |
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