2018-09-12 1172.72 2018-09-13 1170.74 2018-09-14 1179.10 2018-09-17 1170.14 2018-09-18 1157.09 2018-09-19 1164.98 2018-09-20 1179.99 2018-09-21 1192.00 High: 1244.23 on 2018-08-30 Low: 1157.09 on 2018-09-18 On success, the program should print the following for goog.csv. Enter the name of the file to be analyzed:goog.csv 2018-08-21 1208.00 2018-08-22 1200.00 2018-08-23 1207.14 2018-08-24 1208.82 2018-08-27 1227.60 2018-08-28 1241.29 2018-08-29 1237.45 2018-08-30 1244.23 2018-08-31 1234.98 2018-09-04 1204.27 2018-09-05 1193.80 2018-09-06 1186.30 2018-09-07 1158.67 2018-09-10 1172.19 2018-09-11 1161.63

Enhanced Discovering Computers 2017 (Shelly Cashman Series) (MindTap Course List)
1st Edition
ISBN:9781305657458
Author:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Chapter2: Connecting And Communicating Online: The Internet, Websites, And Media
Section: Chapter Questions
Problem 2MC
icon
Related questions
Question

Complete the program by filling in the code to read the file (goog.csv) and print the date and first price from each line. Compute the high and low price from the file and save the dates for the high and low price. Print them at the end.

 

HINT: Remember to open the file and check if that open command succeseded using the fail() method. When reading lines from a file, it makes sense to read all parts in the while condition.  

 

infile.open(filename);

while(infile >> name >> value >> theRest) {

   // Process input

}

infile.close();

 

 

 

If the program files to open the file:

Enter the name of the file to be analyzed:amzn.csv
File amzn.csv cannot be opened.

code:

#include <iostream>
#include <limits>
#include <fstream>

using namespace std;

//Todo: declare your functions here.
int main()
{
ifstream infile;
char fileName[256];
cout <<"Enter the name of the file to be analyzed:";
cin >> fileName;

// TODO: Open the filename and test that it was successful


// Used to read in te date, price and the rest.
double price;
string date, junk;
// Going to store the date of the high price and low price
string lowDate, highDate;

// Going to store the high price and low price.
double high=numeric_limits<double>::min(), low=numeric_limits<double>::max();

cout.precision(2);
cout.setf(ios::fixed);

// TODO: Implement a loop that reads line by line from input.
// TODO: A line has the date, the price and the rest (use junk)
// TODO: Stop reading on end of input.
while ( true ) {
cout << date << " " << price << endl;

// TODO: Find the highest price
// TODO: Save the date of the price

// TODO: Find the lowest price
// TODO: Save the date of the price

}
cout << "High: " << high << " on " << highDate << endl;
cout << "Low: " << low << " on " << lowDate << endl;
}

 

2018-09-12 1172.72
2018-09-13 1170.74
2018-09-14 1179.10
2018-09-17 1170.14
2018-09-18 1157.09
2018-09-19 1164.98
2018-09-20 1179.99
2018-09-21 1192.00
High: 1244.23 on 2018-08-30
Low:
1157.09 on 2018-09-18
Transcribed Image Text:2018-09-12 1172.72 2018-09-13 1170.74 2018-09-14 1179.10 2018-09-17 1170.14 2018-09-18 1157.09 2018-09-19 1164.98 2018-09-20 1179.99 2018-09-21 1192.00 High: 1244.23 on 2018-08-30 Low: 1157.09 on 2018-09-18
On success, the program should print the following for goog.csv.
Enter the name of the file to be analyzed:goog.csv
2018-08-21 1208.00
2018-08-22 1200.00
2018-08-23 1207.14
2018-08-24 1208.82
2018-08-27 1227.60
2018-08-28 1241.29
2018-08-29 1237.45
2018-08-30 1244.23
2018-08-31 1234.98
2018-09-04 1204.27
2018-09-05 1193.80
2018-09-06 1186.30
2018-09-07 1158.67
2018-09-10 1172.19
2018-09-11 1161.63
Transcribed Image Text:On success, the program should print the following for goog.csv. Enter the name of the file to be analyzed:goog.csv 2018-08-21 1208.00 2018-08-22 1200.00 2018-08-23 1207.14 2018-08-24 1208.82 2018-08-27 1227.60 2018-08-28 1241.29 2018-08-29 1237.45 2018-08-30 1244.23 2018-08-31 1234.98 2018-09-04 1204.27 2018-09-05 1193.80 2018-09-06 1186.30 2018-09-07 1158.67 2018-09-10 1172.19 2018-09-11 1161.63
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning
A+ Guide To It Technical Support
A+ Guide To It Technical Support
Computer Science
ISBN:
9780357108291
Author:
ANDREWS, Jean.
Publisher:
Cengage,