Assignment 06

Due: Wednesday, March 13, 2019 at Noon1 100 pts

For this assignment you will submit (in the usual way) multiple files. These files will contain a C++ program that you have named appropriately, each file with an appropriate name and appropriate extension. Be sure that your program compiles using the g++ compiler before you submit it. To compile a program with multiple files, use the usual fg++ command but instead of the single file you compiled before, compile *.cpp and the compiler will "grab" all the cpp files in that directory. So, you see, it's important that you put all the files for a particular program in their own directory! You don't have to list the header files; that will happen automatically. Use cssubmit in the usual way.

Background: Moe has been pleased with your work so far. However, Moe has been losing money on his slot machine and now wants you to re-implement it. This time, you are to use functions. Furthermore, you are to make the machine work in Moe's favor! As you are well aware, Moe has had his run-ins with the law. So, he wants you to make the machine pay him enough that he can afford to pay off the cops on a regular basis. He also has problems with a springy cord on his phone, but there's no solving that problem.

Specifications: Your program is to fill the requirements of homework #4 along with the optionals of multiple spins and displaying letters, but this time using functions and multiple files. You are to put your function prototypes, constant declarations, and structures in a header ( .h) file, and the implementations of the functions in a implementation ( .cpp) file. Main will be in its own file. So, you should have 3 files in all. You are to decide how to apply "functionalizification" for this assignment. You will be graded on how effectively you do this. Use functions to avoid repeated code, clean up your main, and increase the efficiency of your coding.

Additional Requirements: For your implementation of this program, you are to use a struct to represent a slot machine. In fact, you could call it a slot_machine. And, so, like, uhhh, n'stuff, what IS a slot machine? Since the machine knows how much money you're going to play with, it should include the game balance. And, since the machine tumblizes stuff, I think it should include the results for three tumblers. Having this information wrapped up in a "bag-o-variables" might just make it easier to code with. So....do it! (It's mandatory anyway.)

You are also to include a function in your program that will put the outcome of the game definitely in Moe's favor. This function will not be called explicitly by the user of the program; it will be called when the user (player) wins too much. The function is to work like this: If, anytime after the fifth spin, the player has a net gain, the machine will start cheating and continue so. Thus, any subsequent spin will have a significantly higher chance of losing. [By the way, this would be a coooool place to use function overloading: a spin function that doesn't cheat, and one that does. It's not required, but a darned good idea!]

So what does this mean? First, the first five spins are off-limits to Moe; they're fair. But after that, once the player has a net gain before the next spin, your code will use a different function to determine the outcome of the spin from then on. You have to use your imagination on how to do this. If you are not careful, then the outcome could look like this:

aab win $1 bbb win $30 aba win $1 bca lose $5 abc lose $5 net gain so far: $22 cab lose $5 function kicks in; still up $17 cab lose $5 again, still up $12 cab lose $5 again, still up $7 . . .

You see what's happening here? It's obviously cheating. Can YOU do better?

When you submit:

  • choose option 3

  • choose option 1

  • choose option 2 and transfer $200

  • choose option 3 and spin 30 times

  • cash out

As always, if you have questions, don't hesitate to ask your instructor or the tutor in the lab in the evenings.

1This, incidentally, is when many bars open. Hmmm.