Question: 1.Read in the original file, VTSMX.csv , partially shown below. Write that data out into a second file, VTSMXmodified.csv , partially displayed below. The second
1.Read in the original file, VTSMX.csv, partially shown below. Write that data out into a second file, VTSMXmodified.csv, partially displayed below. The second file should have the headings removed and the hyphens removed, and the commas should be replaced by spaces. The original file contains 501 records and the modified file should contain 500 records.
2.Read in the modified file into a 2-dimensional int array with 500 rows and two columns. You should store the first column of data (the Date) and the fifth column of data (the Close) into the two columns of your array. Note, the floating point Close value should be converted to a roundedint value. Sample array values are shown below. Note, the original data is sorted in ascending order by date.
3.Write a sort function that will allow you to sort the array data by either column in ascending or descending order.
4.Produce the report shown below, matching exactly the formats shown. You will need to sort the array a few times to produce the desired results.
Input File (VTSMX.csv)
| Date,Open,High,Low,Close,Adj Close,Volume 2015-10-16,50.860001,50.860001,50.860001,50.860001,49.009617,0 2015-10-19,50.880001,50.880001,50.880001,50.880001,49.028889,0 2015-10-20,50.810001,50.810001,50.810001,50.810001,48.961437,0 2015-10-21,50.439999,50.439999,50.439999,50.439999,48.604893,0 2015-10-22,51.200001,51.200001,51.200001,51.200001,49.337242,0 2015-10-23,51.720001,51.720001,51.720001,51.720001,49.838326,0 2015-10-26,51.610001,51.610001,51.610001,51.610001,49.732330,0 2015-10-27,51.419998,51.419998,51.419998,51.419998,49.549244,0 2015-10-28,52.130001,52.130001,52.130001,52.130001,50.233410,0 2015-10-29,52.049999,52.049999,52.049999,52.049999,50.156319,0 ... |
Modified Input File (VTSMXmodified.csv)
| 20151016 50.860001 50.860001 50.860001 50.860001 49.009617 0 20151019 50.880001 50.880001 50.880001 50.880001 49.028889 0 20151020 50.810001 50.810001 50.810001 50.810001 48.961437 0 20151021 50.439999 50.439999 50.439999 50.439999 48.604893 0 20151022 51.200001 51.200001 51.200001 51.200001 49.337242 0 20151023 51.720001 51.720001 51.720001 51.720001 49.838326 0 20151026 51.610001 51.610001 51.610001 51.610001 49.732330 0 20151027 51.419998 51.419998 51.419998 51.419998 49.549244 0 20151028 52.130001 52.130001 52.130001 52.130001 50.233410 0 20151029 52.049999 52.049999 52.049999 52.049999 50.156319 0 ... |
Array Data
| 20151016 5086 20151019 5088 20151020 5081 20151021 5044 20151022 5120 20151023 5172 20151026 5161 20151027 5142 20151028 5213 20151029 5205 ... |
Program Output
| Current Date: 10/10/17 Current Close: $63.84 The latest five closes are: 10/10/17 $63.84 10/09/17 $63.69 10/06/17 $63.83 10/05/17 $63.89 10/04/17 $63.55 The oldest five closes are: 10/16/15 $50.86 10/19/15 $50.88 10/20/15 $50.81 10/21/15 $50.44 10/22/15 $51.20 The five highest closes are: 10/05/17 $63.89 10/10/17 $63.84 10/06/17 $63.83 10/09/17 $63.69 10/04/17 $63.55 Percent gain YTD: 13.88% 50 Day Moving Average: $62.02 200 Day Moving Average: $60.00 Percent gain over 200 Day Moving Average: 6.41% Recommendation: Sell |
here is what i have:
#include
int main() { char ch; string comma;
ifstream inputfile("vtsmx.csv.txt"); ofstream myfile("vtsmx_modified.csv.txt");
if(!inputfile) cout << "Cannot open input file. ";
while(!inputfile.eof()) { ch = inputfile.get(); if(ch != '-') myfile << ch;
}
inputfile.close(); myfile.close();
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
