(Latest Revision: 02/15/2009)

File I/O and 2D-Array Processing: A Program That Decodes a Message


PRELIMINARIES:

Before you begin this assignment you need to read the guideline document: General Instructions For Submitting Programming Assignments & Statement Of Program Grading Policies. You also need to examine the other directions and examples here: http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/.


THE ASSIGNMENT:

Write a program that will read a file into a two-dimensional array of characters and decode the message that is contained in the file.


INPUT:

The program will read all input from standard input. That way, the user can enter input at the keyboard or enter input from a file by redirecting standard input. (If you aren't positive you know what I mean by "standard input" please ask in class, and I can demonstrate.)

A typical input might look like this:
GGJMMVX NDRZG--

"?OCBDM ND OD ,ZBV MPJT OV ,FIDCO PJT JY
-- YVZC MPJT IJ YIVON TGOIVNNZXID PJT OZT YIV"
The input is a message that has been encoded by substituting a different letter for each letter of the original message, and by writing the message backwards.

You may assume that lines in the input are no more than 70 characters in length. Also, you may assume that there are no more than 20 lines in the input, including blank lines.

To keep the problem simple assume that all letters in the message are UPPER CASE LETTERS. Assume also that the substitution has been done only on the letters, not on the punctuation characters, the numerals, or any other kind of character. Assume that blanks and newlines are the only "white space" in the input (no tabs, for example.)


OUTPUT:

The program will write all its output to standard output. That allows the user to see output on the screen or redirect it to a file. (If you aren't positive you know what I mean by "standard output" please ask in class, and I can demonstrate.)

The program must reverse the message and substitute the correct letter for each letter that appears in the message. For example, the output for the input above is:

"AND YET YOU INCESSANTLY STAND ON YOUR HEAD -- 
DO YOU THINK, AT YOUR AGE, IT IS RIGHT?" 

--LEWIS CARROLL
The substitution is a simple circular one. Each letter in the alphabet is decoded by replacing it with the letter five positions further down in the alphabet. For example, 'A' is replaced with 'F' and 'K' with 'P'. When you get to the end of the alphabet, you "wrap around." For example, 'X' is replaced by 'C'.


PROCESSING:

One of the goals of this assignment is to give you practice using a 2D array. Therefore, your program must:

GOTCHA'S:

How should your program handle blanks when reversing a line of text? How will your program recognize when a decoded line of text is supposed to start with some blanks? A related question is: how will your program tell if a location in the array contains a character or not? Let's discuss this problem in class.

How should you generate test files for this program? By hand? Is there an easier way? Notice that the process of encoding is not much different than the process of decoding. I suggest you try to write a little program that will create your test files for you by encoding a "clear text" message.

Here is a little riddle related to the discussion above: What would you get if you applied the decoding process to a file, put the output in a second file, and then applied the decoding process to the second file? If you continued doing this, do you think you would ever get the original message back? If yes, how many times would it take? Is there a way to tell without actually running the program over and over?


HOW THE PROGRAM WILL BE USED:

Suppose the program is called decoder. If the user wants to enter the input from the keyboard, s/he just enters the command:

decoder

Suppose the user wants the input to come from a prepared file called input01. In that case s/he just enters:

decoder < input01

The user may wish to save the output of the program to a file. In that case, s/he can use commands such as:

decoder > output01

or

decoder < input01 > output01

When I test your program, I will test it on several prepared files.


WHAT TO TURN IN:

You will be turning in two versions of this program: a level-two program and a final level program. (Don't panic: we will be discussing this in class.) For each phase of the assignment, you will turn in a printer output (hardcopy) and you will send me an e-mail message. Please follow these rules: Here is the list of things you have to turn in: Since this is a simple program, the final-level of the program should be the third level.

Note that there are no spaces in the subject lines given. It is important that you do not insert any spaces. My e-mail address is: john@ishi.csustan.edu.


DUE DATES:

For the due dates, see the class schedule.