Question
I need to put this C++ code in separate files, such as the main.cpp, the Class.h (header file) and the Class.cpp #include #include #include #include
I need to put this C++ code in separate files, such as the main.cpp, the Class.h (header file) and the Class.cpp
#include
int BodyParts = 6; // There are 6 body parts: head, torso, 2 arms and 2 legs
// Declaring the class for our game class Hangman{ private: char letter; int limb_extractor = 0, right_guess, lenght; // The limb_extractor is 0 because we must declare that the game starts with 0 limbs // As the player guesses wrong, the limbs increases string word, words[10]; // We must declare the necessary variables for the player inputs // and keep track of the misses
public: // Function that returns the right guess to fill the blank with the correct letter int fill_blank(char letter_input, string hidden_word, string &guess_word){ right_guess = 0; lenght = hidden_word.length(); for(int i=0; i if (letter_input == hidden_word[i]){ guess_word[i] = letter_input; right_guess++; // If the letter the player inputs is in the secret word, the score increases } } return right_guess; } // Constructor Hangman(){ // Declaring the ten 3 letter words words[0] = "cat"; words[1] = "pen"; words[2] = "fan"; words[3] = "lot"; words[4] = "can"; words[5] = "ham"; words[6] = "dog"; words[7] = "rat"; words[8] = "hat"; words[9] = "fun"; // Function to randomize the word to appear so the player does not memorize the order srand(time(NULL)); int x = rand()%10; word = words[x]; // The secret word will be hidden in asterisks string disguise(word.length(), '*'); // Calling the Game function Game(disguise); } //Define the play function void Game(string disguise){ // User interface cout // While loop will end if the player guesses wrong 6 times or if he guesses right three times while (limb_extractor > letter; if (fill_blank(letter, word, disguise)==0){ cout if (word==disguise){ cout if(limb_extractor == BodyParts){ cout } }; int main(){ // Calls class with object's name Hangman Project; return 0; } /* OUTPUT: This is a simple Hangman Game. Each word consists of 3 letters only. You have 6 chances to guess wrong. Good luck! *** Guess a letter: c That letter is correct :) You have 6 lives left. c** Guess a letter: a That letter is correct :) You have 6 lives left. ca* Guess a letter: t That letter is correct :) You have 6 lives left. You won! The secret word was: cat Process returned 0 (0x0) execution time : 6.825 s Press any key to continue. */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started