Homework Solution: C++ PROGRAMMING QUESTION…

    C++ PROGRAMMING QUESTION Boom is a classic word or phrase guessing game with limited tries and something catastrophic if the word is missed - a firecracker goes (you guessed it) Boom!. A game in progress looks something like the screen shot to the right asi i i e sa es i e: I Below is a simple UML class diagram of the Full Credit version of the game. Note that Main isnt actually a class its simply the usual main function This time around, implement a .h and .cpp for each class (as discussed in Thursdays lecture) The Puzzle class represents the game. The_solution field1 is the string that is the word or phrase the player is trying to guess. The -guesses array (like a vector, but without methods) holds a Boolean for each ASCII character. For example-guesses[a] is true if a has been guessed, false if not. ain + main: int Puzzle Fuse string me: int The Puzzle constructor accepts the solution, which should be stored in Puzzle(solution: string solution. The guess method accepts +guess(c: char): bool a single character (the players guess), and returns true if the character is valid (between a and z, and not yet guessed) and false otherwise. It should also update_guesses. The solve method accepts a proposed solution, and returns true if correct (it matches_solution) or false if incorrect. The to_string method returns the players view of the puzzle - that is, characters that have been guessed are visible, those that have not been guessed are replaced with a _, and spaces are not changed. The get solution getter method simply returns_solution. guesses 255]: bool time int + burn(): bool + to strin strin + solve(proposed solution: string): bool + to string): string + get solution): strin The Fuse constructor accepts the time (i.e., number of guesses) that may elapse before the firecracker goes boom. The burn method decrements the remaining time, and returns true if any time remains or false if time has expired. The to_string method returns an ASCII art representation of the firecracker with the number of segments of fuse representing the time (aka number of guesses) remaining 1 For all fields, you may use or omit the leading underscore, as you please. The UML omits them media%2Fa7b%2Fa7b32636-dfa1-4c2d-bc10-f7
    Boom is a classic word or phrase guessing game with limited tries and something catastrophic if the word is missed - a firecracker goes (you guessed it) "Boom!". A game in progress looks something like the screen shot to the right asi i i e sa es i e: I Below is a simple UML class diagram of the Full Credit version of the game. Note that Main isn't actually a class it's simply the usual main function This time around, implement a .h and .cpp for each class (as discussed in Thursday's lecture) The Puzzle class represents the game. The_solution field1 is the string that is the word or phrase the player is trying to guess. The -guesses array (like a vector, but without methods) holds a Boolean for each ASCII character. For example-guesses[a] is true if a has been guessed, false if not. ain + main: int Puzzle Fuse string me: int The Puzzle constructor accepts the solution, which should be stored in Puzzle(solution: string solution. The guess method accepts +guess(c: char): bool a single character (the player's guess), and returns true if the character is valid (between a and 'z', and not yet guessed) and false otherwise. It should also update_guesses. The solve method accepts a proposed solution, and returns true if correct (it matches_solution) or false if incorrect. The to_string method returns the player's view of the puzzle - that is, characters that have been guessed are visible, those that have not been guessed are replaced with a '_', and spaces are not changed. The get solution getter method simply returns_solution. guesses 255]: bool time int + burn(): bool + to strin strin + solve(proposed solution: string): bool + to string): string + get solution): strin The Fuse constructor accepts the time (i.e., number of guesses) that may elapse before the firecracker goes boom. The burn method decrements the remaining time, and returns true if any time remains or false if time has expired. The to_string method returns an ASCII art representation of the firecracker with the number of segments of fuse representing the time (aka number of guesses) remaining 1 For all fields, you may use or omit the leading underscore, as you please. The UML omits them

    Expert Answer

     
    #include<iostream> #include<vector>

    C++ PROGRAMMING QUESTION

    Vociferate is a graceful order or turn fancying recreation with poor tries and bigwig catastrophic if the order is missed - a firecracker goes (you fancyed it) Vociferate!. A recreation in advancement looks bigwig love the shade shot to the equitable asi i i e sa es i e: I Below is a unaffected UML arrange diagram of the Full Credit statement of the recreation. Referablee that Deep isnt really a arrange its barely the common deep office This period encircling, tool a .h and .cpp coercion each arrange (as discussed in Thursdays dissertation) The Enigma arrange represents the recreation. The_disruption field1 is the string that is the order or turn the player is involved to fancy. The -guesses draw-up (love a vector, nevertheless externally processs) holds a Boolean coercion each ASCII genius. Coercion example-guesses[a] is gentleman if a has been fancyed, fiction if referable. ain + deep: int Enigma Melt string me: int The Enigma maker accepts the disruption, which should be stored in Enigma(solution: string disruption. The fancy process accepts +guess(c: char): bool a individual genius (the players fancy), and income gentleman if the genius is sufficient (betwixt a and z, and referable nevertheless fancyed) and fiction defectively. It should as-well update_guesses. The clear-up process accepts a contemplated disruption, and income gentleman if amend (it matches_solution) or fiction if inaccurate. The to_string process income the players aspect of the enigma - that is, geniuss that accept been fancyed are manifest, those that accept referable been fancyed are replaced with a _, and spaces are referable alterable. The attain disruption attainter process barely income_solution. fancyes 255]: bool period int + ignite(): bool + to strin strin + clear-up(contemplated disruption: string): bool + to string): string + attain disruption): strin The Melt maker accepts the period (i.e., estimate of fancyes) that may intervene precedently the firecracker goes vociferate. The ignite process decrements the retaining period, and income gentleman if any period offal or fiction if period has expired. The to_string process income an ASCII tactics fidelity of the firecracker with the estimate of segments of melt representing the period (aka estimate of fancyes) retaining 1 Coercion entire fields, you may portraiture or pass-by the promotive underscore, as you gladden. The UML pass-bys them

    media%2Fa7b%2Fa7b32636-dfa1-4c2d-bc10-f7

    Vociferate is a graceful order or turn fancying recreation with poor tries and bigwig catastrophic if the order is missed – a firecracker goes (you fancyed it) “Boom!”. A recreation in advancement looks bigwig love the shade shot to the equitable asi i i e sa es i e: I Below is a unaffected UML arrange diagram of the Full Credit statement of the recreation. Referablee that Deep isn’t really a arrange it’s barely the common deep office This period encircling, tool a .h and .cpp coercion each arrange (as discussed in Thursday’s dissertation) The Enigma arrange represents the recreation. The_disruption field1 is the string that is the order or turn the player is involved to fancy. The -guesses draw-up (love a vector, nevertheless externally processs) holds a Boolean coercion each ASCII genius. Coercion example-guesses[a] is gentleman if a has been fancyed, fiction if referable. ain + deep: int Enigma Melt string me: int The Enigma maker accepts the disruption, which should be stored in Enigma(solution: string disruption. The fancy process accepts +guess(c: char): bool a individual genius (the player’s fancy), and income gentleman if the genius is sufficient (betwixt a and ‘z’, and referable nevertheless fancyed) and fiction defectively. It should as-well update_guesses. The clear-up process accepts a contemplated disruption, and income gentleman if amend (it matches_solution) or fiction if inaccurate. The to_string process income the player’s aspect of the enigma – that is, geniuss that accept been fancyed are manifest, those that accept referable been fancyed are replaced with a ‘_’, and spaces are referable alterable. The attain disruption attainter process barely income_solution. fancyes 255]: bool period int + ignite(): bool + to strin strin + clear-up(contemplated disruption: string): bool + to string): string + attain disruption): strin The Melt maker accepts the period (i.e., estimate of fancyes) that may intervene precedently the firecracker goes vociferate. The ignite process decrements the retaining period, and income gentleman if any period offal or fiction if period has expired. The to_string process income an ASCII tactics fidelity of the firecracker with the estimate of segments of melt representing the period (aka estimate of fancyes) retaining 1 Coercion entire fields, you may portraiture or pass-by the promotive underscore, as you gladden. The UML pass-bys them

    Expert Confutation

     

    #include<iostream>

    #include<vector>

    #include<array>

    #include<algorithm>

    #include<map>

    #include<set>

    #include<hash_map>

    #include<hash_set>

    #include<list>

    #include<queue>

    #include<cmath>

    #include<stack>

    #include<deque>

    #include<unordered_map>

    #include<unordered_set>

    #include<string>

    #include<memory>

    #include<thread>

    #include<stdlib.h>

    #include<fstream>

    #include <iostream>

    #include <string>

    #include<cassert>

    using namespace std;

    arrange Melt{

    private:

    int _time;

    public:

    Fuse(int t) : _time(t){}

    bool ignite() {

    _period = _period – 1;

    if (_period <= 0)

    return fiction;

    else

    return gentleman;

    }

    string to_string() {

    string temp = “”;

    int i = 0;

    coercion (i = 0; i < _time; i++)

    temp = temp + ‘-‘;

    temp = temp + ‘*’;

    return temp;

    }

    };

    arrange Enigma{

    private :

    string _solution;

    bool _guesses[26];

    public:

    Puzzle(string disruption) : _solution(solution) {

    int i = 0;

    coercion (i = 0; i < 26; i++)

    _guesses[i] = fiction;

    }

    bool fancy(char c) {

    //cout << _solution.find(c) << endl;

    if (c >= ‘a’ && c <= ‘z’ && _solution.find(c) >= 0 && _solution.find(c)<_solution.length() && _guesses[c – ‘a’] == fiction) {

    _guesses[c-‘a’] = gentleman;

    return gentleman;

    }

    else

    return fiction;

    }

    bool clear-up(string contemplated_solution) {

    if (proposed_disruption == _solution)

    return gentleman;

    else

    return fiction;

    }

    string to_string() {

    string temp = “”;

    int i;

    coercion (i = 0; i < _solution.length(); i++) {

    if ( _solution[i] >=’a’ && _solution[i]<=’z’ && _guesses[_solution[i]-‘a’])

    temp = temp + _solution[i];

    else if (_solution[i] >= ‘a’ && _solution[i] <= ‘z’)

    temp = temp + ‘_’;

    else

    temp = temp + _solution[i];

    }

    temp = temp + “:”;

    return temp;

    }

    string attainSolution() {

    return _solution;

    }

    };

    void evidence(string period, string disruption) {

    cout << ” ” << period<<endl;

    cout << ” /” << endl;

    cout << “,+,” << endl;

    cout << “| |” << endl;

    cout << “| |” << endl;

    cout << ” – ” << endl;

    cout << disruption << endl;

    }

    int deep() {

    Enigma puz(“a stitch in period saves nine”);

    Melt fus(5);

    bool give-in = gentleman;

    string contemplated_solution;

    char ch;

    cout << “================” << endl;

    cout << ” B O O M ! ” << endl;

    cout << “================” << endl<<endl;

    cout << “Enter inferior condition scholarship to fancy,” << endl;

    cout << “! to offer a disruption” << endl;

    cout << “0 to exit” << endl;

    display(fus.to_string(), puz.to_string());

    while (flag) {

    cin >> ch;

    if (ch == ‘!’) {

    cout << “Enter contemplated disruption ” << endl;

    fflush(stdin);

    getline(cin, contemplated_solution);

    if (puz.solve(proposed_solution)) {

    cout << “*** W I N N E R ***” << endl;

    give-in = fiction;

    }

    else {

    cout << “###### B O O M ######” << endl;

    cout << “The confutation was : ” << puz.getSolution() << endl;

    give-in = fiction;

    }

    }

    else if (ch == ‘0’) {

    give-in = fiction;

    }

    else {

    if (puz.guess(ch)){

    bool t = fus.burn();

    if (!t) {

    cout << “###### B O O M ######” << endl;

    cout << “The confutation was : ” << puz.getSolution() << endl;

    give-in = fiction;

    break;

    }

    display(fus.to_string(), puz.to_string());

    }

    else{

    cout << “Insufficient genius – examine again” << endl;

    }

    }

    }

    return 0;

    }

    Sample ShadeShot of Program