3. Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed number of slots with each slot having a number selected within a given range. The main function is responsible for obtaining the number of slots as well as the range of numbers from the end user. Define a lotto function that accepts two parameters. The first should be the upper range for the available 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. Also create a display function which 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 (based on the given range), shuffles these values using the random_shuffle() function, and then retrieves the number of values needed from the beginning of the vector. The random_shuffle() function requires two parameters that specify the beginning and ending elements and will randomly rearrange the values within these elements. Use the .begin() and .end() methods to define this range. For example, when the vector allNumbers contains all the values between 1 and 51, the values can be rearranged (shuffled) using: random_shuffle(alINumbers.begin(),alINumbers.end()); The sort() function can be used to order the values stored in the result vector. The sort() function requires two parameters that specify the range, using the same syntax as the random_shuffle() function. Both random_shuffle() and sort() are defined in the library. Please see http://www.cplusplus.com/reference/algorithm/¤ to learn more about the random_shuffle and sort algorithms. Еxample run: 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 tícket? (Y or N): n

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The program should be in C++. Please use easy logic for a beginner with a proper indentations and comments

3. Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed number of slots
with each slot having a number selected within a given range. The main function is responsible for obtaining the number
of slots as well as the range of numbers from the end user. Define a lotto function that accepts two parameters. The first
should be the upper range for the available 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. Also create a display function which 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 (based on the given range), shuffles these values using the random_shuffle()
function, and then retrieves the number of values needed from the beginning of the vector. The random_shuffle()
function requires two parameters that specify the beginning and ending elements and will randomly rearrange the values
within these elements. Use the .begin() and .end() methods to define this range. For example, when the vector
allNumbers contains all the values between 1 and 51, the values can be rearranged (shuffled) using:
random_shuffle(alINumbers.begin(),alINumbers.end());
The sort() function can be used to order the values stored in the result vector. The sort() function requires two
parameters that specify the range, using the same syntax as the random_shuffle() function. Both random_shuffle() and
sort() are defined in the <algorithm> library. Please see http://www.cplusplus.com/reference/algorithm/¤ to learn more
about the random_shuffle and sort algorithms.
Еxample run:
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 tícket? (Y or N): n
Transcribed Image Text:3. Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed number of slots with each slot having a number selected within a given range. The main function is responsible for obtaining the number of slots as well as the range of numbers from the end user. Define a lotto function that accepts two parameters. The first should be the upper range for the available 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. Also create a display function which 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 (based on the given range), shuffles these values using the random_shuffle() function, and then retrieves the number of values needed from the beginning of the vector. The random_shuffle() function requires two parameters that specify the beginning and ending elements and will randomly rearrange the values within these elements. Use the .begin() and .end() methods to define this range. For example, when the vector allNumbers contains all the values between 1 and 51, the values can be rearranged (shuffled) using: random_shuffle(alINumbers.begin(),alINumbers.end()); The sort() function can be used to order the values stored in the result vector. The sort() function requires two parameters that specify the range, using the same syntax as the random_shuffle() function. Both random_shuffle() and sort() are defined in the <algorithm> library. Please see http://www.cplusplus.com/reference/algorithm/¤ to learn more about the random_shuffle and sort algorithms. Еxample run: 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 tícket? (Y or N): n
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education