Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data Structure class please help (instructions at bottom in bolded words) This is player.h file #pragma once #include using namespace std; class Player { public:

Data Structure class please help (instructions at bottom in bolded words) This is player.h file

#pragma once

#include

using namespace std;

class Player

{

public:

Player(const string& new_name = "No Name");

string getName() const;

int getPoints() const;

void setName(const string& new_name);

void setPoints(int new_points);

private:

string name;

int points;

};

This is the player.cpp file #include "Player.h"

Player::Player(const string& new_name)

{

setName(new_name);

}

string Player::getName() const

{

return name;

}

int Player::getPoints() const

{

return points;

}

void Player::setName(const string& new_name)

{

name = new_name;

}

void Player::setPoints(int new_points)

{

points = new_points;

}

This is the source.cpp file #include

#include

#include

#include

#include

#include "Player.h"

using namespace std;

int main()

{

const int M = 37;

const int N = 5;

Player player[N];

player[0].setName("Ged"); player[0].setPoints(0);

player[1].setName("Ted"); player[1].setPoints(0);

player[2].setName("Jed"); player[2].setPoints(0);

player[3].setName("Edd"); player[3].setPoints(0);

player[4].setName("Zed"); player[4].setPoints(0);

default_random_engine dre(static_cast(time(0)));

uniform_int_distribution player_uid(0, N - 1);

uniform_int_distribution dice_uid(1, 6);

int index = player_uid(dre);

do

{

index = (index + 1) % N;//implements circular array

int die1 = dice_uid(dre);

int die2 = dice_uid(dre);

int points = player[index].getPoints();

player[index].setPoints(points + die1 + die2);

cout << player[index].getName() << '/' << setw(2) << die1 + die2 << '/' << setw(2) << player[index].getPoints() << endl;

} while (player[index].getPoints() != M);

cout << player[index].getName() << " wins" << endl;

system("pause");

return 0;

}

Modify the simple race game as follows:

if a player's are greater than M then

1. the player loses 1/2 half of his points

2. the player loses his next turn

3. the game displays a message about the consequences of the roll of the player's dice

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

9. Describe the characteristics of power.

Answered: 1 week ago