Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed count of numbers to be played with each number selected being within a given range.  For example, when the range of numbers is 1 through 100, and 5 numbers are to be played, the lottery ticket will be composed of 5 unique values between 1 and 100.  The values are selected at random. The main function is responsible for obtaining the upper range of the numbers and the count of numbers to be played from the end user.  The count of numbers must be less than the upper range.  The main function will call the generateLotto function to generate the lottery ticket and then call the displayTicket function to display the resulting lottery ticket.  Any number of lottery tickets may be generated. The generateLotto function should accept two parameters. The first should be the upper range for the numbers while the second parameter represents a count of the numbers to be played. For example, lotto(51, 6) will select 6 numbers at random between 1 and 51 (inclusive.) The function should return a vector of unique integer values in sorted order.   The displayTicket function accepts a vector of integers and displays the vector. Hints: Although the standard library defines a rand() function for generating random numbers, the function may produce duplicate numbers and hence, is not suitable for this application. To ensure that unique values are generated, create a vector that contains all possible values (1 through the given upper range) and then shuffle these values using the random_shuffle() function.  This will result in a vector of numbers between 1 and the upper range in random order.  From this vector, select the required number of values from the beginning of the vector, adding these values to the result vector.  Lastly, use the sort() function to sort the result vector. The random_shuffle() and sort() functions require two parameters that specify the beginning and ending elements on which to operate.  To specify the beginning and ending of the vector, the begin() and end() methods of the vector class can be used.  For example, when the vector allNumbers contains all the values between 1 and 51, the values within the vector can be rearranged (shuffled) using:      random_shuffle(allNumbers.begin(),allNumbers.end()); I HAVE ATTACHED AND EXAMPLE DISPLAY!

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter5: Making Decisions
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed count of numbers to be played with each number selected being within a given range.  For example, when the range of numbers is 1 through 100, and 5 numbers are to be played, the lottery ticket will be composed of 5 unique values between 1 and 100.  The values are selected at random.

The main function is responsible for obtaining the upper range of the numbers and the count of numbers to be played from the end user.  The count of numbers must be less than the upper range.  The main function will call the generateLotto function to generate the lottery ticket and then call the displayTicket function to display the resulting lottery ticket.  Any number of lottery tickets may be generated.

The generateLotto function should accept two parameters. The first should be the upper range for the numbers while the second parameter represents a count of the numbers to be played. For example, lotto(51, 6) will select 6 numbers at random between 1 and 51 (inclusive.) The function should return a vector of unique integer values in sorted order.  

The displayTicket function accepts a vector of integers and displays the vector.

Hints: Although the standard library defines a rand() function for generating random numbers, the function may produce duplicate numbers and hence, is not suitable for this application. To ensure that unique values are generated, create a vector that contains all possible values (1 through the given upper range) and then shuffle these values using the random_shuffle() function.  This will result in a vector of numbers between 1 and the upper range in random order.  From this vector, select the required number of values from the beginning of the vector, adding these values to the result vector.  Lastly, use the sort() function to sort the result vector.

The random_shuffle() and sort() functions require two parameters that specify the beginning and ending elements on which to operate.  To specify the beginning and ending of the vector, the begin() and end() methods of the vector class can be used.  For example, when the vector allNumbers contains all the values between 1 and 51, the values within the vector can be rearranged (shuffled) using:

     random_shuffle(allNumbers.begin(),allNumbers.end());

I HAVE ATTACHED AND EXAMPLE DISPLAY!

Enter the highest number: 51
How many numbers should be generated? 6
Your randomly generated ticket: 1 2 10 13 28 50
Do you want to generate another ticket? (Y or N): y
Enter the highest number: 51
How many numbers should be generated? 6
Your randomly generated ticket: 2 24 30 35 37 39
Do you want to generate another ticket? (Y or N) : y
Enter the highest number: 21
How many numbers should be generated? 4
Your randomly generated ticket: 6 10 11 14
Do you want to generate another ticket? (Y or N): n
Transcribed Image Text:Enter the highest number: 51 How many numbers should be generated? 6 Your randomly generated ticket: 1 2 10 13 28 50 Do you want to generate another ticket? (Y or N): y Enter the highest number: 51 How many numbers should be generated? 6 Your randomly generated ticket: 2 24 30 35 37 39 Do you want to generate another ticket? (Y or N) : y Enter the highest number: 21 How many numbers should be generated? 4 Your randomly generated ticket: 6 10 11 14 Do you want to generate another ticket? (Y or N): n
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L