The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Write an application that simulates a simple guessing game similar to playing Lotto. The user guesses
six unique numbers between 1 and 39. The program (Lotto machine) also generates six unique random
numbers in the same range. The program compares the user’s guess to the set of random numbers
generated and displays a score. The score says how many of the user’s numbers matches that of the
program.
The random numbers are generated and the score of the game is calculated by the class
GuessingGame as shown below:
The data member num stores the number (e.g. 6) of random numbers to be generated for the game,
fromNum (e.g. 1) stores the starting number and toNum (e.g. 39) stores the ending number.
generateNumbers() can generate and return unique or non-unique random numbers. The getters
simply return the relevant values stored in the data members. score() returns the number of numbers
correctly guessed by the user.
Use the qrand() and qsrand() functions in Qt to generate random numbers.
Implement the main() function so that the user can enter six numbers in the range 1 - 39 in one
QInputDialog (using an appropriate separator, which should be indicated in the QInputDialog).
These numbers should then be compared to the six numbers generated by GuessingGame. Display the
score to the user using a QMessageBox. Give the user a choice to play the game again before quitting
the application.
The input entered by the user should be validated so that only six unique numbers in the range 1 – 39
are accepted.
Attachments:
-----------