![]()
This assignment uses the Dice class from Chapter 5 of your
textbook to simulate a slot machine. It is meant to familiarize
you with the following concepts discussed in class and the textbook:
|
![]() |
Write a program to simulate the play of a slot machine. Your program should do the following:
If the same number appears on all three wheels, the gambler wins
10 times the coin. The same two numbers and the "*" is
equivalent to the same number appearing on all three wheels.
| If the same number appears only on two wheels, the gambler wins 2
times the coin. A "*" and any other number is equivalent
to the number appearing on two wheels.
| If the numbers are all different, the gambler gets no winnings. | |
Below are two sample runs. Your output does not have to look exactly like this, but should follow the specifications above. Input from the user is shown in italics.
How many dollars do you want to spend? 4 Which dollar machine do you wish to play (one, five, or ten)? one You have 4 coins. Spinning... Numbers are 5 * 9 *** Congratulations, you won $2 Spinning... Numbers are 8 * 8 *** Congratulations, you won $10 Spinning... Numbers are 9 2 2 *** Congratulations, you won $2 Spinning... Numbers are 8 7 5 Total winnings are $14 You won money! Do you want to play your $14 in winnings (yes or no)? no
How many dollars do you want to spend? 88 Which dollar machine do you wish to play (one, five, or ten)? tne We do not have a tne slot machine. (one, five, or ten)? fve We do not have a fve slot machine. (one, five, or ten)? ten You have 8 coins, you can spend all but 8 dollars. Spinning... Numbers are 7 2 4 Spinning... Numbers are 8 7 10 Spinning... Numbers are 5 7 4 Spinning... Numbers are 7 4 6 Spinning... Numbers are 10 * 3 *** Congratulations, you won $20 Spinning... Numbers are 2 9 3 Spinning... Numbers are 4 5 7 Spinning... Numbers are 3 * 5 *** Congratulations, you won $20 Total winnings are $40 You lost money! Do you want to play your $40 in winnings (yes or no)? yes You have 4 coins. Spinning... Numbers are 9 8 9 *** Congratulations, you won $20 Spinning... Numbers are 5 6 7 Spinning... Numbers are 1 6 3 Spinning... Numbers are 2 4 7 Total winnings are $20 You lost money! Do you want to play your $20 in winnings (yes or no)? yes You have 2 coins. Spinning... Numbers are 8 3 1 Spinning... Numbers are 2 7 5 Total winnings are $0 You lost money! You have no more money, go home.
Your SlotMachine class should provide at least the following member functions:
| int Spin () // spins the
slot machine, generating 3 random values // returns winning factor (i.e., 10 if all matched, 2 if two matched, // or 0 if none matched) and increments number of spins on the machine int NumSpins() // returns the number of
spins on the machine | |
Your Gambler class should provide at least the following member functions:
int GetWinnings ()
// returns amount of money the gambler has won
| void UpdateWinnings (int amount) // updates the gambler's
winning by the given amount | // (i.e., positive for wins and negative for losses) bool PlayAgain ()
// prompt the user to play again | // returns true if the user answers yes, // otherwise returns false |
Like the Dice class shown in the book, you should implement each of your classes in two separate files: e.g., machine.h and machine.cpp. See the code here for a start.
![]()