1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
frez [133]
3 years ago
11

Create a class called Hangman. In this class, Create the following private variables: char word[40], progress[40], int word_leng

th. word will be used to store the current word progress will be a dash representation of the the current word. It will be the same length as the current word. If word is set to ‘apple’, then progress should be "‑‑‑‑‑" at the beginning of the game. As the user guesses letters, progress will be updated with the correct guesses. For example, if the user guesses ‘p’ then progress will look like "‑pp‑‑" Create a private function void clear_progress(int length). This function will set progress to contain all dashes of length length. If this function is called as clear_progress(10), this will set progress to "‑‑‑‑‑‑‑‑‑‑". Remember that progress is a character array; don’t forget your null terminator. Create the following protected data members: int matches, char last_guess, string chars_guessed, int wrong_guesses, int remaining. Create a public function void initialize(string start). This function will initialize chars_guessed to a blank string, wrong_guesses to 0. Set remaining to 6. Use strcpy() to set word to the starting word passed as start (You can use start.c_str() to convert it to a character array). Set word_length to the length of word. Call clear_progress in this function.
Computers and Technology
1 answer:
PSYCHO15rus [73]3 years ago
7 0

Answer:

See explaination

Explanation:

#include <cstring>

#include <cstdio>

#include <string>

#include <array>

#include <random>

#include <algorithm>

struct RandomGenerator {

RandomGenerator(const size_t min, const size_t max) : dist(min, max) {}

std::random_device rd;

std::uniform_int_distribution<size_t> dist;

unsigned operator()() { return dist(rd); }

};

struct Gallow {

void Draw() const

{

std::printf(" ________\n"

"| |\n"

"| %c %c\n"

"| %c%c%c\n"

"| %c %c\n"

"|\n"

"|\n", body[0], body[1], body[2], body[3],

body[4], body[5], body[6]);

}

bool Increment()

{

switch (++errors) {

case 6: body[6] = '\\'; break;

case 5: body[5] = '/'; break;

case 4: body[4] = '\\'; break;

case 3: body[3] = '|'; break;

case 2: body[2] = '/'; break;

case 1: body[0] = '(', body[1] = ')'; break;

}

return errors < 6;

}

char body[7] { '\0' };

int errors { 0 };

};

struct Game {

void Draw() const

{

#ifdef _WIN32

std::system("cls");

#else

std::system("clear");

#endif

gallow.Draw();

std::for_each(guess.begin(), guess.end(), [](const char c) { std::printf("%c ", c); });

std::putchar('\n');

}

bool Update()

{

std::printf("Enter a letter: ");

const char letter = std::tolower(std::getchar());

while (std::getchar() != '\n') {}

bool found = false;

for (size_t i = 0; i < word.size(); ++i) {

if (word[i] == letter) {

guess[i] = letter;

found = true;

}

}

const auto end_game = [this](const char* msg) {

Draw();

std::puts(msg);

return false;

};

if (not found and not gallow.Increment())

return end_game("#### you lose! ####");

else if (found and word == guess)

return end_game("#### you win! ####");

return true;

}

RandomGenerator rand_gen { 0, words.size() - 1 };

const std::string word { words[rand_gen()] };

std::string guess { std::string().insert(0, word.size(), '_') };

Gallow gallow;

static const std::array<const std::string, 3> words;

};

const std::array<const std::string, 3> Game::words{{"control", "television", "computer"}};

int main()

{

Game game;

do {

game.Draw();

} while (game.Update());

return EXIT_SUCCESS;

}

You might be interested in
Fill in the blanks using A to J below.
Gre4nikov [31]

Answer:

A.software written to meet specific needs of company

B.Related specialized programs combined in a unified package

4 0
3 years ago
Which function can you use to abbreviate the lengthy expression, A1+A2+A3+A3...+A19+A20?  MAX COUNT SUM ROUND
Naddika [18.5K]
Which function can you use to abbreviate the lengthy expression, A1+A2+A3+A3...+A19+A20? SUM
6 0
4 years ago
Read 2 more answers
There are 5 houses in a row and in 5 different colors.
tankabanditka [31]
What’s the question?
5 0
4 years ago
15.Every CPU needs to:
aliya0001 [1]

Answer:

Dissipate heat

Explanation:

As CPU works efficiently while there is cool

8 0
3 years ago
Which term describes a character used to separate items in a text file?
frosja888 [35]

Answer:

extension describes a character used to separate items in a text

6 0
3 years ago
Other questions:
  • What is the Web of Trust?
    12·1 answer
  • Dolphin Tecx is a new tech company that just issued smart watches to its
    9·1 answer
  • Templates allow for the quick creation of _____.
    7·1 answer
  • Which of the following statistical models is best to use to represent data showing the effect that changing the amount of daily
    6·2 answers
  • Which of the following is part of the process of publishing a website?
    7·2 answers
  • Reesa works for a large real estate company. She is responsible for installing and supporting the company's internet systems, in
    5·1 answer
  • Help ASAP please This is a skills lab simulation for college, it’s on Microsoft word is there a keyboard shortcut or something o
    12·1 answer
  • What is the datapath of add instruction?
    6·1 answer
  • Answer pleaseeeeeeeeeee!
    9·2 answers
  • A)​What would be the state of the following list after each of the first four passes in a Bubble sort, sorting into ascending se
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!