CSE 143 Summer 2001

Homework 2

Due: Electronic submission by 9:30 pm, Wednesday July 11.  Paper receipt and written report due in quiz section the following day.


Overview

The spell checking program was a big success, and you're being promoted to bigger and better things  (still no stock options though).  Your next project will be to extend the spell checking software into a very basic word processing program. The business types at your company have heard a lot of good buzz about this C++ language and they want you to start using it for all of your projects.  This means that from now on you'll be using classes in all of your code design.  

Concepts

The goal of this assignment is to gain experience using the following new concepts, as well as to continue to work with previous programming and C++ ideas.

Program Specification

The program contains 4 primary classes: WordPro, Document, Dictionary, and WordPair.

WordPro - This class represents the Word Processor, it should have functionality to start/continue a new document, spell check the document, and find a text string in the document.

Document - This class represents the text contained in your current document.  

Dictionary - This class should contain functionality for loading the dictionary file (words.txt), for storing the word-pair information from words.txt, and for looking up words for spell checking.

WordPair - This class simply contains a correctly and incorrectly spelled word and any simple methods for interacting with these words.

The interaction for the program should operate as follows:

  1. When the program starts, it should create instances of any needed data types, the constructors for your classes should perform any necessary initialization, and as in HW1, the program should load the words.txt dictionary file.
        
  2. After reading the dictionary file, the program should present the user with a menu containing the following options:

(1) Start new document (2) Continue document
(3) Spell check document (4) Find text string in document
(5) Quit  
  1. Each menu option should perform as follows, and at the end of each option (except for quit) the user should be returned to the menu:

  1. Start new document - This will start a new document, any data in the previous document is lost.  Following this, the option will behave exactly as Continue document

  2. Continue document - This should allow the user to continue entering text into a document from where she left off.  The end of input is indicated by inserting a line containing only a period '.'   At this point the program should once more present the user with a menu.  NOTE: To get a line of text from the command line, use the void stringGetLine(string &inputLine) that we have provided.

  3. Spell check document - This will behave almost exactly the same as in the previous assignment.  Each word in the document should be compared with the words in the Dictionary, if an incorrect spelling is found, it should be replaced with the correct spelling.  As before, you should allow for punctuation in the input document, though the punctuation does not need to be maintained after the spell check.  E.g. The cat, he's in a hat. ---> The cat hes in a hat .  Finally, print out the corrected text.  NOTE: As we are no longer using char *, do not use the strtok function to parse the sentences.  Instead, use the 
    string stringStrtok(string sentence, string delim) function that is provided.

  4. Find text string in document - Prompt the user for a text string.  Next, search through the current document, display the line number and line where the 1st occurrence of the string  appears. 

  5. Quit - Ends the program.

File Formats

Dictionary Words File

The same as in HW1.  

Implementation Requirements

A key goal of this assignment is to learn how to construct and use C++ classes with member functions.  The assignment is an extension of HW1, and this time you must use C++ classes and member functions for the main data structures.  Much of the design is up to you, but there are a few specific requirements.  Your program must include the following classes and members.


These classes should, of course, contain additional data and methods as needed, only the minimum required members have been listed.  Use public and private to restrict access to implementation details so they are not usable outside the class as appropriate. 

The source code for each class should be stored in a pair of files with appropriate names: classname.h for the class specification, and classname.cpp for the implementation. 

Other Implementation Requirements

Implementation Hints

Testing

Part of your job as a programmer is to verify that your code works by running appropriate tests.  That means more than just trying it with the example data given above.  You need to invent test data that will check your program under various conditions.  For example, your tests should check that the program works properly if

As part of the report you turn in with this assignment (see below), you will need to describe how you tested the program and why you believe that your tests demonstrate that it works properly.

Sample Program 

To give you an idea of what is expected of this program, a sample executable is provided.  This is simply one idea of how your  program should operate.   Do not assume that your program should be a complete duplicate of the sample solution.  Remember, you need a words.txt file in same directory as the program for it to work correctly.

hw2Solution.exe

Starter Code

To allow you to use only strings in this project, code is supplied containing string versions of getline and strtok.  Download these here and use them in your project where appropriate.

stringUtil.cpp

stringUtil.h

Help!!! Where do I start?

In any non-trivial project, programming or otherwise, the job can often seem overwhelming at first - too many things to do all at once and no clear idea where to start.  An important skill to develop is to figure out what you can do first, without having to finish other things.  Here are some suggestions.

  1. The place to start is not, I repeat not at the computer keyboard.  You have to do some thinking and planning before you start writing code.  Premature use of the computer is guaranteed, I repeat guaranteed to waste huge amounts of your time.
  2. Start by planning, on paper, classes and functions that you will need.  Write down fairly detailed data structure declarations.  Draw pictures.  Figure out what the functions need to do and what their parameters should be - but don't spend much time on implementation details now.
  3. Figure out how you will test your code.  As you design data structures and specify functions, think about how they could fail(!) if you make a mistake.  Design a test that will catch that bug if it happens.  Write it down now, not later.
  4. Only when you've gotten this far should you start writing detailed code on the computer.  You should develop the code bit-by-bit, getting some parts working, then add more until you have everything done.  You might try first getting the data structure definitions right, then implement the code to read the data from the file and store it in the data structure.  Inspect the data structure with the debugger or by printing it out at this point to verify that things are working so far.  Then add code to interact with the user, reading and correcting sentences.  Keep testing as you go.

Time spent planning and thinking at the beginning of the project will be more than repaid by time saved that would otherwise be needed to debug and fix problems.

Report

When you turn in your program, you must also turn in a short report that discusses the following issues:

  1. Planning - How did you plan your code design for this problem.  What kinds of data structures and functions seemed necessary?
  2. Implementation - Describe the implementation.  What data structures did you use?   How did you structure the code?  Were there any significant differences between the original design and the final program?  If there were major changes, why were they needed?
  3. Testing - Describe the test cases you chose.  Describe the kinds of bugs you found using tests.  If some of your test cases still don't work, or there are parts of the program that are incomplete, describe that.  Attach some of your test cases and results to support your claims.
  4. What did you learn from completing this project?  This could include things you learned about program specification and design, C++ language issues, developing test cases, debugging, etc.

This report need not be long, but it should be complete enough to give us a good picture of what you accomplished.

Electronic Submission

When you've finished your program, turn it in using this turnin form. Print out the receipt that appears, staple it and your report together, and hand it in during quiz section.