Assignment 04

Due: Monday, Feb. 22, 2016 at noon 100 pts

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to submit a file for this course electronically, from the directory in which the file resides type in at the UNIX prompt the command: cssubmit 1570 section_letter assignment_number. Be sure that only the file you want to submit is in that directory - make a directory for every assignment! The submit system will deliver every .cpp file in the current directory to me. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.

  1. The "Check bank balance" option is to display their bank balance and the game balance. The game balance will start at $0.00 and will accumulate value as the user transfers funds from the bank to the game or as winnings accrue. Now, bank (Cletus's Bankk - a future project for you!) balance will be determined by your code using a random value between $200 and $1000, but only as multiples of $100, at the beginning of the program. The only way the bank balance can change after that is when option 2 is chosen. And no transfer back into the bank can be made.

  2. The "Transfer.." option will allow the user to transfer funds not to exceed the bank balance to the game balance to be used to gamble with. Output to the screen both balances when a transfer is made.

  3. "Play" allows the user to play the game. The player is first asked how many spins they desire (a positive integer). The game will randomly produce three characters, a -> d. That is, a spin could produce the result [ a d d ], or it could be [ d c a ], or .... You get the idea. Imagine there are three tumblers (as in all these kinds of machines) but the tumblers have only 4 sides with pictures of the letters a, b, c, and d. If any two pictures (letters) match, the game balance is increased by $1; if all three match, the game balance increases by $30. If none match, then balance decreases by $5. Now, your game must check to see if the game balance for a player can handle the potential loss when they enter the number of spins. During the play, output to the screen on one line the outcome of any roll and then the payoff or loss and then the current game balance.

  4. "Leave" will report the amount the player has in the game balance and bank balance.

Now remember, if the player has no more funds (anywhere), then they have no choice but to "Leave".

Note: Your code for this and future assignments should check the validity of user input when user input is prompted. This is sometimes called "range checking" or "input cleansing". This means that the values that a user inputs should fall in the requested range of values, or be reasonable inputs. For example, if your program was to prompt for a person's age, and they enter a non-positive value or a value over, say, 120, then your code should issue an error message and re-prompt. Your code is not expected to check for type. That is, if you prompt for a char, assume you get a char; if you prompt for an int, assume you get an int; etc.

When you submit: the submit script will (attempt to) compile and execute your program in the process. This means that you will be the "user" of the program for that few minutes. Now, in order that the grader isn't driven crazy by a multitude of inputs/outputs, you will ALL input the same values so that he has uniform output to grade. They are:

  • seed the random number generator to ..... ummm. ..... 5, yeah 5.

  • choose option 3

  • choose option 1

  • choose option 2 and attempt to transfer $1200

  • choose option 2 and attempt to transfer -$300

  • choose option 2 transfer $200 to game balance

  • choose option 3 and request 300 spins

  • choose option 3 and request -5 spins

  • choose option 3, spin 40 times

  • choose option 3, spin 1 time

  • quit

And, as always, if you have any questions about this assignment, don't gamble....ask your instructor.

Background: Your last assignment was to write a program to help out in ag-electronics-engineering. You did well; the cows are behaving. Now for something new and completely different: gamblengineering. You are going to write the software to run a slot machine. It's a combination of ATM (automatic teller machine - produces money "magically") and a SLOT machine (you know, that machine that you pull handle and three tumblers spin and you want the pictures to match). Pull this off and Cletus will be able to make lots of money off his friends and neighbors.

Specifications: Your program will simulate the machine that will present a menu with these choices:

OPTIONS ------- 1. Check bank balance 2. Transfer funds to game 3. Play 4. Leave (cash out)

A player can "leave" anytime, but he/she cannot "play" before transferring any funds to the game, and cannot "transfer" before first checking savings balance. Thus, it should be clear by now, that the first choice any player must make is to check their balance. They must then transfer funds to the game. After this, players are free to make any choice of the menu in any order as long as they have funds to cover their addiction. When a player chooses "leave", the program will end and the player is notified of their bank balance and their game balance.

Specs on the Specs: