CSCI 261 - Programming Concepts (C++)Spring 2017 - Lab 08AQuick Links: Blackboard | Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks |
|
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |
This lab is due by March
21, 2017 11:59pm.
ConceptsThe focus of this assignment is on one
concept: how to write data to an "output file stream" or ofstream
object.
Working with Data
Today's class discussed how data is often treated as "streams" of
information that can be written a piece at a time. The files we will
write in CSCI 261 are simple text files; for lab today, the simple text
file will contain a series of characters. Remember that whenever you
work with a file stream as output, we call them
ofstream
objects.
There will always be four things you will do whenever working with an
ofstream
. Open the file, check for an error, write its data, and close the
file. The typical pattern for this is as follows:
#include <iostream>
#include <fstream> using namespace std; int main() { ofstream myCatsAges("filename"); // declare ofstream object and open the file // check for an error if ( myCatsAges.fail() ) { cerr << "Error opening output file"; exit(1); } // write the data myCatsAges << 5; myCatsAges.close(); // close the file return 0; }
Remember, once you have an
ofstream
object (like
myCatsAges
shown above) you use it in a manner similar to using
cout
.
Instructions
For this lab, start with your solution to Lab03B.
We want to write out a log of all of the user's input. What option they
selected, what values they entered, and what time this occurred.
This log will be created by writing to a file in the following format:
Time: 1489549042 Option: 1
Time: 1489549155 Measurements: 3 4 5 Time: 1489549200 Option: 2 Time: 1489549251 Option: 4 Time: 1489549277 Option: 3
From this log, we could go back and study a user's behavior. How long it takes them to complete steps, what order they select steps.
You should modify your Lab03B program by first
opening a file to write out to. Then everytime the user selects an
option, write to the file the current time and the option that was
selected following the format above. If the user selects Option 1, then also write out to the file the three side lengths they enter.
Lab Submission
You will submit your solution to this lab with the rest of Week08.
Detailed instructions for doing this are posted in Assignment 08.
This lab is due by March
21, 2017 11:59pm.
| |
Last Updated: 01/01/70 00:00
|