Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design ann ADT for a one-person guessing game that chooses n random integers in the range from 1 to m and asks the user to

Design ann ADT for a one-person guessing game that chooses n random integers in the range from 1 to m and asks the user to guess them. The same integer might be chosen more than once. For example, the game might chose the following four integers that range from 1 to 10: 4, 6, 1, 6.

The following interaction could occur between the user and the game, after the user has specified the integers m and n:

Enter your guesses for the 4 integers in the range from 1 to 10 that have been selected:

1 2 3 4

2 of your guesses are correct. Guess again.

Enter your guesses for the 4 integers in the range from 1 to 10 that have been selected:

2 4 6 8

2 of your guesses are correct. Guess again.

1 4 6 6

You are correct! Play again? No

Good-bye!

Algorithm:

Remember that you define an ADT as a class.

Guess.h

private:

randomVector (will contain n random numbers)

foundVector (create it with n numbers = 0 for not found)

public:

startGuess member function

createRandomNumber member function

Possibly some other functions

Guess.cpp

Public Member function definitions

main.cpp

Calls the startGuess

First ask the user for the n (number of random numbers) and m (range from 1 to m)

Populate the randomVector with "n" .push_backs and filling each with a random number in the range of 1 to m. Remember a vector is dynamic, so this is better than an array in this case.

Read in a guess or set of guesses (with cin)

Now you have to compare the guess to each item (with a for loop) against the randomVector . If found, add one to the found vector (that started at zero) then break out of that loop. After breaking out of the loop, or going through all of the Random vectors, go through the Found vector and count the number correct.

Let's say that you guess 3 times before the game ends, unless you get it right on try one or two.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions