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
Complete the
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6900813d-7c23-46b7-a2db-4b3d463f1913%2F537e8842-0cf9-4c24-944f-a59cbd6958b1%2Fqtixej.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6900813d-7c23-46b7-a2db-4b3d463f1913%2F537e8842-0cf9-4c24-944f-a59cbd6958b1%2Fh02lmgr.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)