Create a simple commented C++ HANGMAN game using CLASSES using the following specifications:
- The game must keep track of the player misses
- It must ONLY use 10 three letter words
- It does NOT need a graphical implementation
/*main.cpp*/
#include "hangman.h"
using namespace std;
//
declaring constants
typedef char String[MAX_WORD_SIZE];
// including implementation of cpp file
//Driver function
int main()
{
const string fileName = "words.txt";
//Declaring object of Hangman class
Hangman obj;
char ch;
//Calling function to load words from file
obj.loadFile(fileName);
do
{
system("CLS");
cout<<"Hangman Game ";
//Function to start game
obj.runGame();
//Asking user for new game
cout<<"Do you want to play again (Y/N)? ";
cin>>ch;
}while(ch == 'Y' || ch =='y');
cout<<"Thanks for playing"<<endl;
return 0;
}
/*End of main.cpp*/
/*hangman.h*/
#ifndef HANGMAN_H
#define HANGMAN_H
#include<iostream>
#include<string>
#include<fstream>
#include <ctime>
#include <cstdlib>
#define MAX_WORD_SIZE 3
#define MAX_WORDS 10
using namespace std;
class
Hangman
{
private:
string words[MAX_WORDS];
int count;
public:
Hangman() : count(0) {}
void
loadFile(string fileName);
void runGame();
};
#endif
/*End of hangman.h*/
/*hangman.cpp*/
#include "hangman.h"
using namespace std;
//Function to read words from a file and store them into array of
words
void Hangman::loadFile(string fileName)
{
char ch;
// opening file in read mode
ifstream file(fileName);
while(file.bad())
{
cout<<"Error in opening file.
Enter new file name: ";
cin>>fileName;
file.open(fileName);
}
//Read MAX_WORDS words from the file
for(; count < MAX_WORDS; count++)
file>>words[count];
//Close file
file.close();
}
//Function to start the game
void Hangman::runGame()
{
// declaring varibales
int word;
int tries = 1;//To keep track of number of tries
string guess = "---";//Guess initially
string copy;
char letter;//User's guess
bool correct = false;
//Calling random function to get a random word
srand(time( NULL ));
word = rand() % count;//Get a word number
copy = words[word];//Make a copy of selected
word
//Main game block
while(tries != 6)
{
cout<<"Current guess:
"<<guess<<endl;
cout<<"Guess a letter:
";
cin>>letter;
letter = tolower(letter);//Convert
any capital letter to lower case
for(int i = 0; i <
MAX_WORD_SIZE; i++)
{
if(copy[i] ==
letter)//Check if letter matches with any letter in the correct
word
{
guess[i] = letter;
correct = true;
}
}
if(correct)//If guess was
correct
{
cout<<"Good Guess! ";
//If all letters
are matched, player won!
if(copy ==
guess)
{
cout<<"Congratulations, You Won!";
cout<<"Correct word is:
"<<copy<<endl<<endl;
return;
}
}
else//If letter was not a correct
guess
{
cout<<"Sorry, bad guess! ";
tries++;//One
more incorrect try
}
correct = false;
}
cout<<"The word was :
"<<copy<<endl;
}
/*End of hangman.cpp*/
/*words.txt*/

OUTPUTS:

Create a simple commented C++ HANGMAN game using CLASSES using the following specifications: - The game...
Create a Hangman Game in C++ using Classes. The program doesn't need to have the hangman drawing, it just needs the following: - Ten 3-letter words - Keep track of everytime the player misses a letter - Simple and commented code
Create the game hangman using c code: Program description In the game of hangman, one player picks a word, and the other player has to try to guess what the word is by selecting one letter at a time. If they select a correct letter, all occurrences of the letter are shown. If no letter shows up, they use up one of their turns. The player is allowed to use no more than 10 incorrect turns to guess what the...
Create a Program in C++ We need commentaries in the program
setter and getter we need the Output of the program and the code
compiling and use a file.
You will design a program that plays hangman. The rules are explained here. The program must at least include one class and client code. It does not require graphical representation but to keep track of the player misses. The host is the computer. The user has eight chances for error (otherwise,...
C++ Hangman (game) In this project, you are required to implement a program that can play the hangman game with the user. The hangman game is described in https://en.wikipedia.org/wiki/Hangman_(game) . Your program should support the following functionality: - Randomly select a word from a dictionary -- this dictionary should be stored in an ASCII text file (the format is up to you). The program then provides the information about the number of letters in this word for the user to...
For this assignment, you will create a command-line version of the game Hangman. For this assignment you will research on StringBuilder Class (Use this link) and use it in your code. Please finish the program in Java Language Your game should have a list of at least ten phrases of your choosing (appropriate to all audiences please!) The game chooses a random phrase from the list. This is the phrase the player tries to guess. (10) ● The phrase is...
For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...
Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...
I have this program using class that plays the game hangman the only thing that I need to make is a file or a function that will store the 10 words ( hey, ace, cow, fix, fly, fun, ice, max, new, sam) when the user starts the game the words most be chosen randomly not in any order C++ code: // Header of the class #ifndef Hangman_H #define Hangman_H #include <string> #include <iostream> #include <string.h> using namespace std; class Hangman...
Create a modification to the Hangman game to provide
enhancements for the user experience. Share the code in text format
in this thread.
Could someone please assist me coming up with a modification
in Python?
4. EXERCISE 4 The following code implements a very simple Hangman game: word = 'underutilise guesses = [] user_input = " while user_input == '0': user_input = input ("Enter a letter, or 0 to give up:') guesses.append(user_input) output = '' for letter in range(1, len...
Please create a Hangman game in Java language. For this game a random word will be selected from the following list (abstract, cemetery, nurse, pharmacy, climbing). You should keep a running tab of the user’s score and display it on screen; the user begins with 100 pts possible if they correctly guess the word without any mistakes. For every incorrect letter which is guessed, 10 pts should be taken away from what is left of their total possible points. For...