In this lesson, our instructor Alvin Sylvain goes through an introduction on input and output. He discusses streams, input and output class hierarchy, buffer class hierarchy, base class attributes, sub-class members, input classes, output classes, multiple inheritance and includes, detect failures using status bits, failure bit cautions, string input and output with stringstream, flushing data buffer, and internationalization.
Modify your program that implements the “Auto” class.
Don’t “hard-code” multiple loops to test; read the pedal pressures from a file.
Test your program by running it with different input files that test different scenarios.
Write output to a human-readable data file that you can review after the run.
Also write the data to a comma-separated values (CSV) file. Any labels are only on the first record. Each data point on each line is separated by a comma, and text data is enclosed in double-quotes. E.g.:
That way, you’ll be able to read the file into a spreadsheet program. Once in a spreadsheet, you do other computations or create graphs.
If you haven’t done so already, output each exception to a separate log file.
Validate the input from the file. Set the exception bits so that you can use exception handling.
Read the input from a CSV file. That is, use the comma as a field delimiter.
For example, the first column might be the value for the acceleration pedal, then the comma, then the second column can be the value for the brake pedal.
Use the “stringsteam” class as part of the validation, so you can read in an entire field up to the comma, then convert that value to a number for input.
Test that the entire field was a number, with no extraneous non-numeric, non-delimiter, non white-space character.
Put the result into a class or function which throws an exception of the data is not valid.
It can be useful for the input files to be self-documenting.
Read the first field on a line into a buffer, test the first character to see if it is a “comment character.” Typically the hash symbol (#) is used for line comments in cases like this. Process normally if it is not a comment line.
Skip over each line in a loop until the first character is not a comment.
Document your input files with comments as to what exactly is being tested.
Extra: There are additional ways to help document the testing process. Use a different “comment character” to indicate, “Print this line.” When your program sees that character at the beginning of the line, print the entire line to the output, including the exception log.
Run your program through its paces to test the various functions.
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.