Change into your cps6 directory and create a directory called "assign4". Change into the "assign4" directory. If you did this correctly, when you type "pwd" you should see a long path name that ends with "/cps6/assign4"
In order to do this assignment, you need to copy a Makefile using the following "cp" command (don't forget the trailing period, or dot):
cp ~dr/cps6/assign4/* .
This command will copy files in the directory ~dr/cps6/assign4 into your directory for you to use. If you type "ls" you should see "Makefile" and "slotgame.cc".
For the programming problem that follows, you should use the style rules discussed in class, which includes meaningful variable names, indentation, and comments at the top of the file and for each function.
Refer to the Dice class in Chapter 5 of your textbook for this problem.
Write a program slotgame.cc to play the slot machine. The file slotgame.cc has been provided for you to help you get started. Your program should do the following.
In addition, your program should have at least two meaningful functions besides the main function. These functions must be organized in such a way that you do not pass Dice as parameters. We'll learn later in the semester how to pass class objects as parameters
Below are two sample runs. Your output does not have to look exactly like this, but should follow the specifications above.
> slotgame How many dollars do you want to spend:? 7 Which dollar machine do you wish to play (one, five, or ten)? one Spinning... Numbers are: 2 9 1 Spinning... Numbers are: 5 * 9 *** Congrats, won $2 Spinning... Numbers are: 8 * 8 *** Congrats, won $10 Spinning... Numbers are: 9 2 2 *** Congrats, won $2 Spinning... Numbers are: 8 7 5 Spinning... Numbers are: 4 * 5 *** Congrats, won $2 Spinning... Numbers are: 9 9 2 *** Congrats, won $2 Total winnings are $18 You won money! >> slotgame How many dollars do you want to spend:? 88 Which dollar machine do you wish to play (one, five, or ten)? ten 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 *** Congrats, won $20 Spinning... Numbers are: 2 9 3 Spinning... Numbers are: 4 5 7 Spinning... Numbers are: 3 * 5 *** Congrats, won $20 Total winnings are $40 You lost money! >
Make a copy of the program slotgame.cc called slotgameX.cc using the "cp" command by typing:
cp slotgame.cc slotgameX.ccModify slotgameX.cc in the following manner.
Here is a sample run:
>> slotgame 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 can spend all but 8 dollars Spinning... Numbers are: 6 3 1 Spinning... Numbers are: 5 7 10 Spinning... Numbers are: 4 6 1 Spinning... Numbers are: 7 4 3 Spinning... Numbers are: 10 * 8 *** Congrats, won $20 Spinning... Numbers are: 1 9 3 Spinning... Numbers are: 2 8 6 Spinning... Numbers are: 1 * 5 *** Congrats, won $20 Total winnings are $40 You lost money! Do you want to play your winnings? (yes or no): yes Spinning... Numbers are: 9 8 9 *** Congrats, won $20 Spinning... Numbers are: 5 6 7 Spinning... Numbers are: 1 6 3 Spinning... Numbers are: 2 4 7 You lost money! Do you want to play your winnings? (yes or no): yes Spinning... Numbers are: 8 3 1 Spinning... Numbers are: 2 7 5 You lost money! You have no more money, go home. >
Submitting Programs
When your programs compile and produce the correct output, create a "README" file (please use all capital letters). Include your name, section number, the date, and an estimate of how long you worked on the assignment in the "README" file. You must also include a list of names of all those people with whom you collaborated on the assignment.
To submit your programs electronically type (leave off slotgameX.cc if you did not do the extra credit):
submit6 assign4 README slotgame.cc slotgameX.cc
You should receive a message telling you that the program was submitted correctly.