Question: I need to implement a CLASS or CLASSES in this C++ code, or transform the whole code with the use of classes. #include #include #include

I need to implement a CLASS or CLASSES in this C++ code, or transform the whole code with the use of classes.

#include #include #include #include

using namespace std;

const int MAX_TRIES=5; int letterFill (char, string, string&);

int main (){ string name; char letter; int num_of_wrong_guesses=0; string word; string words[] ={ "india", "japan", "nepal", "china", "madagascar", "azerbaijan", "kyrgyzstan", "turkmenistan", "french guiana", "caledonia" };

//choose and copy a word from array of words randomly int n=rand()% 10; word=words[n]; // Initialize the secret word with the * character. string unknown(word.length(),'*'); // welcome the user cout > letter; // Fill secret word with letter if the guess is correct, // otherwise increment the number of wrong guesses. if (letterFill(letter, word, unknown)==0){ cout

/* Take a one character guess and the secret word, and fill in the unfinished guessword. Returns number of characters matched. Also, returns zero if the character is already guessed. */ int letterFill (char guess, string secretword, string &guessword){ int i; int matches=0; int len=secretword.length(); for (i = 0; i

/* OUTPUT:

Welcome to hangman!! Guess a country that comes into your mind.

Each letter is represented by an asterisk.

You have to type only one letter in one try.

You have 5 tries to try and guess the country. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*****

Guess a letter: q

Whoops! That letter isn't in there! You have 4 guesses left.

*****

Guess a letter: w

Whoops! That letter isn't in there! You have 3 guesses left.

*****

Guess a letter: e

Whoops! That letter isn't in there! You have 2 guesses left.

*****

Guess a letter: r

Whoops! That letter isn't in there! You have 1 guesses left.

*****

Guess a letter: t

Whoops! That letter isn't in there! You have 0 guesses left.

Sorry, you lose...you've been hanged. The word was : japan */

I need to implement a CLASS or CLASSES in this C++ code,

or transform the whole code with the use of classes. #include #include

#include #include using namespace std; const int MAX_TRIES=5; int letterFill (char, string,

string&); int main (){ string name; char letter; int num_of_wrong_guesses=0; string word;

string words[] ={ "india", "japan", "nepal", "china", "madagascar", "azerbaijan", "kyrgyzstan", "turkmenistan", "french

include #include #include #include ctime> 2 4 using namespace std; 6 7 const int MAX_TRIES 5; 9int letterFill(char, string, string&) 10 11 Eint main) 12 13 14 15 16 17 18 19 20 string name; char letter int num of wrong guesses string word; india", "nepal", string words[] "japan "china" "madagascar", "azerbaijan", kyrgyzstan", turkmenistan", 23 french guiana", 25 26 27 "caledonia" //choose and copy a word from array of words randomly int n rand() % 10; word words [n]; // Initialize the secret word with the character. string unknown (word.length), *'); // welcome the user cout letter; : I Fill secret word with letter if the guess is correct, // otherwise increment the number of wrong guesses. if (letterFill(letter, word, unknown)) :cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!