Using the date from NYC Open Data Current Reservoir Levels. Filter date between
ID: 3754415 • Letter: U
Question
Using the date from NYC Open Data Current Reservoir Levels.
Filter date between January 1, 2016 and December 31, 2016
Task B. Minimum and maximum storage in 2016
Write a program minmax.cpp that finds the minimum and maximum storage in East basin in 2016.
Example (using made up numbers):
Hint:
The program should read the file line by line, while keeping track of what is the highest and the lowest storage level in the basin so far. In the end, after reading the entire file, the found values will be the minimum and the maximum storage levels for the entire year.
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:
Explanation:
Task D. Reverse chronological order
Write a program reverse-order.cpp which asks the user to input two dates (earlier date then later date). The program should report the West basin elevation for all days in the interval in the reverse chronological order (from the later date to the earlier).
Example:
Hint: If for the previous tasks you did not use arrays, here you really have to read the data into arrays first, and only then report them in the required order.
Date East (ft) West (ft) 09/13/2016 576.28 575.93 East is higher 09/14/2016 576.06 575.79 East is higher 09/15/2016 575.75 575.75 Equal elevation 09/16/2016 575.51 575.61 West is higher 09/17/2016 575.32 575.4 West is higher 3 1 8Explanation / Answer
Task B:
minmax.cpp:
Code:
#include<iostream>
#include <fstream>
#include <cstdlib>
#include <climits>
using namespace std;
int main(){
ifstream fin("Current_Reservoir_Levels.tsv");
if (fin.fail()) {
cerr << "File cannot be opened for reading." << endl;
exit(1);
}
string head;
getline(fin,head);
string date;
double eastStorage;
double eastElevation;
double westStorage;
double westElevation;
double max = INT_MIN;
double min = INT_MAX;
while(fin>> date>> eastStorage>> eastElevation>> westStorage>> westElevation){
fin.ignore(INT_MAX,' ');
if(eastStorage>max){
max = eastStorage;
}
if(eastStorage<min){
min = eastStorage;
}
}
cout << "Minimum storage in East Basin: " << min << " billion gallons"<< endl;
cout << "Maximum storage in East Basin: " << max << " billion gallons"<< endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.