Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education