Question

Design and implement a class for a one person guessing game as described on page 30, Chapter 1, Programming Problem 7 of the textbook. CSCI 2421 HW1.jpg

Submit header file guess.h, implementation file guess.cpp, main function file main.cpp that asks initial seed number, and prints three sequential numbers generated by the program. You need to include a makefile, and Readme file

pseudocode version UF comments in your code. 6. Exercises 6, 7, and 8 ask you to specify methods for the ADT bag that retuml tie unOl l lon difrerence of two bags. Define each of these methods independently of the bags implementat (Gaming) Design an ADT for a one-person guessing game that chooses n random inte from I to m and asks the user to only ADT bag operations. in the r guess them. The same integer might be chosen more than on ple, 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 specif Ealrr incgers internge om Ito 10 that have been selected: integers m and n 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! Gaming) A system of caves is a group of interconnected underground tunnels. Two, and only tw can intersect to form a cave. Design an ADT cave and an AnT

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note that you can change the values of n and m and also the numbers to be guessed as required

Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

#include <bits/stdc++.h>
using namespace std;
int matchGuesses(vector <int>answers,vector <int>guess)
{
int res=0;
sort(answers.begin(),answers.end());
sort(guess.begin(),guess.end());
int i=0,j=0;
while(i<answers.size()&&j<guess.size())
{
if(answers[i]==guess[j]) //match found
{
res++;
i++;
j++;
}
else if(answers[i]<guess[j])
i++;
else
j++;
}
return res;
}
int main()
{
int n=4,m=10;
vector <int>answers={4,6,1,6};
int i,p;
vector <int>guess(n);
string input;
do
{
do
{
cout<<"Enter your "<<n<<" guesses in the range 1 to "<<m<<endl;
for(i=0;i<n;i++)
{
cin>>guess[i];
}
p=matchGuesses(answers,guess);
if(p==n)
{
cout<<"You are correct.Play Again? ";
cin>>input;
}
else
{
cout<<p<<" of your guesses are correct Guess again ";
}
}while(p!=n);
}while(input=="Yes");
return 0;
}

Below is the screenshot of output

CAUserslPrakher1Documentslcitest.exe your 4 guesses in the range 1 to 1e 1 2 3 4 2 of your guesses are correct Guess again E

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any.

Add a comment
Know the answer?
Add Answer to:
Design and implement a class for a one person guessing game as described on page 30,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Guessing Game Class The class will generate a random number of 1 to 15, and...

    Java Guessing Game Class The class will generate a random number of 1 to 15, and then check to see if the user guessed the number correctly. If the number is incorrect, the user should have the chance to guess again, until they guess the right number or they guess 10 times. The class method should keep track of the number of guesses the user has had, and return this value.   The class should have one constructors, a default and...

  • Task 4 (20 points) Implement a simple guessing game. Name your file task4.c. Your game will...

    Task 4 (20 points) Implement a simple guessing game. Name your file task4.c. Your game will use rand() to generate a random number from 1 to 10 then prompt user to guess that number. User will have unlimited number of tries to guess the correct number. Your program should work like this hb117@uxb4:$ gco -Wall task4 . c -o task4 hb117@uxb4:~$ ./guessing Guess a number from 1-10: 1 Guess again: 4 Guess again: 2 Guess again: 9 Guess again: 10...

  • Java 1) In a game of guessing numbers, one person says, “I’m thinking of a number...

    Java 1) In a game of guessing numbers, one person says, “I’m thinking of a number between 1 and 100.” The other person guesses “50.” The first person replies, “No, the number is less.” The second person then guesses “25,” and so on, until she guesses correctly. Write a program that plays this game. The computer knows the number (a random number between 1 and 100) and the user is the guesser. At the end of the game, the computer...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game...

    In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.   For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”. Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the...

  • Exercise 4-4      Create an object and use it with the Number Guessing Game In this exercise,...

    Exercise 4-4      Create an object and use it with the Number Guessing Game In this exercise, you’ll convert a number guessing game so it uses some object-oriented features. The class we create will have 3 private instancevariables, 2 constructors, 3 getmethodswhich return a value, and 1 methodthat acts as a sub procedure. The logic for creating a random number and tracking the # of guesses is moved to this new class. Review the project Start NetBeans and open the project...

  • Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent...

    Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent generates a secret letter for the user to guess. The user must be able to take turns guessing the secret letter, with the Al responding to the user's guesses. After successfully guessing, the user must be allowed to play again. The Al must count how many turns the user has taken. Here is an example of a game in progress where the human user...

  • Write a java program that simulates the operation of a Halloween Vampire Hunt game. In the...

    Write a java program that simulates the operation of a Halloween Vampire Hunt game. In the game scenario, you are a vampire hunting a victim in a dark cave. The cave consists of 10 by 10 little squares, numbered 0-9 on each side; your victim is in the cave, with x-coordinate and y-coordinate 0-9 (both integers). On each turn, you guess where your victim is, and try to bite her/him. Your “health” is determined by the number of bloodpoints you...

  • Need help with a number guessing game in java 1) You should store prior guessses in...

    Need help with a number guessing game in java 1) You should store prior guessses in a linked list, and the nodes in the list must follow the order of prior guesses. For example, if the prior guesses are 1000, 2111, 3222 in that order, the nodes must follow the same order 2) You should store the candidate numbers also in a linked list, and the nodes must follow the order of numbers (i.e. from the smallest to the largest)....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT