(Latest Revision: 08/28/2004)
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:
- copy the input into a 2D array, and
- decode the message by processing the contents of the array.
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:
- Always send me e-mail as plain text in the main message body.
Never send me attachments.
- Always use the exact subject line I specify for each
message. (I often get hundreds of e-mail messages in a week. The
subject line allows me to find, filter and sort messages.) You will lose
a significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when you send the e-mail. You may use the
instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me,
and check immediately to see if you receive the message intact.
You are responsible for sending
e-mail correctly.
Here is the list of things you have to turn in:
- On the first due date;
- At the start of class place a hardcopy of a
level-two source file
(or greater) of your program on the "counter" in front of me. Make
sure all the code is properly formatted and that it all shows on the
paper.
- Using the subject line: CS2500,prog1.2 send a
level-two source file
(or greater) of your program to me by e-mail before midnight.
- Using the subject line: CS2500,script1.2 send a
level-two test script
of your program to me by e-mail before midnight.
- On the second due date;
- At the start of class place a hardcopy of a
final level source file
of your program on the "counter" in front of me. Make sure all the
code is properly formatted and that it all shows on the paper.
- Using the subject line: CS2500,prog1.f send a
final level source file
of your program to me by e-mail before midnight.
- Using the subject line: CS2500,script1.f send a
final level test script
of your program to me by e-mail before midnight.
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.