127k views
5 votes
Create Player.h and Player.cpp to implement the Player class as described below. You will also need to create a playerDriver.cpp file to test your Player class implementation, but do not include those routines here. The Player class has the following attributes:Data members (private):Data members (private):

string: name The player’s name
double: points The player’s points
Member functions (public):
Default constructor Set name="" and points to value 0.
Parameterized constructor Takes a string and double initializing name and points, in this order
getName() Returns the player’s name as a string
getPoints() Returns the player’s points as a double
setName(string) Sets the player’s name (and returns nothing)
setPoints(double) Sets the player’s points (and returns nothing)

In the Answer Box below, paste your Player class and its implementation (the contents of Player.h and Player.cpp).

Do not have #ifndef or #define.
Do not add #include (or any other headers - they are provided)
Do not add using namespace std;
Do not add main() function
Note that there are some random test cases. These are not edge cases, but rather just randomly generated input values to make sure code is flexible. They're also meant to be mildly entertaining.

For example:

Test Result
// checking default constructor
Player stella;
cout << stella.getName() << endl;
cout << stella.getPoints() << endl;
0
// checking name setters and getters
Player stella;
stella.setName("Stella");
cout << stella.getName() << endl;
Stella
// checking points setters and getters
Player stella;
stella.setPoints(13.1);
cout << stella.getPoints() << endl;
13.1
// checking parameterized constructor
Player hector("Hector", 6.2);
cout << hector.getName() << endl;
cout << hector.getPoints() << endl;
Hector
6.2

1 Answer

0 votes

Answer:

Code is given below and output is attached:

Step-by-step explanation:

#include <iostream>

using namespace std;

class Player

{

string name;

double points;

public:

Player()

{

name = "";

points = 0;

}

Player(string userName, double userPoints)

{

name = userName;

points = userPoints;

}

void setName(string Name)

{

name = Name;

}

string getName()

{

return name;

}

void setPoints(double Points)

{

points = Points;

}

double getPoints()

{

return points;

}

};

int main()

{

Player stella;

cout<<stella.getName()<<endl;

cout<<stella.getPoints()<<endl;

stella.setName("Stella");

cout<<stella.getName()<<endl;

stella.setPoints(13.1);

cout<<stella.getPoints()<<endl;

Player hector("Hector",6.2);

cout<<hector.getName()<<endl;

cout<<hector.getPoints()<<endl;

return 0;

}

Create Player.h and Player.cpp to implement the Player class as described below. You-example-1
User Xaqq
by
3.3k points