Programming Assignments for CS 124

The programs that you turn in will be graded according to the criteria given in the first of the following three links. The second link gives detailed instructions on exactly how you are to turn in your finished assignments. The programs that you turn in should conform to the style guide contained in the third link (it was written by Cay Horstmann, a well known C++ and Java author).

Program grading criteria
Turning in your assignments
C++ Language Coding Guidelines

Below are your programming assignments. The due date for each one is contained in the assignment description.

Assignment 10. (Optional)
Do Programming Project 2 on page 658 at the end of Chapter 12. This assignment is due on Monday, May 5 (the first day of finals week). This assignment is optional in the sense that if you do it, I will drop your lowest homework grade (or, to put it another way, only your nine highest homework grades will count towards your final grade in the course).

Assignment 9.
Do Programming Project 3 on page 612 at the end of Chapter 11. In particular, do the more difficult version of the problem where the user can input a double using e-notation. This assignment is due on Wednesday, April 23.

Assignment 8.
This assignment is a modification of Programming Project 12 on page 564 at the end of Chapter 10. Instead of writing a program so that two users can play tic-tac-toe, write a program so that one user can play tic-tac-toe against the computer. So you will need to implement a tic-tac-toe strategy in your program. I will not grade you on how well your strategy plays tic-tac-toe, so you can implement as trivial a strategy (or strategies, see below) as you wish. But whatever your strategy is, be sure to clearly document it. Your program should display the tic-tac-toe board after each player makes its move (including the computer player). Your program should not allow the human player to make an illegal move. Your program should automatically detect when one of the players has won or the game has tied.

Write your program in as modular a form as you can. For example, you might want to write parts of your program as classes. Write your program so that it would be fairly easy to make the following kinds of modifications. Design your program so that it is easy to "swap in" a new strategy for the computer player. Make it easy to modify the program so that the computer would play against itself (with the same or different strategies for each computer player). Make it easy to modify the program so that two humans players can play against each other. Also, make it easy to modify the way the program prints out a tic-tac-toe board. (For example, if you have a "human player" class and a "computer player" class (or a couple of "computer player" classes, one for each strategy) and a "board" class, then you could have a human play against the computer by instantiating one of each class in your main function. And you could have two humans play each other or have the computer play itself by instantiating two of the same kind of player classes (note that this will work best if all the player classes implement the same public interface). The board prints itself out by overloading operator<<.) This assignment is due on Wednesday, April 16.

Assignment 7.
This assignment is a slight modification of Programming Project 5 on page 489 at the end of Chapter 9. This assignment extends Assignment 6. Redo your Rational class using separate "interface", "implementation", and "application" files. That is, break up your solution to Assignment 6 into three files, a Rational.h file, a Rational.cpp file, and a RationalClient.cpp file. In addition, create a second (simple) application file RationalClient2.cpp that makes use of the Rational class. To show that you understand how separate compilation works, turn in, along with these four source files, the compiled and linked executables RationalClient.exe and RationalClient2.exe. Place all six files into a single zip file and send me the zip file. Please do not send me a Microsoft Visual Studio project folder (project folders are way to large and contain far more stuff than I need for this assignment). This assignment is due on Monday, March 31.

Assignment 6.
Do Programming Project 4 on page 453 at the end of Chapter 8. This assignment extends Assignment 5. Be sure to include a main() function in your program that tests your implementation of the rational number class. This assignment is due on Wednesday, March 26.

Assignment 5.
Do Programming Project 10 on pages 331-332 at the end of Chapter 6. Be sure to include a main() function in your program that tests your implementation of the rational number class. This assignment is due on Monday, March 3.

Assignment 4.
This assignment is a slight modification of Programming Project 8 on page 265 at the end of Chapter 5. Do the harder version of the problem, so there can be any number of occurrences of the string #N# in the input file. Your program should prompt the user for the name of the input file. Instead of using an output file, your program should use standard output (if a user wants to use an output file, the user can use I/O redirection). Notice that when you use standard output for the output of your program, there is a slight problem with the prompts; they get mixed in with the program's output, which is not what we want. So use the output stream cerr (standard error) for your program's prompts (there is an example of using cerr in the third example from February 4). When you prompt the user for the name to substitute into the output, assume that the name is contained in a single string (even though the book's problem says that the name is stored in two strings) and that string will be used for every occurance of #N# in the input file. Here is a sample file that you can use for input to your program. This assignment is due on Monday, February 18.

Assignment 3.
This assignment is a modification of Programming Project 2 on page 264 at the end of Chapter 5. First, do Programming Project 2, with the additional requirement that your program should prompt the user for the name of the input file (see the example programs from class on February 4 and also see the section "File Names as Input" starting on page 213 of the textbook). After you have done that, rewrite your program as a "filter" that reads its input from "standard input" (i.e., cin) and writes its output to "standard output" (i.e., cout). Your program should output only one thing, the average value. If you wish, your program can make some use of "standard error". (Notice how, as a filter, your program is a kind of glorified function that computes the average of any number of numbers.) You will turn in two programs for this assignment. Please put them in a zip file (as explained in the instructions for turning in programming assignments). This assignment is due on Monday, February 11.

Assignment 2.
Do Programming Project 5 on page 195 at the end of Chapter 4. This assignment uses call-by-reference, which is described in the textbook in Section 4.2. This assignment is due on Monday, February 4.

Assignment 1.
Write a function called print_frame that takes two (even) integer parameters. This function should print a "frame" in the console window consisting of two squares, one inside of the other, with the corners of the squares connected with 45 degree lines. The dimensions of the two squares are given by the two integer parameters. Here are a couple of examples. The function call print_frame(20, 12) should produce the following output in the console window. (Notice that these really are "squares" in that they have the same number of characters in their horizontal and vertical sides.)
********************
**                **
* *              * *
*  *            *  *
*   ************   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   ************   *
*  *            *  *
* *              * *
**                **
********************
The function call print_frame(6, 24) should produce the following output. Notice that the larger of the two input integers should be the dimension of the outer "square".
************************
**                    **
* *                  * *
*  *                *  *
*   *              *   *
*    *            *    *
*     *          *     *
*      *        *      *
*       *      *       *
*        ******        *
*        *    *        *
*        *    *        *
*        *    *        *
*        *    *        *
*        ******        *
*       *      *       *
*      *        *      *
*     *          *     *
*    *            *    *
*   *              *   *
*  *                *  *
* *                  * *
**                    **
************************
Also write a main() function that prompts the user for the two even integer dimensions. If one of the input integers is not even, ask the user for another integer. The main() function should then call the print_frame() function with the user's parameters. The main() function should continue to prompt the user for input and draw "frames" until the user inputs 0 as one of the dimensions. This assignment is due on Friday, January 25.


Return to the CS 124 home page.


compliments and criticisms