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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education