CS 111 - SUMMER 2002: Homework 4

Due: Monday, June 24

Reading: Chapter 5, pages 342-370 and chapter6, pages 389-427.


Reminder: Homework is due by 11:59 PM.

Program:

Write a program which takes as input a paragraph of text. You should store the paragraph in a two-dimensional array of characters, one word or one line to each row of the array. You may assume there are no more than 300 words in the text, each sentence ends with a period or question mark, there are spaces or line breaks between words. A hyphenated words should count as one word. There may be other assumptions to make, but be sure you say what you are assuming.

One data set for your program can be found in ~homer/data4. You should test your program with at least two other small sets of data as well which you make up.

You program should,

1. Count the number of words in the text

2. Count the number of occurrences of each letter in the text and print out a list of each letter and how often it occurs. For this part you should consider a and A, b and B,... as the same.

3. Print a histogram of each letter and how often it occurs in the text.

4. Find the longest word in the text. If there is more than one word of that length, print out all of them.

5. Count the number of sentences in the text.

The histogram might look like,

A |++++

B |++

C |+++++++++++++++++++++++++++++++++++++++...

etc. However, as some letters may occur often, your histogram should print at most 35 +'s per letter. At the end of a line of 35 +'s put ...

You should break your program up into functions as usual. It is up to you how to do this but there should be at least 3 functions in addition to main.

In order to input the data into your 2 dimensional array you can either use the cin function to input the data one word at a time, or you can use the cin.getline function, (see page 324 or this short example ) to input the data a whole line at a time. You can use string functions (from cstring) or character functions from (cctype). Be careful of punctuation, it can cause minor problems. Your histogram function from the last assignment should come in handy.

You should prepare a directory called hw4 with 2 files, a source file called prog4.cc and a script file called prog4.scr which you will gsubmit. prog4.cc contains your program. prog4.scr contains a listing of the program and of the data files you used to test it, show that it compiles and then show the output of the tests including the run on my data4 file.

Extra Credit (2 points): What is the name of the poem in the data file and who wrote it ?


Academic Honesty and Collaboration

It is reasonable to discuss with others possible general approaches to problems. It is unreasonable to work together on a detailed solution, to copy a solution, or to give away a solution. If your common discussion can be detected by looking at the solutions, then there is too much collaboration. Such instances of academic dishonesty will result in a course grade of F or expulsion from Boston University.

Do not allow your work to be used by others:

Warning: If someone cheats by using your work, you will also be penalized


Page Created: May 25, 2002