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
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
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.
Design and implement a class for a one person guessing game as described on page 30,...
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, 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) { 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 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 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 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 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 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...