CSC 172
Homework 2

Assigned Feb. 13, due Feb. 25 (bridge-hand design document due Feb. 18), to be done in teams of two

PSP recording:

Before you start on the programming part of the assignment, estimate how long the program will be and how long it'll take you to write. Enter your estimates using the PSP forms (click on "Input" under "Product Plan Estimates").

While you work on the programs, keep track of all the error messages and other defects you encounter (click on "Input" under "Defect Removal Data"). (I recommend having a Web browser open while you work, so you can record each defect as you find it, rather than trying to remember them all later.)

While you work on the programs, keep track of how much time you spend on various phases of program development (click on "Input" under "Time Management Data"). Again, I recommend recording this stuff while you work rather than trying to reconstruct it after the fact.

The Programming Part:

You are to design, write, test, and debug several C++ programs:
  1. Programming Problem 2 on pages 50-51 of the textbook (the bridge-hand problem). Note: By Feb. 18, you should have completed the design of the program; turn in a list of data type definitions and functions, specifying the parameters (if any), return type (if any), and I/O behavior (if any) of each function.
    By Feb. 25, you are to turn in a complete, compiling, working program that solves this problem.

    Requirements modification, Feb. 25: There are now five suits: spades, hearts, diamonds, clubs, and fnords (represented by an F). There's a new rank above Ace: Professor (represented by a P); a Professor is treated as a face-card with a value of 5. There are ten cards in a hand, not thirteen. And a hand gets an extra point if it has exactly seven cards in a suit (in addition to the points it would have gotten otherwise).

  2. Do problem 15, chapter 2, pp. 107-108 (on computing xn). Note that parts a, b, and c ask you to write a function (which you should test and debug); parts d and e should be answered in writing and turned in along with the program.
    To test this, you'll probably want to write a main program that gets x and n from standard input, then calls each of the functions in turn and prints the results.

  3. Do problem 9 (chapter 2, pp. 105-106). This question asks "what output does the following program produce?", which technically you can answer just by typing it in and running it. So to make sure you understand the program, write an iterative program that prints the same sequence of "first" and "last" values for any given n.

  4. Write a function that takes in two strings, a pattern and a target, and determines whether the pattern "matches" the target. The trick is that the pattern may contain "?" characters, which match any single character in the target, and "*" characters, which match any zero or more characters in the target.
    For example, the pattern "abc?de" matches the targets "abcxde" and "abccde", but not "abcde" or "abcxyde".
    Similarly, the pattern "abc*de" matches the targets "abcde", "abcxde", "abcxyde", and "abcdedededede", but not "abcdededededed".
    For that matter, the pattern "*abc?de*?f" matches the targets "abcxdegf", "abcddegf", and "xyzabcadexyzf", but not "abcdef", "abcdexf", "abcxdef", or "abcxdexfg".
    To test this, you'll probably want to write a main program that gets the pattern and the target from standard input, calls the matching function, and prints out whether they matche or not. Since you'll have a lot of test cases to try, it might save you some time to put this inside some kind of loop.

How to turn this in:

The PSP forms are sent to me automatically when you use the on-line forms, so don't worry about them. Send me an e-mail, attaching each of your complete C++ source files and including the written parts of the assignment as the body of the message (or as an attached text file).
If you're using multiple source code files for each program, please put the source code for each program into its own folder, zip the folder, and send me the resulting zip file as an attachment.
Last modified: Wed Feb 13 16:44:45 EST 2002
Stephen Bloch / sbloch@adelphi.edu