Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

According to the following C++ code from Visual Studio, rewrite it with the other requests in the image. // // Guessing_Game.cpp // CMPS367_Project1_FirstName_LastName // //

According to the following C++ code from Visual Studio, rewrite it with the other requests in the image.

// // Guessing_Game.cpp // CMPS367_Project1_FirstName_LastName // // Created by Author's Name on 02/28/18. // Copyright ? 2018 University of La Verne. All rights reserved. // #include "stdafx.h" #include #include #include//library includes the definition of rand funcion (a random number generator) and the exit function #include//library includes the the definition of time funcion. void introduction(); /* function 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: -------------------------------- //error codes /ormal paramter range */ int getNumberOfGame(); /* function 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. */ int compareTwoCharacters(char, char); /* function compareTwoCharacters which receives two parameters of type character (e.g. the character to be guessed in that game and the character typed by the user). This functions return 0 if the two characters are the same, returns 2 if the first parameter comes after the second parameter, otherwise it returns -2. */ bool playOneGame(char); /* function playOneGame, which 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. This function will handle all tasks to play one game (ask the user to enter their guess, provide up to 5 chances to guess, provide a hint to the user, etc.). This function is going to call the third function (i.e. compareTwoCharacters) to decide if the user has guessed the correct answer or to provide a hint to the user. */ using namespace std; const int NUMBER_OF_GUESSES = 5; int main() { int numberOfGames = 0; char usersGuess, secretLetter; bool winFlag = false; introduction(); //ifstream inputFile; //Uncomment for option two read the value from the file /* //Uncomment for option two read the value from the file inputFile.open("Secret_Letters.txt"); //Uncomment for option two read the value from the file if (inputFile.fail()) //Uncomment for option two read the value from the file cout>secretLetter; //Uncomment for option two read the value from the file //cout4) { cout > numberOfGames; } return numberOfGames; } int compareTwoCharacters(char secret, char guess) { if (secret == guess) { return 0; } else if (secret>guess) { return 2; } else { return -2; } } bool playOneGame(char secret) { int loopCounter=0; char usersGuess; int resultOfComarison; while (loopCounter> usersGuess; resultOfComarison=compareTwoCharacters(secret, usersGuess); if (resultOfComarison == 0) { return true; } else if (resultOfComarison==-2) { cout  

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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 o o o The function prototype appears in the class definition Comment describing what the function does appears directly under function prototype Formal variable names are not used in any prototype 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 return:s 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 function's 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 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 o o o The function prototype appears in the class definition Comment describing what the function does appears directly under function prototype Formal variable names are not used in any prototype 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 return:s 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 function's 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

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

Step: 3

blur-text-image

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago