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.
Do Programming Project 5 on page 747 at the end of Chapter 12. However, instead of the very last paragraph of the project, just implement in your Text class overloaded + (concatenation), == (equals), and = (assignment) operators. Treat the tab character the same as a space. Implement your Text class as separate interface and implementation files and provide a separate file with a main() function that tests your Text class. This assignment is due on Monday, May 3 (the first day of finals week).

Assignment 9.
Do Programming Project 3 on page 694 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 Monday, April 19.

Assignment 8.
This assignment is a modification of Programming Project 11 on page 639 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. Try to design your program so that it is easy to "swap in" a new strategy for the computer player. Try to 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). Try to make it easy to modify the program so that two humans players can play against each other. Also, try to make it easy to modify the way the program prints out a tic-tac-toe board. This assignment is due on Monday, April 12.

Assignment 7.
This assignment is a slight modification of Programming Project 3 on page 556 at the end of Chapter 9. This assignment extends Assignment 6. Redo your Fraction class using separate "interface", "implementation", and "application" files. That is, break up your solution to Assignment 6 into three files, a fraction.h file, a fraction.cpp file, and a UseFraction.cpp file. In addition, create a second (simple) application file UseFraction2.cpp that makes use of the Fraction class. To show that you understand how separate compilation works, turn in, along with these four source files, the compiled and linked executables UseFraction.exe and UseFraction2.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 Friday, March 26.

Assignment 6.
Do Programming Project 4 on pages 515-516 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 Friday, March 12.

Assignment 5.
Do Programming Project 9 on pages 379-380 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 1.

Assignment 4.
This assignment is a slight modification of Programming Project 8 on pages 301-302 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 2). 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). Here is a sample file that you can use for input to your program. This assignment is due on Monday, February 16.

Assignment 3.
This assignment is a modification of Programming Project 2 on page 300 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 2). 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. This assignment is due on Monday, February 9.

Assignment 2.
Do Programming Project 3 on page 220 at the end of Chapter 4. This assignment uses call-by-reference, which is described in the textbook on pages 184-187. This assignment is due on Monday, February 2.

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 print_frame 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 23.

Return to the CS 124 home page.


compliments and criticisms