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

Write a code using C++, make sure it complies after you program it with NO warni

ID: 3627187 • Letter: W

Question

Write a code using C++, make sure it complies after you program it with NO warnings . I'd really appreciate it! Thanks! The extra credit if you know show me how, if not that's fine to! Again,thanks!

This assignment is to give you practice using Enums, String variables and the functions of the string class, as well as more practice writing your own functions. In order to get full credit for the program you must use these topics.

You are to write a program that will play a word game similar to the game "Hangman". The computer will read a word from a file and tell the user how many letters it contains. The user must then guess letters in the word until they guess the entire word or have guessed incorrectly seven times. For each turn, the user chooses a letter; the program determines whether there are any occurrences of that letter in the word and, if so, replaces ALL occurrences of the letter, showing the word with the correctly guessed letters (with *’s in the places of the unguessed letters). If there are no occurrences of the letter in the word, the user is penalized an incorrect guess. The user is asked whether they want to guess the whole word. If they guess the word correctly, they have won that game. If not, play continues if they have not used up the seven incorrect guesses. When the word play is over, the program should print a message with the word, whether the player won or lost, how many guesses were made and of those, how many were incorrect. These word plays continue until the end of the file is reached, at which time a message showing how many games the user won and lost is printed.

The data file is mp4wordguess.txt. Copy this file to the folder containing your project. It contains one word on each line.

You are REQUIRED to use functions, enums, string variables and string functions in the solution to this problem. Define an enum for the Status of the game (with the values CONTINUE, WON and LOST) and have the loop that plays a word game as long as the game state is CONTINUE.

For simplicity, you may assume all words contain upper-case letters and the user enters upper-case responses at all times.

A sample output of the game for a game starting with the word HANGMAN is shown on the next page.

Extra credit:
You may add a graphic similar to the one below where one part of the figure is added each time the user makes a wrong guess. Remember to get the basic assignment working correctly before trying this. No extra credit on late programs.


_________
| |
O |
/| |
| |
/ |
|
-----


Word guessing game by (your name)
Starting a new game
The word has 7 characters.
The word is now *******
Enter a letter: A
The word is now *A***A*
Do you want to guess the word? 'Y' or 'N' N
Enter a letter: H
The word is now HA***A*
Do you want to guess the word? 'Y' or 'N' N
Enter a letter: P
Sorry, no occurrences of P
Do you want to guess the word? 'Y' or 'N' N
Enter a letter: N
The word is now HAN**AN
Do you want to guess the word? 'Y' or 'N' Y
Enter your guess: HANDMAN
Sorry, that is not the word
Enter a letter: T
Sorry, no occurrences of T
Do you want to guess the word? 'Y' or 'N' N
Enter a letter: M
The word is now HAN*MAN
Do you want to guess the word? 'Y' or 'N' N
Enter a letter: E
Sorry, no occurrences of E
Do you want to guess the word? 'Y' or 'N' Y
Enter your guess: HANGMAN
The word is HANGMAN.
Congratulations, you won! You guessed 8 letters, of which 4 were wrong.


The word has 5 characters.
The word is now *****
Enter a letter: A
.
.
etc.
.
.
The word is now SUP*R*I**I*S
Sorry, no occurrences of Q
Do you want to guess the word? 'Y' or 'N' Y
Enter your guess: SUPERCILIOUS
The word is SUPERSILLIES.
Sorry, you lost! You guessed 13 letters, of which 7 were wrong.
No more words!
You won 3 games and lost 549.

Explanation / Answer

please rate - thanks

#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;
#define MAX_GUESSES 7
enum done{CONTINUE, WON ,LOST};
done getGuess(string);
int good_guess(string,char);
void printword(string);
char getletter();
void draw(int);
int main()
{
int i,guesses=0,gwon=0,glost=0,bad;
string Word;
string word_so_far;
char guess;
bool guessed=false;
done won;
ifstream input;
   input.open("mp4wordguess.txt");           //open file
   if(input.fail())             //is it ok?
       { cout<<"word file did not open please check it ";
        system("pause");
        return 1;
        }
       cout<<"Word guessing game by (your name) ";
input>>Word;      
while(input)
{cout<<"Starting a new game My word has "<<Word.length()<<" characters. ";

guesses=0;
bad=0;
won=CONTINUE;
guessed=false;
word_so_far="";
word_so_far.insert(0,Word.length(),'*');
cout<<"User word is ";      
printword(word_so_far);
while(won==CONTINUE)
    {guesses++;
    guess=getletter();
     if(good_guess(Word,guess)==1)
         {i=0;
         i=Word.find(guess,i);
         while(i<string::npos)
            {word_so_far[i]=guess;
              i=Word.find(guess,i+1);
              }
           cout<<"The word is now ";
          printword(word_so_far);
        }
     else
         {bad++;
        draw(bad);
        }
     won=getGuess(Word);
     if(guesses==MAX_GUESSES)
           won=LOST;
    
     }

if(won==WON)
    { cout<<"Congratulations YOU WON!! :) :)";
    gwon++;
   }
else
    {cout<<"sorry :( :( The word was "<<Word;  
    glost++;
    }
cout<<" You guessed "<<guesses<<" letters, of which "<<bad<<" were wrong. ";
input>>Word;
}
cout<<" No more words You won "<<gwon<<" games and lost "<<glost<<". ";
system("pause");
}
void draw(int i)
{int j,m;
cout<<"________ | | ";
if(i>=1)
    cout<<" o | ";
if(i>=2)
    cout<<"/";
if(i>=3)
    cout<<"|";
if(i>=4)
    cout<<"\";
m=i;
if(i>4)
   m=4;
   for(j=4;j>m;j--)
        cout<<" ";
    cout<<"| ";

if(i>=5)
     cout<<" | | ";
else
     cout<<"   | ";
if(i>=6)
     cout<<"/";
if(i>=7)
     cout<<" \";
if(i==6)
   m=3;
else if(i==7)
   m=1;
else
   m=4;
for(j=1;j<m;j++)
        cout<<" ";
    cout<<"| ";
cout<<"   | --------- ";
  
}


done getGuess(string w)
{cout<<"Do you want to guess the word? 'Y' or 'N' ";
char yorn;
string guess;
cin>>yorn;
if(yorn!='Y')
     return CONTINUE;
cout<<"Enter your word now: ";

cin>>guess;
if(w.compare(guess)==0)
     return WON;
cout<<"Sorry, that is not the word ";
return CONTINUE;
}   

char getletter()
{char letter;
cout<<"Enter a letter: ";
cin>>letter;
return letter;
}
void printword(string w)
{int i;
cout<<w;
cout<<" ";
}
int good_guess(string w,char let)
{if(w.find(let,0)<string::npos)
      return 1;
cout<<"Sorry, no occurrences of "<<let<<endl;
return 0;
}

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