Question

The programming language for this exercise must be on C++. The exercise is the following: Design...

The programming language for this exercise must be on C++. The exercise is the following:
Design a program that plays hangman. 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 list of words is 10 and all of them will be three-letters(file?)
Evaluation criteria:
Documentation 20%
Logics and Execution 60%
Interface 20%

Homework Answers

Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

class Hangman
{
private :
  
//Declare and string array
static const string words[10];
public :
Hangman();
void guessWord();
int indx;
};


const string Hangman::words[10] = {"cat","pen","pop","can","pan","rat","mat","bat","pin","bun"};

Hangman::Hangman()
{
}

//This function will ask the user to guess a word
void Hangman::guessWord()
{
int seedVal = 0;
// t is a 'time_t' type variable
time_t t;
seedVal = (unsigned)time(&t);
srand(seedVal);
//Generating a random number between 0-25
this->indx= rand() % (10);
  
string word=words[indx];
char ch;
const int NO_OF_MISSES=7;
int miss = 0,flag;
int len = word.length();
char arr[len];
for (int i = 0; i < len; i++)
{
arr[i] = '*';
}

while (len != 0)
{
flag=0;
cout << "(Guess) Enter a letter in word ";
for (int i = 0; i < word.length(); i++)
{
cout << arr[i];
}
cout << ">";
cin >> ch;

for (int i = 0; i < word.length(); i++)
{
if (word[i] == ch)
{
arr[i] = ch;
len--;
flag=1;
}
  
}
  
if(flag==0)
{
miss++;
cout<<"No of gueses Remaining :"<<NO_OF_MISSES-miss<<endl;
if(miss==NO_OF_MISSES)
{
cout<<"You Lost the game."<<endl;
cout<<"The Word is :"<<word<<endl;
break;
}
}
if (len == 0)
{
cout<<"\nThe word is :"<<word<<endl;  
cout<<"You won the game."<<endl;  
}
  
}

}


int main()
{
//Declaring variables
string word;
char ch;
Hangman h;

/* This while loop continues to execute
* until the user enters a 'y' or 'Y'
*/
while (true)
{

//calling a function
h.guessWord();
  
  
//Prompting the user to run again
cout << "\nDo you Want to continue(Y/N):";
cin >> ch;

if (ch == 'y' || ch == 'Y')
{

continue;
}
else
{
break;
}
}


return 0;
}


================================================

Output:


=====================Could you plz rate me well.Thank You

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas,...
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas, the following les for each of your programs: (1) the client and the server source les each (2) the client and the serve executable les each (3) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identiers suitable, to enable enhanced readability of the code. Problems 1. Write an ftp client that...
use repl.it intro to C-programing no advance code also put good comment that i can know...
use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter,...
in c++ : Problem Domain: The classic TicTacToe game alternatively place Xs and Os on a...
in c++ : Problem Domain: The classic TicTacToe game alternatively place Xs and Os on a 3x3 grid. The winner is the first player to place 3 consecutive marks in a horizontal, vertical or diagonal row. Understanding the Problem: In this assignment, you will: 1) Create a tic tac toe board data structure. 2) Check for game over. 3) Clear the tic tac toe game for each game. 4) Display the tic tac toe board to screen. 5) Simulate playing...
You are coding a simple game called Pig. Players take turns rolling a die. The die...
You are coding a simple game called Pig. Players take turns rolling a die. The die determines how many points they get. You may get points each turn your roll (turn points), you also have points for the entire game (grand points). The first player with 100 grand points is the winner. The rules are as follows: Each turn, the active player faces a decision (roll or hold): Roll the die. If it’s is a: 1: You lose your turn,...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT