|
|
 |
|
|
|
|
Add up the points in the hand and print one of the following messages. |
|
|
|
|
| | |
|
|
|
|
From 13 through 16 points, |
|
|
|
| | |
|
|
|
|
From 17 through 19 points, |
|
|
|
| | |
|
|
|
|
From 20 through 22 points, |
|
|
|
| | | |
|
|
|
|
|
|
2. Write an interactive program that plays tic-tac-toe. Represent the board as a three-by-three character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position will be marked on the board with an O, and the second player's position will be marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have three marks in a row, in a column, or on a diagonal. A draw occurs when the board is full and no one has won. |
|
|
|
 |
|
|
|
|
Each player's position should be input as indices into the tic-tac-toe board that is, a row number, a space, and a column number. Make the program user friendly. |
|
|
|
 |
|
|
|
|
After each game, print out a diagram of the board showing the ending positions. Keep a count of the number of games each player has won and the number of draws. Before the beginning of each game, ask each player if he or she wishes to continue. If either player wishes to quit, print out the statistics and stop. |
|
|
|
|
|
|
|
|
3. Write a C++ program to read in two 2-dimensional arrays, and then multiply one by the other. This is called matrix multiplication. For example, if firstArray (a 2-row by 2-column array) appears as |
|
|
|
 |
|
|
|
|
2 7
9 3 |
|
|
|
|
|
|
|
|
and secondArray (a 2-row by 1-column array) appears as |
|
|
|
 |
|
|
|
|
8
6 |
|
|
|
|
|
|
|
|
then the product matrix is |
|
|
|
 |
|
|
|
|
productMatrix[0][0] = 2 * 8 + 7 * 6
productMatrix[1][0] = 9 * 8 + 3 * 6 |
|
|
|
 |
|
|
|
|
Matrix multiplication can be done only if the number of columns in the multiplicand (the first array) equals the number of rows in the multiplier (the second array). |
|
|
|
 |
|
|
|
|
The program should read in the two arrays, test to see if multiplication is possible, and then multiply them if it is. The output will be a printout of the two arrays and will either output the product array or print a message saying that multiplication is not possible. |
|
|
|
|
|
|
|
|
4. Photos taken in space by the Galileo spacecraft are sent back to earth as a stream of numbers. Each number represents a level of brightness. A large number represents a high brightness level, and a small number represents a low level. Your job is to take a matrix (a two-dimensional array) of the numbers and print it as a picture. |
|
|
|
|
|