Answered step by step
Verified Expert Solution
Question
1 Approved Answer
swift 4 comments seperate model,view,controller show compile screen Lottery Quick Picks Quick Picks refers to the use of a computer to randomly generate playing numbers
swift 4
comments
seperate model,view,controller
show compile screen
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 drawrn (36 and 58 in the two examples above) and numPicks, an Int 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 Ints containing the quick pick values. To use your class, a user will first set the values of range and numPicks, then call generatePicks(). 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 function getWinningOdds(), which accepts no parameters and returns a Double. The odds of winning is calculated as 1 in range! numPicks! (range-numP icks)! 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 Name vour class QuickPick and save it all by itself in a swift file with the same name. Instantiate 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-1)!. 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 can be completed using a struct rather than a class. This is acceptable. 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 drawrn (36 and 58 in the two examples above) and numPicks, an Int 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 Ints containing the quick pick values. To use your class, a user will first set the values of range and numPicks, then call generatePicks(). 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 function getWinningOdds(), which accepts no parameters and returns a Double. The odds of winning is calculated as 1 in range! numPicks! (range-numP icks)! 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 Name vour class QuickPick and save it all by itself in a swift file with the same name. Instantiate 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-1)!. 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 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