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.