CSc 2311
Programming project #2

DATE ASSIGNED: September 26, 2000

DUE DATE:  October 10, 2000, at 9:30 a.m. (in class)
 

Objectives

1. Practice new C++ commands.

2. Practice using streams.

3. Practice using files.

Introduction

Your assignment is given below. To solve it, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Following the pattern in the class example, first, design your program by specifying its behavior, identifying the objects and operations it needs to solve the problem, and then organizing the objects and operations into an algorithm. Then code your design in C++ using stepwise translation. Finally, test your program thoroughly.

Project

1. Your program should compute the average word length for a text file. The average word length is the average number of characters per word. A word is a string of symbols that is preceded and followed by a blank space, a comma, a period, the beginning of a line, or the end of a line.

Consider any alpha-numeric character to be part of a word. If there is an apostrophe, then the characters following it should be counted as part of the word before it. For example, "Paula's Bookstore" should be considered to be 2 words of 6 and 9 characters, respectively.

Clarification -
There were some questions about how to interpret the above directions, so let me clarify it. Your program should decide if a character is alpha-numeric or not. If it is alpha-numeric, then it should be treated as part of a word. If it is not alpha-numeric, then it should be treated as a separator, something between words. The only exception is the apostrophe, which is not counted as a character, and is not a separator either. For example, here is how to treat the following cases:

_ab$c2e_      The $ is not a letter or a number, so it seperates two words "ab" and "c2e".
_1_             1 is alpha-numeric, so it is a word of 1 character.
_3%_         3 is alpha-numeric, so it is a word of 1 character. The % is ignored.
_'_             The apostrophe is by itself, so it is ignored. This is not a word.
_'ab_         The apostrophe comes before the start of the word, so it has no effect on the word.
                  This forms a 2 character word.
_a'b_         The apostrophe comes in the middle of a word. It should be ignored.
                  This forms a 2 character word.
_ab'_         The apostrophe comes at the end of a word. It should be ignored.
                  This forms a 2 character word. If it were followed by another alpha-numeric
                  character, then it would be like the _a'b_ case above.

2. INPUT: Your program should input the name of the file to use. You can use the following test file as an example input. When we grade your program, we may use a different text file.

3. OUTPUT: Output the word count (an integer), and the average length of the words (a double with 2 digits of precision after the decimal). See p.54 and p.114 of your book.

4. Name your source file 'hmwk2.cc' and store it in your Panther directory. Create your own library files as well, and give them appropriate names such as "wordcount.h".

5. Be sure to include the appropriate information as comments in the header of your source file, as specified in homework #1's directions. Also make sure you understand the collaboration policy, and that you follow the standards given in class. (See homework #1, sections 5, 6, and 7).

6. Submit your program to the T.A.

TURN IN A HARD COPY OF YOUR SCRIPT FILE IN CLASS, after you have completed the steps below.

When you are finally done with your program, and are ready to submit it, do the following steps.

  1. script hmwk2.log

  2. This command starts recording all the things you type and the responses from the system. "hmwk2.log" is just the name of the file it creates.
  3. cat hmwk2.cc

  4. Shows the contents of the file. You may want to include other relevant commands, such as "ls -l", which gives a file list. Make sure that you repeat this as many times as you need to show all of the files (.h, .doc, .cc) that you used.
  5. g++ yourlibraryfile.cc -c

  6. Compiles "yourlibraryfile" without linking it. Repeat this step for every library file that you have.
  7. g++ hmwk2.cc -o hmwk2 [yourlibraryfile1.o yourlibraryfile2.o ..]

  8. Compiles it.
  9. ./hmwk2

  10. Runs your program. Be sure to try multiple test cases. Three test cases may be enough, but it is up to you to decide how many cases are enough.
  11. ~/../csc6001/submit file1 hmwk2/csc60XX

  12. This calls the "submit" program which is located in the TA's account. It copies the file "file1" to the TA's file space, under the subdirectory "hmwk2/csc60XX". Since everyone will have their own subdirectory under the TA's account, you can submit all of your files without needing to re-name them. Make sure that you submit all of the source files, including the .h, .cc, and .doc files. You do not submit the executable code - we will compile it ourselves. Once you submit a homework, you can re-submit it, but be careful not to do so after the due date and time. Read the submit program's response to make sure it was submitted properly.
  13. exit

  14. This command ends the recording of the things you type/system responses. You can now view "hmwk2.log"