Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need a UML diagram not the code If possible can you do it with this code // program to fill a vector with random numbers

Need a UML diagram not the code image text in transcribed
If possible can you do it with this code
// program to fill a vector with random numbers and guess them
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int i, j;
int r;
bool playagain, guessagain;
string option;
int m, n, count;
int temp;
// seed the random generator
srand(time(0));
playagain = true;
while (playagain)
{
// take the value of m and n from user:
cout
cin >> m;
cout
cin >> n;
// create a vector of size m
vector arr;
vector userinput(n, -1);
// generate random numbers and fill the vector
for (i = 0; i
{
r = rand() % m + 1;
arr.push_back(r);
}
// ask the user to guess the n random numbers
guessagain = true;
while (guessagain)
{
cout
for (i = 0; i
{
cin >> temp;
userinput[i] = temp;
}
// check if the guesses are correct
count = 0;
vector indexmatched;
bool seen = false;
for (i = 0; i
{
// uncomment below line to see the number generated within the program.
// cout
for (j = 0; j
{
if (userinput[i] == arr[j])
{
// check if index position j was not already seen
for (int k = 0; k
{
if (indexmatched[k] == j)
{
// already seen
seen = true;
}
}
if (seen == false)
{
count++;
indexmatched.push_back(j);
}
}
}
}
if (count
{
cout
}
else
{
cout
guessagain = false;
}
}
cin.ignore();
getline(cin, option);
if (option == "No")
{
playagain = false;
cout
}
cout
}
return 0;
}
(Gaming) Using UML, to design an 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 choose 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: 1234 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: 2468 2 of your guesses are correct. Guess again. 1466 You are correct! Play again? No Good-bye

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_2

Step: 3

blur-text-image_3

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

explain the concept of strategy formulation

Answered: 1 week ago