Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Language: Swift 4.0.3 Lottery Quick Picks Quick Picks refers to the use of a computer to randomly generate playing numbers when purchasing a lottery
Programming Language: Swift 4.0.3
Lottery Quick Picks Quick Picks" refers to the use of a computer to randomly generate playing numbers when purchasing a lottery ticket. Because different lotteries use different range of numbers and different number of picks, the quick pick program has to be configurable. For example, one lottery may call for users to pick 6 numbers from a range of 1 to 36, while another lottery may require its users to pick 5 numbers from a range of 1 to 58. Assume that no lottery allows players to pick repeated values. Your task is to develop a class to generate quick pick numbers given a range and a number of required picks. Your class must have 2 public members and 2 public methods. The public members will be range, an Int representing the range of value from which numbers will be drawn (36 and 58 in the two examples above) and pumPisks, an lot representing the number of picks from the range (6 and 5 in the two examples above. One of the two public functions will be generatePicks, which accepts no parameters and returns an array of 10 containing the quick pick values. To use your class, a user will first set the values of range and numPicks, then calgeneratePicks0. Your class must also calculate the odds of winning for given values of range and numPicks, This will be returned by a call to the second public funiongetinningOddsO. which accepts no parameters and returns a Double. The odds of winning is calculated as 1 in Range! numPicks! (range-numPicks)! All other class members or methods you create should be private. Note that the I's in the above expression denote factorials, not forced unwrapping. and save it all by itself in a swift file with the same name. Instantiate Name vour class your class and use it in a program that prompts the user for a range and number of picks required. The program should then generate an appropriate set of values for the user as well as inform the user of her chances of winning (more like her chances of not losing!). Hints: 1) create a private method in your class to calculate factorials. Using double precision numbers in this method will allow your code to easily handle a range of 100. 2) Recall that mathematically, n! = n * (n-1) * (n.2) . all the way down to 1. So, for example, 5! 5*4*3*2* 1-120. By observation, n! = n * (n.IL Your factorial function will be a good opportunity to practice your recursion (though using recursion is not a requirement) 3) Take the time to get this code right. We will be re-using it to make a graphical quick-pick app. 4) This assignment can be completed using a struct rather than a class. This is acceptableStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started