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

Imagine you have been asked by a first grade teacher to create a hangman game fo

ID: 644956 • Letter: I

Question

Imagine you have been asked by a first grade teacher to create a hangman game for her students to help them with spelling and word recognition. The teacher has given you a list of words that she would like the students to practice spelling. The list of words is stored in a data file named "words.dat". It is available for download from the course web page. On ranger, you may also co this data file into your account with the command cp ~cen/data/words dat words dat After your program reads in the list of words, it randomly picks one word to play the game. This word is referred to as the "gameWord'' In the game of hangman, as a user, you are first presented with a list of blanks representing unknown letters uess a letter to see if that letter exists in the word. If it do the blank that corresponds to the guessed letter is then displayed along with blanks for the letters that have not bee guessed yet. If you guess a previously guessed letter, you get to try again. If you guess wron ould incrementally move toward being hung. You have 8 bad guesses until you lose the game. To represent the different states of being hung", we will use the values PLATFORM, HEAD, BODY, LEFT ARM, RIGHT ARM, LEFT LEG, RIGHT LEG, and HUNG. To implement the game you should use the unsorted List ADT to represent the word (gameWord being uessed. Each element in the list should be a struct that stores the letter of the word and a Boolean that indicates if the letter is to be displayed or if a blank should be displayed. You should use a second list guesses) to represent the letters that have already been guessed and an enumeration to represent the states of the game. Your program should keep asking the user for another guess until either the entire word has een guessed or the state of the game is HUNG. After each guess the program should display the current tate of the word to be guessed, the list of characters already guessed, and the state of the game from the word bank to play the next game. Top down design of the client program in Pseudo code: 0. Main function Open data file Read in the list of words in the data file Close data file For as long as the player wants to play the game Randomly select a word from the list of words Call Play Game to play hangman with the selected word Function PlayGame input ame Word' Output: none While (the player has not lost or win), do the followin Call GetGuess to get the player's gues Check if the player has entered a duplicate gues i.e., whether the user guess is in the list guesses

Explanation / Answer

Program for Hangman:

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
  int newlife=0;
char letter;
bool yes;
char solution[100]={0};
char newW[100]={0};

cout<<"Write a word: ";

cin>>solution;
cout<<"you have six lives to guess the word";

while ( newlife <6 && strcmp(newW, solution) != 0)
{
   yes=0;
   cout<<endl<<"Guess a letter: ";
   cin>>letter;   
   for(int n=0; n<100; n++) {
   if(solution[n] == letter) {
   newW[n]=solution[n];
   yes=1;
   cout<<"nice!"<<"This is what you got so far:" <<endl<<newW;}
   }
   if (yes<=0){ //This part seems to be working now...
   cout<<"Sorry please try again."<<endl;
   newlife=(newlife+1);
   cout << "you lost this many lifes: "<<newlife<<endl;
   cout<<"This is what you got so far: "<<endl<<newW;
   }

if (newlife==1) {
   cout<<endl<<"Head";}
if (newlife==2) {
cout<<endl<<"Head-Body"; }
   if (newlife==3) {
cout<<endl<<"Head-Body-RightArm"; }
   if (newlife==4) {
cout<<endl<<"Head-Body-RightArm-LeftArm"; }
   if (newlife==5) {
cout<<endl<<"Head-Body-RightArm-LeftArm-RightLeg"; }
   if (newlife==6) {
       cout<<endl<<"Head-Body-RightArm-LeftArm-RightLeg-LeftLeg";
       cout<<endl<<"Sorry you lost! HANGMAN!!"<<endl<<endl;

   }}
system("pause");
getch();
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