Question 4:
(30 marks)
This problem contains loops, sorting arrays, random generation, and variable matching.
Include an analysis (data requirements) and algorithm in your reply.
Write a “lottery engine” program to simulate drawing lottery numbers. You will draw 7 numbers,
randomly selected from 1 to 16.
a) Allow the user to enter their own selection of numbers first,
Example numbers: 2 3 7 9 10 11 15
b) then run your “lottery engine” to select the “winning numbers”. Numbers are drawn
randomly.
Use the clock as the seed value for your random function (Hint: use “srand(clock());” ).
c) Be sure to remove duplicate entries.
d) Print out the draw result as it was generated (unsorted), then sort the array and print out the
sorted numbers.
Example output:
“
Draw unsorted: 2 12 16 14 7 13 1
Draw sorted: 1 2 7 12 13 14 16
“
e) Then print out the matching numbers selected by the user:
f) Also print the sorted user selection and draw results and matching numbers to a TXT file
called “Results.txt”.
Example output
“
Draw sorted: 1 2 7 12 13 14 16
User’s sorted: 2 3 7 9 10 11 15
Matching numbers: 2 – 7
END