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;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images