/* Problem description: The text file DJI.txt contains the information of a stoc
ID: 3549632 • Letter: #
Question
/* Problem description: The text file DJI.txt contains the information of a stock market index --
Dow Jones Industrial Average Index (DJI for short) -- for a continuous time
in year 2008. Each line contains the date and the DJI's value on that day.
For the format of the file, please view DJI.txt.
Please write a program that reads DJI values stored in the data file DJI.txt,
and finds out the date with highest DJI value during this period stored in the file.
*/
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main( )
{
const string inputFile = "/var/www/html/programs2/2170_1_5/dataFiles/DJI.txt";
ifstream ifs; //an input file stream
int day; //Today's day
int maxDay; //The day of the date with max. DJI
string month; //Today's month
string maxMonth; //The month of the date with max. DJI
double maxDJI; //The max. DJI value got so far.
double dji; //Today's DJI
ifs.open( inputFile.c_str() ); //open the file
Please write a program that reads DJI value from the file opened above, and find out the date with highest DJI value during this period.
ifs.close(); //close the input file
cout << "DJI is highest on " << maxMonth << " " << maxDay << " with " << maxDJI << endl;
return 0;
}
Explanation / Answer
//put this code in blank space
string temp;
ifs>>maxMonth>>maxDay>>temp>>maxDJI;
while(ifs>>month>>day>>temp>>dji)
{
if(dji>=maxDJI)
{
maxMonth=month;
maxDay=day;
maxDJI =dji;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.