Your instructor will assign you one of the problems below. To
solve your problem, write a program that reads the necessary
information to compute and output the indicated values, as
efficiently as possible. Following the pattern in the lab
exercise, first, *design* using OCD; then *code* your
design in C++ using stepwise translation; finally, test your
program thoroughly.

Project #13.1: Amagic squareis an n-by-n table in which the integers 1, 2, 3, ..., n^2 appear exactly once, and all column sums, row sums and diagonal sums are equal. For example, here is a 5-by-5 magic square in which all the rows, columns and diagonals add up to 65:-------------------------- | 17 | 24 | 1 | 8 | 15 | -------------------------- | 23 | 5 | 7 | 14 | 16 | -------------------------- | 4 | 6 | 13 | 20 | 22 | -------------------------- | 10 | 12 | 19 | 21 | 3 | -------------------------- | 11 | 18 | 25 | 2 | 9 | --------------------------Here is apartialalgorithm for constructing an n-by-n magic square, for any odd integer n:

- Set
to 1.`i`

- Set
to be the first row; set`r`

to be the middle column.`c`

- Repeat:

- Place
in row`i`

and column`r`

.`c`

- Move
`r`

up one row, and moveone column to the right.`c`

- If the move takes you past the top,

Resetto be the last row.`r`

- If the move takes you to off the right side of the grid,

Setto be the first column.`c`

- If the move takes you to an already filled square

Move`r`

downtwo rows and`c`

to theleftone column.The algorithm is missing two crucial steps: (1) when should the loop terminate? and (2) what happens when the algorithm tries to work its way up the main diagonal a second time? Both of these steps are fixed with one statement each, although the second problem will require a bit more thought---consider the example above when

= 16 is placed into the square.`i`

Build a

`MagicSquare`

class as a`vector`

of`vector`

s. Given an odd integern, its constructor should use the preceding algorithm to initialize the two-dimensional structure. Provide an output operator to display the magic square using the format shown above. Then write a driver program that inputs the valuenand, using your`MagicSquare`

class, constructs and outputs the corresponding magic square.

Project #13.2: A certain automobile dealership sells ten different models of automobiles, and employs eight salespeople. Each month, the sales are recorded in a table in entry [r][c] corresponds to the number of sales of model r by salesperson c. For example, a typical sales table might appear as follows:0 0 2 0 5 6 3 0 5 1 9 0 0 2 3 2 0 0 0 1 0 0 0 0 1 1 1 0 2 2 2 1 5 3 2 0 0 2 5 5 2 2 1 0 1 1 0 0 3 2 5 0 1 2 0 4 3 0 7 1 3 5 2 4 0 2 6 1 0 5 2 1 4 0 2 0 3 2 1 0Write a program that, given such a sales table, produces a monthly sales report, displaying the monthly sales and the totals for each model and salesperson in easy-to-read format:Sales Person Model : 1 2 3 4 5 6 7 8 : Totals ------------------------------------------------------ 1 : 0 0 2 0 5 6 3 0 : 16 2 : 5 1 9 0 0 2 3 2 : 22 3 : 0 0 0 1 0 0 0 0 : 1 4 : 1 1 1 0 2 2 2 1 : 10 5 : 5 3 2 0 0 2 5 5 : 22 6 : 2 2 1 0 1 1 0 0 : 7 7 : 3 2 5 0 1 2 0 4 : 17 8 : 3 0 7 1 3 5 2 4 : 25 9 : 0 2 6 1 0 5 2 1 : 17 10 : 4 0 2 0 3 2 1 0 : 12 ------------------------------------------------------ Totals : 23 11 35 3 15 27 18 17Use object-centered design to design and implement a`SalesTable`

class and use it to solve this problem. In addition to an output operation that displays a`SalesTable`

in a format like that shown above, its constructor should allow a`SalesTable`

object to be initialized with data from a file. It should also provide operations to determine the total sales for a given salesperson, as well as the total sales for a particular model of automobile.

Project #13.3: In Chapter 13 ofC++: An Introduction to Computing, a`Matrix`

data type is presented. Get this data type fully operational, including functions (or methods if you define it as a class) to perform the addition, subtraction, multiplication, transpose, test equality, input, and output operations for`Matrix`

objects. To test your class, create a driven driver program that implements a menu-driven`Matrix`

calculator.

Project #13.4: Create a`TicTacToeGame`

class that stores the 3-by-3 board, and methods to initialize the board, display the board, and take a turn. Add a driver program that uses your class to allow a person to play Tic-Tac-Toe against the computer.

Turn the following things:

- This grade sheet.
- Your OCD.
- Your source program.
- The output from an execution of your program.

Lab Home Page | Lab Exercise

© 2003 by Prentice Hall. All rights reserved.

Report all errors to Jeremy D. Frens.