Advertisement
akosiraff

Slot Machine Simulation

Jun 9th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/slot-machine-simulation/
  3. For this assignment you will have to investigate the use of the C++ random generator function, rand(). Rand() produces a random integer in the range of 0 to RAND_MAX (a constant — often 32767 — defined in the stdlib, automatically included in all of your projects). You can find this in the text or using the online resources given in the lectures.
  4. OPTION A (Basic) A Slot Machine Simulation
  5. Understand the Application
  6. What it Looks Like to the User
  7. The program will loop, asking the user for a bet amount from 0 to 50 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are: BAR 7 BAR, 7 7 cherries, cherries BAR space, space BAR BAR, or cherries cherries BAR.
  8. •Each of the three positions in the string could be one of the following: “BAR”, “7″, “cherries” or “space”.
  9. •Each of the three output positions is must be generated by your program randomly with probabilities:
  10. ?BAR (40%)
  11. ?cherries (30%)
  12. ?space (5%)
  13. ?7 (25%)
  14. ?Therefore, BAR should be the most frequent symbol seen and space or 7 the least frequent.
  15. •The following combinations should pay the bet as shown (note ORDER MATTERS):
  16. ?cherries [not cherries] [any] pays 5 × bet (5 times the bet)
  17. ?cherries cherries [not cherries] pays 15 × bet
  18. ?cherries cherries cherries pays 30 × bet
  19. ?BAR BAR BARpays 50 × bet
  20. ?7 7 7 pays 100 × bet
  21. •After the pull, display the three strings regardless of the outcome. If the user did not win, tell him/her “Sorry, you lose.” If he won, pay him by displaying his winnings (his original bet times the winning factor from the above table). Then, repeat the whole process by requesting another bet amount.
  22. Position counts! If you read the above bullet that contains the warning “ORDER MATTERS”, you will see that cherries bar cherries pays 5× while cherries cherries bar pays 15× and bar cherries cherries pays nothing.
  23. A Helper Class: TripleString
  24. We create a new data type to use for this assignment: class TripleString. TripleString will consist of three private member strings as its basic data: (string1, string2, and string3). There will be few instance methods to support that data. The class will be very modest. Once defined, we will use it to instantiate TripleString objects that can be used in our main() method and/or the global-scope methods that main() invokes to simulate this casino project.
  25. The Global-Scope Client Methods
  26. Each global-scope method that you have to write to simulate this casino app plays a special role. For example, there will be one method that gets the bet from the user and returns it to main():
  27. int getBet()
  28. Another method will simulate a random pull of the slot machine — it generates three random strings and returns them as a TripleString object to main():
  29. TripleString pull()
  30. An output method will be used at the end of each loop-pass when the user needs to see the results of her pull, and receive the news about how much she won (or not):
  31. void display (TripleString thePull, int winnings )
  32. We will describe each method — and a few others — in the next section.
  33. The Program Spec
  34. Class TripleString Spec
  35. The first step in writing this program is to create a simple, working class TripleString.
  36. The Data
  37. It will contain three private member strings as its main data: string1, string2, and string3. We will also add a public static member which is to be a const int MAX_LEN set to 20. This represents the maximum length that our class will allow any of its strings to be set to. We can use MAX_LEN in the TripleString method whose job it is to test for valid strings (see below).
  38. In summary, three private instances strings and one public static MAX_LEN. That’s all the data for this class.
  39. Default Constructor
  40. TripleString() — a default constructor that initializes all members to “”. We do not need any parameter-taking constructors.
  41. A Private Helper Method
  42. bool validString( string str ) — a helper function that the mutators can use to determine whether a string is legal. This method returns true if its length <= MAX_LEN and false, otherwise.
  43. Mutators/Accessor
  44. set()s and get()s for these members.
  45. Where it All Goes
  46. There are now a variety of program elements, so let’s review the order in which things appear in your .cpp file:
  47. 1.includes and namespace
  48. 2.class prototype(s)
  49. 3.global-scope method prototype(s)
  50. 4.main() definition
  51. 5.global-scope method definition( )
  52. 6.class method definition(s)
  53. After writing this class, test it using a simple main() which instantiates an object, mutates the members, displays the object, etc. Don’t turn this test in. It’s part of your development cycle.
  54. The Global Scope Method Specs
  55. int getBet()
  56. Download: http://solutionzip.com/downloads/slot-machine-simulation/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement