Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following program, write the code in C++, please do it well, make sure you show all steps and how you did it. Please make

The following program, write the code in C++, please do it well, make sure you show all steps and how you did it. Please make the code such that I can copy paste it. Also please show the output as well, as sometimes the code is given but there is not a correct output, so show a screenshot of your output and that it matches everything asked in the question.

So for the following question i have already done Task A, and I will send you the instructions for the Task A so you have context of what I did and will send my code for it as well, as you will need that to add on to the code for Task B.

So for background on Task A:

image text in transcribed

image text in transcribed

image text in transcribed

Now that the data part of the code is done and how you lead into the problem, this is the problem itself that I did for Task A:

image text in transcribed

Now while this is the main step, I also added these following files and put the codes for them for this problem for the addition part of this code:

For this lab, you will create a program with multiple files and us make to control compilation. There will be a sample Makefile along with other starter files in this repo.

image text in transcribed

The following is my code for Task A and the output it produces so you know what do for Task B:

Main.cpp:

#include

#include "reservoir.h"

int main() {

double east_storage;

std::string dates[] = {"01/01/2018", "02/01/2018", "03/01/2018", "04/01/2018", "05/01/2018",

"06/01/2018", "07/01/2018", "08/01/2018", "09/01/2018", "10/01/2018"};

int n = sizeof(dates) / sizeof(dates[0]);

for (int i = 0; i

east_storage = get_east_storage(dates[i]);

std::cout

}

return 0;

}

Reservoir.cpp:

#include

#include

#include

double get_east_storage(std::string date) {

// Open the data file

std::ifstream fin("Current_Reservoir_Levels.tsv");

if (fin.fail()) {

std::cerr

exit(1);

}

// Skip the header line

std::string junk;

getline(fin, junk);

// Search for the given date in the file

std::string file_date;

double east_storage;

bool found = false;

while (fin >> file_date >> east_storage) {

// Check if the current line contains the given date

if (file_date == date) {

found = true;

break;

}

// Ignore the rest of the line

std::string line;

getline(fin, line);

}

// Close the file

fin.close();

// Check if the date was found in the file

if (!found) {

std::cerr

exit(1);

}

return east_storage;

}

Reservoir.h:

#ifndef RESERVOIR_H

#define RESERVOIR_H

double get_east_storage(std::string date);

#endif

Makefile:

all: main.cpp reservoir.cpp reservoir.h

g++ -std=c++11 -o main main.cpp reservoir.cpp

clean:

rm -f main

This is what the output is:

image text in transcribed

Note that I downloaded the file Current_Reservoir_Levels.tsv regarding the gallon and water levels per the date

Also before I mention Task B and what you have to do, make sure that the dates i have hardcoded remain the same and that the computer reads the Current_Reservoir_Levels.tsv to print the output for the gallons storage.

Add the following two functions to reservoir.cpp and reservoir.h double get_min_east() - this function should return the minimum storage in the East basin in the 2018. double get_max_east() - this function should return the maximum storage in the East basin in the 2018. Test these by calling them from main and printing out results. As with previous task, there should be no keyboard input. Note: Like in previous task you will have to read the file completely in these functions.

This is what you have to do, please read the overall assignment, assignment from Task A well, and my code, and use the reservoir.cpp and reservoir.h well and make sure it reads the output well to print the gallons storage for minimum and maximum in addition to the gallons storage for the 10 days it also has to say for my code. Make sure everything runs and send a screenshot of your output for this

IMPORTANT IT IS SUPPOSED TO PRINT THE OUTPUT FOR ALL THOSE 10 DATES FROM THE CODE I SENT FOR TASK A AND THAT SHOULD NOT GO AWAY, THAT OUTPUT REMAINS THE SAME BUT YOU HAVE TO ADD THE OUTPUT FOR MAX AND MIN STORAGE OF THE YEAR, THAT IS YOUR TASK, MY CODE SHOULD BE CHANGED SUCH THAT BOTH THESE OUTPUTS COME, PLEASE DO THIS WELL REQUEST

please also make sure it runs, i have asked this question before but the code does not get ran. make sure you have minimum and maximum storage well in addition to the storage levels of each hardcoded day for my task and answered everything

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: 1. Follow the link NYC Open Data Current Reservoir Levels. 2. Choose the View Data menu option (it will reload the page). 3. 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 4. Sort entries by Date in the Ascending order. 5. Export the data: - Click the light blue button Export - Choose TSV for Excel (it will produce a plain text data file in tab-separated values format). - Save obtained file Current_Reservoir_Levels.tsv on your hard drive. Don't 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-separatedvalues). 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: 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 f in( "Current_Reservoir_Levels.tsv"); if (fin.fail()) cerr "File cannot be opened for reading." endl; exit(1); / exit if failed to open the file \} Remember 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 file After 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: Here, variable can be of type string, and the others are numeric variables of type 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 and a stream class make them work, we have to include two new headers at the beginning of the program: Write a program east-storage.cpp that asks the user to input a string representing the date (in MM/DD/YYYY format), and prints out the East basin storage on that day. Example $. /east-storage Enter date: 05/20/2018 East basin storage: 80.96 billion gallons Write a program that consists of two .cpp files plus any supporting files. One will be named main. cpp and it will drive your program. It will contain the main function. The other file should be named reservoir.cpp and should contain a function with the prototype double get_east_storage(std::string date). The function should accept a std::string specifying a date and should return the East Basin storage for that day. Your program should call and test this function from main. There should be no keyboard input but the output should illustrate that the function works correctly. Note: This assignment template contains a skeleton that includes the Makefile, main.cpp, and reservoir.h and reservoir.cpp. You are expected to fill in the functions and calls. Note: The get_east_storage function should open and read the data file. Date: 01/01/2018 East basin storage: 59.94 bi llion gallons Date: 02/01/2018 East basin storage: 65.69 bi llion gallons Date: 03/01/2018 East basin storage: 75.83 bi llion gallons Date: 04/01/2018 East basin storage: 74.61 bi llion gallons Date: 05/01/2018 East basin storage: 80.14 bi llion gallons Date: 06/01/2018 East basin storage: 78 billi on gallons Date: 07/01/2018 East basin storage: 77.73 bi llion gallons Date: 08/01/2018 East basin storage: 76.5 bil lion gallons Date: 09/01/2018 East basin storage: 73.99 bi llion gallons Date: 10/01/2018 East basin storage: 69.94 bi

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago