IUP Computer Science
CO 110     Spring 2002
 
 

Project #2
(Due 15 Feb 2002)


Write a C++ program that examines some given text, displays statistics about the text, and searches the text for a specified string.  The given text consists of the five lines below. Each line must be held in a separate string identifier and must NOT be read in.

These are the words that we are going to use
in the sentences that are to be examined.
Inspection shows nothing very odd about these
lines except maybe that the word
length varies a bit.  Did you find the answers?

Your program must do each of the following tasks.

  1. Count the total number of characters in the five lines and display this count.  (As you put these lines into your program, be sure to leave one space after the normal last word of a line and two spaces after punctuation that ends a sentence.  This way we should all get the same count.)
  2. Determine the average length of the first word on each line and display this average.
  3. Prompt the person at the keyboard to enter a short string to search for and read in the specified string.
  4. For each of the five lines, find the specified string and display that part of the line that follows the first occurrence of the specified string.
  5. Also, calculate the average position at which the specified string begins in each of the five the strings and display this average.
When you test this program, you should be sure to enter a string to search for that actually occurs in each of the five lines.  Here are some suggestions:  individual letters (a, e, i, o, r, s, n, d, t, h), two-letter groups (in, th, es, he), a three-letter group (the)  Below is a sample output when the specified string is "in"   Your program's output need not be identical to this; but it must produce readable results that contain this same information; and your program must be able to work with any reasonable string that the person at the keyboard enters.
 
 
 

What should be found in each line? in

There are 216 total characters.
The average length of the first words is 5.6

The remainders of the lines after the occurrence of "in" are:

g to use
 the sentences that are to be examined.
g very odd about these
es except maybe that the word
d the answers?

The average position for the first "in" is 17.4

Hand in a printout of your well-commented program and a printout showing the results of executing your program when the entered string is "th" and the results of executing your program when the entered string is "d"  Also, copy the source file (the .cpp file) to the Handin folder on the P: drive for this course; i.e., copy to P:\courses\spring2002\cosc\cosc110\003\hand-in   Be sure to name the .cpp file after yourself; for example, I might name something I was handing in    wolfe2nd.cpp

 There are several ways you may need to try to print the results window.  One way to print is with the "Print Screen" key - Hold down the shift key and press Print Screen; this may not output because there is no form feed at the end of the results window.  Or you may copy the entire window to the clipboard (hold down Alt and press Print Screen); then, paste it into a document, such as an MS Word document and print.  Or mark and copy the contents of the window to the clipboard, then paste it into a wordprocessor document (even Note Pad can accept this) and print.