Question: Hello and good day! Could you clean up this code and remove the HTML away from this as I am unsure how to do it?

Hello and good day!

Could you clean up this code and remove the HTML away from this as I am unsure how to do it?

#include

#include

#include

class Player {

private:

std::string __name;

int __points;

int __counter;

float __percentage;

int __yes_counter;

public:

Player(std::string name) : __name(name), __points(0), __counter(0),

__percentage(0), __yes_counter(0) {}

std::string get_name() { return __name; }

int get_points() { return __points; }

Player* has_won() {

if (__points == 50) {

return this;

}

return nullptr;

}

void add_points(int pts) {

__counter += 1;

__points += pts;

if (pts > 0) {

add_average(pts);

}

if (__points > 50) {

__points = 25;

std::cout << __name << " gets penalty points!" << std::endl;

}

else if (pts > (__points / __counter)) {

std::cout << "Cheers " << __name << "!" << std::endl;

}

if (__points >= 40 && __points <= 49) {

std::cout << __name << " needs only " << 50 - __points

<< " points. It's better to avoid knocking down the pins with higher points."

<< std::endl;

}

}

void add_average(int pts) {

if (pts > 0) {

__yes_counter += 1;

__percentage = (__yes_counter / (float)__counter) * 100;

}

else if (__yes_counter == 0) {

return;

}

__percentage = (__yes_counter / (float)__counter) * 100;

}

std::string get_average() {

std::stringstream ss;

ss << std::fixed << std::setprecision(1) << __percentage / 2;

return ss.str();

}

};

int main() {

Player *player1 = new Player("Matti");

Player *player2 = new Player("Teppo");

int throw = 1;

while (true) {

Player *in_turn;

if (throw % 2 == 0) {

in_turn = player1;

} else {

in_turn = player2;

}

int pts;

std::cout << "Enter the score of player " << in_turn->get_name() << " of throw " << throw​`oaicite:{"index":0,"invalid_reason":"Malformed citation << \": \"; std::cin >>"}`​ pts;

in_turn->add_points(pts);

in_turn->add_average(pts);

if (in_turn->has_won()) {

std::cout << "Game over! The winner is " << in_turn->get_name() << "!" << std::endl;

return 0;

}

std::cout << "" << std::endl;

std::cout << "Scoreboard after throw " << throw << ":" << std::endl;

std::cout << player1->get_name() << ": " << player1->get_points() << " p, hit percentage " << player1->get_average() << std::endl;

std::cout << player2->get_name() << ": " << player2->get_points() << " p, hit percentage " << player2->get_average() << std::endl;

std::cout << "" << std::endl;

throw += 1;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!