Lab 11: File IO
- Due Apr 27, 2021 by 11:59pm
- Points 10
- Submitting a file upload
- File Types cpp
- Available after Apr 27, 2021 at 2pm
Overview
In this lab, you'll practice reading from and writing to files.
Learning outcomes
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)
Exercises
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
Input file | Last three lines of output |
data1.csv |
Row 99: n=11.000 sum=-20650.799 [-1904.414, -1877.345, -1859.956] |
data2.csv |
Row 49: n=20.000 sum=-38157.237 [-1997.613, -1907.862, -1729.028] |
data3.csv |
Row 2: n=5.000 sum=26807.271 [5059.322, 5361.454, 5951.196] |
Submitting
Upload your modified .cpp files (whatever you've completed by the end of lab is fine).
PA options
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.
- PA 2.1: Area under the curve (only if you haven't submitted PA 8.1)
- PA 3.1: Adaptive quiz
- PA 3.2: Password generator+ (only if you haven't submitted PA 4.1 or PA 7.1)
- PA 4.1: Password generator++ (only if you haven't submitted PA 7.1)
- PA 4.2: Calculator
- PA 5.1: Word stats (only if you haven't submitted PA 7.2)
- PA 5.2: Digital Rolodex (only if you haven't submitted PA 7.3)
- PA 6.1: Gridworld with random layout and points
- PA 6.2: Gridworld with moving enemies
- PA 6.3: Speed reader I
- PA 7.1: Password generator++ with functions
- PA 7.2: Word stats with functions (only if you haven't submitted PA 10.2)
- PA 7.3: Digital Rolodex with functions (only if you haven't submitted PA 10.3)
- PA 8.1: Area under the curve with functions
- PA 8.2: Counting coin flip runs through simulation
- PA 10.1: Upcoming assignments+
- PA 10.2: Word stats with functions and structs
- PA 10.3: Digital Rolodex with structs