- read input temperatures by day
- write summarization in an output file
from tempin.txt
01/24/2019 5 22 27 31 26 19
01/25/2019 8 20 25 30 35 40 38 32 29
01/26/2019 3 0 8 2
ENDOFDATA 0
to tempsout.txt
DATE HIGH LOW
---------- ---- ----
01/24/2019 31 19
01/25/2019 40 20
01/26/2019 8 0
int main() {
// Open the input file (when fail, respond appropriately)
// Open the output file (when fail, respond appropriately)
// Start writing to output file
// Read lines one by one (loop)
// Read temperatures get the high and low
// Write the summary line in "mm/dd/yyyy aaa bbb"
// Exit loop at 'ENDOFDATA'
// Close files
}
setw(n)
: set the column width
left
or right
: align
setprecision(m)
: decimal point
fixed
: padding with zeroes up to the precision
#include <fstream>
ifstream f;
string name; int age; float gpa;
f.open(”mydata.txt”);
if (! f.fail()) {
f >> name >> age >> gpa;
f.close();
}
#include <fstream>
ofstream f;
f.open(”mydata.txt”);
if (! f.fail()) {
f << ”Hello world ” << endl;
f << setw(10) << 3.14159;
f.close();
}
lab4 assignment
- Header comment box with all the proper information
- Use of good variable names; proper indentation; good use of comments
- Files opened and checks for failure done
- Header lines written correctly to output file
- Correct number of lines (days) processed and written to the report (no line for ENDOFDATA)
- Data for one line read and processed (correct High and Low found) correctly
- Correct data written to output file for each day, including spacing/widths/justifications specified
- Files closed correctly