(Latest Revision: Thu Apr 24 21:25 PDT 2014 )

SIXTH CS 1500 SOLO PROGRAM: String-Reversing Program


OBJECTIVE: The purpose of this programming assignment is to get practice using files, arrays, and loops.


ASSIGNMENT SYNOPSIS:

Write a program that reads some strings from a file and manipulates them so as to print each string with its characters reversed.


DETAILS:

To get a clear idea of what the program is supposed to do, have a look at the sample runs.


INPUT:

You must write the program with certain facts, assumptions, and preconditions in mind:
THE DESIGN OF THE PROGRAM:

The program must have at least one function (in addition to the main() function).

At least one of the additional functions must have one or more parameters.

You are not allowed to use any global variables.

I expect you to employ good principles of top-down design when you develop the program.

I want you to have the experience of writing a program that reads from a file and uses an array appropriately.

Therefore you must write the program so that it reads each string into an array of char, and copies the characters out of the array (in reverse order) while writing them to the screen.

You should use this kind of declaration in your program:

char theString[256] ;

Each time the program needs to read a string from the file, it should read it into such a variable as theString, as defined above.

The array is nice and long - 256 slots - so it has way more than enough capacity for long words. 256 slots is enough for 255 characters in the string, plus the null character ('\0') that is used to mark the end of the string.

When the program copies the characters OUT of the variable, it must copy ONLY the characters that are part of the string that was read from the file. It's "no fair" copying slots out of the array that aren't actually used to hold characters that are part of the string that was read from the file. For example, if the program reads yppaH from the file, then it has to just copy out the five characters H-a-p-p-y from the variable, not 255 slots from the array, or something like that.

Regarding the idea above, you should check out the strlen() function described on page 449 of our text. Think about how you could use it to help write the program.

Because I am going to test all the programs by compiling and running them on different versions of the input file, I need everyone in the class to use exactly the same name for the input file. Therefore, please name your input file backWords.txt.

Please note that the name is backWords.txt, NOT backWards.txt

You can use a command like
ifstream fin("backWords.txt") ;
to declare an ifstream named fin, and attach it to the backWords.txt file.

Note: Depending on the computing environment in which you develop the program, you may not understand how to give a file the name backWords.txt. If you ask about it, I think I or Julie Gorman can help you figure it out.

Note: Come to class to get more discussion of how to design the code.


FORM AND FORMATTING REQUIREMENTS:

At the beginning of your program file put a header comment like this:

  /* PROGRAM: Stats Calculator */

  /*

  Name:          Gordon Goodguy
  User Name:     goodge
  Course:        CS 1500, Computer Programming I
  Instructor:    John Sarraille
  Date:          January 01, 1970

  */
Of course, in place of "Gordon Goodguy," you must put your own full name. In place of "goodge" put your user (login) name. In place of the Unix epoch, "January 01, 1970," put the date that you finished the program. Note that the comment delimiters /* and */ are important. They need to be placed correctly or you will get compiler errors.


TESTING:

When you make your test script, include all the tests that are in the sample runs. Also perform three more tests: To make it easier for me to check the work in your script, order your tests so that The sample runs also illustrates a way to work with multiple versions of the input file, while still having just one name for the input file. Different versions of the input file have names like backWords_02.txt, backWords_03.txt, and backWords_04.txt. When we want to use one of the files for input, say backWords_03.txt, we do this unix command first:
cp backWords_03.txt backWords.txt
The cp command is the unix command that makes a copy of a file. So after that command executes, backWords.txt is a copy of backWords_03.txt - the two files are identical. So if we run the program right away after we execute that cp command, the program reads from backWords.txt, and what happens is no different than if the program read from backWords_03.txt. By doing a cp command before each program run, we can test many different input files, although the program always uses backWords.txt as the name of its input file.

When you do your testing, verify that all the output of the program is correct.


WHAT TO TURN IN:

You will be sending me two e-mail messages. Please follow these rules: Here is the list of things you have to turn in: 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



WHEN IS THIS ASSIGNMENT DUE?

Look for the due date in the class schedule. (It's at the top level of the class directory.)