Professional Documents
Culture Documents
a) (2 pts) A PairOfDice object represent a pair of dice. Write a declaration for the class
PairOfDice including its data members and function members based on the following
UML and save it in a file called PairOfDice.h.
PairOfDice
- die1: integer
- die2: integer
+ PairOfDice()
+ rollDice(): void
+ rolledRequestedValue(integer): boolean
+ totalRoll(): integer
+ showRoll(): void
Note: die1 and die2 store the result of rolling the dice.
b) (2 pts) A Player object represents a player of the game. Write a declaration for the
class Player including its data members and function members based on the following
UML and save it in a file called Player.h.
Player
- name: string
- nextNum: integer
+ Player()
+ Player(string)
+ getName(): string
+ getNextNum(): integer
+ setName(string): void
+ increaseNextNum(): void
+ nextMove(): void
rolledRequestedValue(): returns true if either of the dice equals the passed value or the
sum of the two dice equals the passed value and false otherwise. For example, a 3 and 6 can be
counted for a 3, 6 or 9.
totalRoll(): returns the sum of the two dice.
showRoll(): displays on the console the value of each dice with a descriptive message.
d) (3 pts) Implement the member functions for the class Player based on the following
descriptions, and save them in a file called Player.cpp.
Player(): default constructor which sets the name attribute to "" and the nextNum
attribute to 1.
Player(): a second constructor which sets the name to the passed name and the nextNum
attribute to 1.
getName(): returns the name stored in the name attribute .
nextMove(): displays on the console the value that the player needs to role in a descriptive
message including his/her name.
e) (5 pts) You will use the classes PairOfDice and Player to simulate a human playing
against the computer the dice game “Round The Clock”.
Write a C++ program which simulates the game as described above using the methods of the class
PairOfDice and Player which you developed in parts a) to d) of this question. Here are the main
steps:
1. Display a welcome header/message.
2. Ask the human player for his/her name.
3. Ask the human player if they want to keep the computer’s name as Computer or change it. If
they wish to change the name, ask them for the name.
4. Now that you have the names of the players you can create 2 Player objects with the
appropriate names assigned.
5. Create a PairOfDice object .
6. Play as many rounds as necessary until there is a winner. Keep track of the number of rounds it
took for there to be a winner. As soon as there is a winner the game is over.
7. Display the winner of the game along with the number of rounds it took for the game to end.
Following are some screen shots of a game to illustrate the expected behavior of your program. Note
this is a sample, meaning you can change the messages and the format but not the content. As this
game took 91 rounds, intermediate results have been omitted.
Following are some sample runs to illustrate the expected behavior of your program. Note this is a
sample, meaning you can change the messages and the format but not the content.