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
  • 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...

  • 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...

  • 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)....

  • For your Project, you will develop a simple battleship game. Battleship is a guessing game for...

    For your Project, you will develop a simple battleship game. Battleship is a guessing game for two players. It is played on four grids. Two grids (one for each player) are used to mark each players' fleets of ships (including battleships). The locations of the fleet (these first two grids) are concealed from the other player so that they do not know the locations of the opponent’s ships. Players alternate turns by ‘firing torpedoes’ at the other player's ships. The...

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

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
ADVERTISEMENT