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
C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320....
C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320. Explain why and how this program outputs this number. int main(void) { int a = 5, b =20; int* ptr = &a; int** ptr2 = &ptr; printf("%d\n", ((int)*ptr * (int)*ptr2)); return 0; }
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...
You must use Windows Programming(Do NOT use Console) to complete this assignment. Use any C# method...
You must use Windows Programming(Do NOT use Console) to complete this assignment. Use any C# method you already know. Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance. Provide TextBox objects for withdrawals and deposits. A button object should be available for clicking to process withdrawal and deposit transactions showing the new balance. Document and...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept generic parameters and perform operation on them. Deliverables A listing of the fully commented, working source code of the Java program Test data for the code A screen shot of the application in execution Step 1 Create a new project. Name it "Assignment_2_1". Step 2 Build a solution. Write the Java source code necessary to build a solution for the problem below:You have just...
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,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] 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) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
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...
In this exercise we will practice using loops to handle collections/containers. Your job is to write...
In this exercise we will practice using loops to handle collections/containers. Your job is to write a program that asks the user to enter a sentence, then it counts and displays the occurrence of each letter. Note: your program should count the letters without regard to case. For example, A and a are counted as the same. Here is a sample run: Enter a sentence: It's a very nice day today! a: 3 times c: 1 times d: 2 times...
ASAP I need this code... Design and implement in Python language, a program that calculates the...
ASAP I need this code... Design and implement in Python language, a program that calculates the molecular weight of a formula. Your program should accept a formula in whatever form you choose as input from the user, and should display the molecular weight for that formula. Your program must be able to handle formulas that: consist of a single element, e.g., He    (worth 40 points) consist of a sequence of elements, e.g., H H O    (worth 20 points) contain numeric constants, e.g.,...
Need in C language also need full documentation/explanation of each line A student has established the...
Need in C language also need full documentation/explanation of each line A student has established the following monthly budget: Budget Categories Budgeted amount ----------------------------------------------------- Housing $ 580.00 Utilities $ 150.00 Household Expenses     $ 65.00 Transportation $ 50.00 Food $ 250.00 Medical $ 30.00 Insurance $ 100.00 Entertainment $ 150.00 Clothing $ 75.00 Miscellaneous $ 50.00 ---------------------------------------------------- Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT