In this lab, you'll practice reading from and writing to files.
By the end of this lab, you should be more comfortable...
- opening file streams
- writing to files
- reading from files
- reading different file formats (e.g., CSV)
Download fileio-lab.zip and unzip the folder somewhere on your computer. Implement the missing components of those file in this order:
- notes.cpp—TODO 1 (implement the LoadNotes function)
- Testing: to see if you got this part working, compile and run the program. Choose the 'l' option and enter: notes1.txt. You should see three notes displayed followed by the menu prompt. The content of these notes should match what is in the notes1.txt file (which you can view directly in Visual Studio Code)
- notes.cpp—TODO 2 (implement the SaveNotes function)
- Testing: compile and run the program. Add 2 or 3 notes, then select the 's' option to save. Name the file whatever you want (e.g., notes2.txt). After saving, you should see a file with the name you provided show up in the folder; open it in Visual Studio Code and check that it includes the 2 or 3 notes you added via the program menu. Quit the program then re-run it. Choose the 'l' option and enter the name of the file you just saved. You should see all the notes you added displayed followed by the menu.
- data-summarizer.cpp—TODO 1 (implement the SummarizeDataFile function)
- Testing: compile and run the program three times, one each for the files data1.csv, data2.csv, and data3.csv. Compare the last three lines of input produced by each of the runs to the correct data below.
Expected results for data-summarizer.cpp
||Last three lines of output
Row 99: n=11.000 sum=-20650.799 [-1904.414, -1877.345, -1859.956]
Row 100: n=9.000 sum=4203.556 [-51.742, 467.062, 785.373]
TOTAL: 100.000 sum=-276188.962 [-5870.982, -2761.890, 7107.847]
Row 49: n=20.000 sum=-38157.237 [-1997.613, -1907.862, -1729.028]
Row 50: n=20.000 sum=11120.697 [134.153, 556.035, 893.045]
TOTAL: 50.000 sum=-71370.308 [-8849.998, -1427.406, 7191.070]
Row 2: n=5.000 sum=26807.271 [5059.322, 5361.454, 5951.196]
Row 3: n=5.000 sum=-19420.923 [-3904.857, -3884.185, -3870.094]
TOTAL: 3.000 sum=15096.352 [-3904.857, 5032.117, 5951.196]
Upload your modified .cpp files (whatever you've completed by the end of lab is fine).
Please see the syllabus and course schedule (both on the homepage) for more information about how many programming assignments you are required to pass, due dates, etc. Of note: you do not need to attempt every or even most PAs.
Note: please add this to the top of your source code file, just above the specs:
// In fulfillment of Lab 11.
You may submit any one of the following PAs that you have not yet received credit for, subject to the noted exclusions. This is the final release of Programming Assignments! The deadline for these is the last day of class (5/7) (that is the last day we're allowed to assign work). However, I will not penalize anyone for submitting as late as Tuesday, May 11 @ 11:59pm.