Colorado State University

This file defines the header for each page. An optional "icon" image (I use the textbook):

Replace this with info about this class:

CS253: Problem Solving with C++

Spring 2013

Classy Word Search

Links to the various pages for this class:

Wish I could do this: * Schedule

Description

You receive a memo from your boss indicating that management is delighted with your work on HW2, and you have been promoted to Chief Assistant to the Assistant Chief. Hooray!

However, management has decided that it would be better if the essence of your program were converted into a standalone, reusable, C++ class, so other employees can use your work. Also, they’ve demanded many changes, because they are shiftless weasels who have no idea how much work programming really is.

For this assignment, you will write a class Words. The interface will be in Words.h, and the implementation will be in Words.cc. You will turn in both files. Neither file will contain main. This class has the concept of many guesses active at once.

Required Methods

The following public methods are required. You may not change their declarations.

Test Program

This test program:

    #include "Words.h"
    #include <iostream>

    using namespace std;

    void dump(const Words &ww) {
        cout << "There are " << ww.match_count() << " matches in "
             << ww.get_dictionary() << ":\n";
        for (int i=0; i<ww.match_count(); i++)
            cout << '\t' << ww[i] << '\n';
    }

    int main() {
        Words w("common-words.txt", "_n____l_"); // dictionary & guess
        dump(w);                                 // Show the matches.

        w = "e__er";                            // change the guess
        dump(w);                                // Show the matches.

        w += "__z_";                            // Add a guess
        const Words w2 = w;                     // Copy the whole object
        dump(w2);                               // Show the matches.

        // Show the list of matches, with each word reversed:
        cout << "And now, backwards:\n";
        for (int i=0; i<w2.match_count(); i++)
            cout << '\t' << w2(i) << '\n';      // w2(i), not w2[i]

        return 0;
    }

Should produce this output (which I’ve indented), when used with common-words.txt:

    There are 3 matches in common-words.txt:
        unlikely
        entirely
        annually
    There are 3 matches in common-words.txt:
        enter
        eager
        elder
    There are 6 matches in common-words.txt:
        jazz
        gaze
        enter
        eager
        elder
        size
    And now, backwards:
        zzaj
        ezag
        retne
        regae
        redle
        ezis

Notes

Comments

Your code must be sufficiently commented. This includes:

Ambiguity

If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.

How to submit your homework:

Follow the directions on the homework page. Turn in exactly two files, Words.h & Words.cc. Do not turn in a tar or zip file.

How to receive negative points:

Turn in someone else’s work.

Page: Main.HW3
Modified: March 02, 2013, at 11:41 AM
Wiki: pmwiki-2.2.35
CS Department
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2012 Colorado State University