Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ language write. Please double check outputs sample and conditions. 100% p

ID: 3751166 • Letter: I

Question

In c++ language write. Please double check outputs sample and conditions. 100% perfection. Use linux terminal and not visual studio headers etc.

Description For the assignment, you will implement a class that runs a classic word guessing game. You will need to implement the following class class wordGuess public: static const int MAX_SIZE - 20; wordGuess(); wordGuess (string); bool makeGuess (char); char game0ver O const string getPuzzle () const; private: string theWord; bool correct [MAX_SIZE]; int attempts; int maxAttempts; Description of Members Each member will perform/contain the following string theWord - contains the word that is to be guessed static const int MAX_SIZE20 - the maximum size of the word bool correct [MAX_SIZE] - boolean array that marks which letters have been guessed or not int attempts - keeps track of the number of attempts the user made int ma:Attempts-contains the maximum number of attempts the user has wordGuess () default constructor, sets default values to all the members of the class (zeros for numbers, empty strings, false, etc.) however if one of the characters in the string is a space, you set that element in the boolean array to a true wordGuess (string) - constructor that takes in a string which will be the word to be guessed, sets everything else to defaults and maxAttempts will be size of the word multiplied by 2

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;

class wordGuess

{

public:

static const int MAX_SIZE=20;

wordGuess()

{

this->attempts=0;

this->theWord="Vishal Singh";

this->maxAttempts=this->theWord.length()*2;

}

wordGuess(string word)

{

this->theWord=word;

this->attempts=0;

this->maxAttempts=this->theWord.length()*2;

for(int i=0; i<this->theWord.length();i++)

{

if(this->theWord.at(i)==' ')

this->correct[i]=true;

else

this->correct[i]=false;

}

}

bool makeGuess(char c)

{

if(this->attempts<this->maxAttempts)

{

for(int i=0; i<this->theWord.length();i++)

{

if(this->theWord.at(i)==c)

this->correct[i]=true;

}

this->attempts++;

return true;

}

else

return false;

}

char gameOver()const

{

for(int i=0; i<this->theWord.length();i++)

{

if(this->correct[i]==false)

return 'C';

}

return 'W';

}

string getPuzzle()const

{

string str="";

for(int i=0; i<this->theWord.length();i++)

{

if(this->correct[i]==true)

str=str+" "+this->theWord.at(i)+" ";

else

str=str+" _ ";

}

return str;

}

private:

string theWord;

bool correct [MAX_SIZE];

int attempts;

int maxAttempts;

};

int main()

{

char c;

wordGuess W=wordGuess("Hello World");

cout<<W.getPuzzle()<<endl;

cout<<"Enter a letter : ";

cin>>c;

while(W.makeGuess(c))

{

cout<<W.getPuzzle()<<endl;

cout<<"Enter a letter : ";

cin>>c;

}

if(W.gameOver()=='W')

cout<<"You won"<<endl;

else

cout<<"You loose"<<endl;

return 0;

}

NEW CODE:

#include<iostream>

#include<string>

#include <ctype.h>

using namespace std;

class wordGuess

{

public:

static const int MAX_SIZE=20;

wordGuess()

{

this->attempts=0;

this->theWord="Vishal Singh";

this->maxAttempts=this->theWord.length()*2;

}

wordGuess(string word)

{

this->theWord=word;

this->attempts=0;

this->maxAttempts=this->theWord.length()*2;

for(int i=0; i<this->theWord.length();i++)

{

if(this->theWord.at(i)==' ')

this->correct[i

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote