Program 6

Home Windows C++ 241 C++ 242 Contact Info Contents

Program 6 - February 14

Up

File I/O

For a change - an assignment out of the book!

Write the program described in our text (Savitch, 3rd edition) on page 295: Programming Project # 12. This is the project that reads and makes minor corrections to a C++ program. For full credit, do what the author calls the "harder" version. That is, you should recognize all of the following and correct them:
    cin<<          cin <<                 cin         <<
and even     cin
<<  (that's with the symbol on a following line).

Hint: Look up the isspace function.

Additions to the Text

Your program should allow the user to input the name of the input file as we discussed in class. For the output file, you can either use a hard coded name or have the user input that as well. Be sure to display an error message if the input file cannot be found.

Suggestions

The best approach is probably to process a word at a time BUT we haven't studied enough about strings to do that cleanly. You will probably have to do it one character at a time. The easiest way to do that is to use a variable that "remembers" what you are looking for. For example:
    1=looking for c
    2=got c, looking for i or o
    3=got ci, looking for n
    4=got cin, skipping spaces looking for <
        etc.
This is called a Finite State Machine, FSM or just a state machine.

You can also do it by having a completely different piece of code for each state of the program.

Ask questions about this on Wednesday, and I'll outline the approach in a little more detail.

Sample Files

I'll have sample input and output files on the FTP site later this week.

 

Home Windows C++ 241 C++ 242 Contact Info Contents

Copyright © 2000  Charlie Poole. All rights reserved.
Revised: July 15, 2002 - cpoole@ctc.edu