CS 162 Spring 2000 Assignment 4 –Strings and Creating a class 100 points

Assigned: 02/28/2000

Due: 03/6/2000 at the start of class.

Pre-Lab (Do Before Lab): Bring a disk. Plan out steps needed for program.

Pairs: You may work in pairs if you want. Note, during the course of the semester, you cannot pair with any one person more than twice. If you work in a pair, turn in ONE copy that is the work of both of you, with both of your names on it. Each member of the pair will receive the same grade for that lab. In such a partnership, students must share as equally as possible the work and learning. Working together with truly shared effort and learning can be a positive experience. However, simply giving/receiving code from someone defeats the learning process. If substantial parts of a program are taken from non-partners, that is plagiarism. The copier and copyee will each receive a zero.

Main Assignment:

You will create a simplified Sentence class, and a main that will use it. The sentence class is really just an enhanced string class. It should include constructor(s), and inspectors: HowManyWords, AveWordLen, LongestWord, and LongestWordLen, plus any other functions that you need, and a << operator. It should have a sting as a data member, plus anything else that you need. Your main should demonstrate the capabilities of the class, as illustrated below. The main should ask for and accept a sentence from the user (ending in a period), and report the various pieces of information about the sentence.

Details:

  1. You should do this the right way (as in Account, rather than the simplified War program)-- you should have a .h and a .cpp file for your class, plus a .cpp file for the main.
  2. While this class is not useful by itself, it is a step on the way toward something useful (e.g. it could be part of judging the reading level of a text). More realistic tasks will be possible as you gain experience.

Hand-in:

1) Listing of the program

2) Disk with your .h and two .cpp files and your working .exe file. NAME YOUR PROGRAM FILES yourlastname4.h, yourlastname4.cpp, and yourlastname4client.cpp; Name your project yourlastname4 so that the executable will be yourlastname4.exe. If you are working in pairs, use both last names (e.g. redmondsmith4.cpp)

Miscellaneous:

1) If you have any questions about what should be done, please ask!!

2) MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors). Test it more than once - I will!

3) Remember: Indentation, meaningful variable names, symbolic constants, and meaningful comments. Weaknesses in any of these could result in points off. Also make sure you put YOUR NAME(s), section, and e-mail address in comments at the beginning of the program.

Sample Interaction:

Please enter a sentence ending in a period

There was a time, not long ago, when programmers used Pascal, not C++.

There was a time, not long ago, when programmers used Pascal, not C++

Words: 13

Mean Word Length: 4.15385

Longest Word: programmers Length: 11