Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will transform the program that was written to play a letter guessing game (Project 2) to an object-oriented program. General Requirements for project 3

You will transform the program that was written to play a letter guessing game (Project 2) to an object-oriented program. General Requirements for project 3 Rewrite the program from project 2 using at least one class Game, which has three member functions. All member functions will be defined as follows: o The function prototype appears in the class definition o Comment describing what the function does appears directly under function prototype o Formal variable names are not used in any prototype o The functions definition appears after the main The first member function is a custom constructor (to set the member variables), which receives two parameters: the first parameter is a character (the character to be guessed in that game); and the second parameter is an integer that specifies the maximum number of attempts that can be made in the game. (the number of attempts ranges between 4 and 7 -inclusive-, this number is randomly generated in the main function using the rand function, you have to seed the random number generator). The second member function is compareTwoCharacters, which receives one parameter of type character (the character typed by the user). This functions compares the character that was passed to the character that was defined initially in the custom constructor (i.e., member variable). The function returns 0 if the two characters are the same, returns 2 if the member variable comes after the passed parameter, otherwise it returns -2. The third member function is playGame, which receives no parameters. This function returns true if the user won; otherwise will return false. This function will handle all tasks to play one game (ask the user to enter their guess, provide guessing chances -equal to the member variable that that was defined initially in the custom constructor-, provide a hint to the user, etc.). This function is going to call the second member function (i.e. compareTwoCharacters) to decide if the user has guessed the correct answer or to provide a hint to the user. The user-defined functions introduction and getNumberOfGame that were defined in the second project will remain unchanged. (Using the same guidelines discussed in project 2) The first functions name is introduction, which will print (show on the screen) Welcome to the Letter Guessing Game You will enter the number of games you want to play (1 - 4 games) You have 5 chances to guess each letter Let's begin: -------------------------------- The second functions name is getNumberOfGame, which asks the user about the number of games to be played and returns the value. This function will validate the user input to make sure it is in the desired range (1-4) inclusive, if the value is out of range the user is notified and asked again. How many games do you want to play (1-4) 3 Make sure to follow the instructions carefully including using the exact function names with the exact letter cases (upper and lower case letters). Your programs are going to be tested using a unified main function that is developed for that purpose. If the unified main function does not compile this indicates inconsistencies in meeting the above requirements and will result in a zero grade. General Requirements from project 1 Write a program that assigns four letters (i.e. char) to four different variables. Your program will ask the user to enter the number of games they wish to play (1 to 4) Your program use one character at a time to play the game and repeat this for the number of games the user wants to play. Maximum number of guesses for each game is 5 Each time the users guess is wrong, you should provide him with a hint indicating whether the letter come before or after the letter he/she is trying to guess.(alphabetically) If the player has used up all of their guesses, a message that the game is over should be displayed along with the letter they were trying to guess. When the number of games has been played, the program will end Additional Requirements: Be sure to comment your code adequately. Be sure to indent properly. Check your textbook to see how it should be done. Use meaningful variable names Sample Output: Welcome to the Letter Guessing Game You will enter the number of games you want to play (1 - 4 games) You have 5 chances to guess each letter Let's begin: -------------------------------- How many games do you want to play (1-4) 3 ************************************ Let's play game 1 Enter a guess: e the letter you are trying to guess comes before e Enter a guess: c the letter you are trying to guess comes before c Enter a guess: a You guessed it!!! ************************************ Let's play game 2 Enter a guess: t the letter you are trying to guess comes before t Enter a guess: a the letter you are trying to guess comes after a Enter a guess: p the letter you are trying to guess comes before p Enter a guess: n the letter you are trying to guess comes before n Enter a guess: g the letter you are trying to guess comes after g You did not guess the letter. It was m ************************************ Let's play game 3 Enter a guess: g the letter you are trying to guess comes after g Enter a guess: m the letter you are trying to guess comes after m Enter a guess: t the letter you are trying to guess comes before t Enter a guess: r the letter you are trying to guess comes before r Enter a guess: s the letter you are trying to guess comes before s You did not guess the letter. It was n Press any key to continue . . .

(PROJECT 2 BELOW)

# include # include //for 'rand', 'srand' //# include //for 'system time' using namespace std; using namespace std;

// prototype of functuons

void welcome();

// this will ask user about number of games he want to play, no any params, return int value

int getNumberOfGame();

// this function compares two char params and return int value int compareTwoCharacters(char , char );

//receives one parameter of type character (the character to be guessed in that game). // This function returns true if the user won; otherwise will return false. bool playOneGame(char );

int main() { int no; char c[4] = {'a', 'b', 'c', 'd'}; welcome(); // taking user input for number of games no = getNumberOfGame(); for(int i=0;i // playing one game in each loop bool status = playOneGame(c[i]); if(status == true ){ // if guessed correctly cout<<" You guessed it!!! "; } else{ cout<<" You did not guess it!!! Try again "; } } return 0; }

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago