Question: C++ It is missing it should have a bool method called hasMorePointsThan that takes a Player parameter and returns true if the player that is
C++
It is missing it should have a bool method called hasMorePointsThan that takes a Player parameter and returns true if the player that is executing the function has more points than the Player that was passed as a parameter. ?
Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It should have set methods for each of the stats. It should have a bool method called hasMorePointsThan that takes a Player parameter and returns true if the player that is executing the function has more points than the Player that was passed as a parameter. Otherwise it should return false. For example, if we have the function call "p1.hasMorePointsThan(p2)", then it should return true if p1 has more points than p2, but return false otherwise. Next write a class called Team that has five data members of type Player: a point guard, a shooting guard, a small forward, a power forward, and a center. The class should have a constructor that takes five Players and uses them to initialize each of those data members (in the given order). The class should have get and set methods for each data member. It should have a method named totalPoints that returns the sum of the points for all players on the team
#include
using namespace std;
class Player
{
private:
string name;
int points, rebounds, assists;
public:
Player()//default constructor
{
name = " ";
points = -1;
rebounds = -1;
assists = -1;
}
Player(string name,int points,int rebounds,int assists)//argument constructor
{
this->name = name;
this->points = points;
this->rebounds = rebounds;
this->assists = assists;
}
//get and set methods
string getName()
{
return name;
}
int getPoints()
{
return points;
}
int getRebounds()
{
return rebounds;
}
int getAssists()
{
return assists;
}
void setName(string name)
{
this->name = name ;
}
void setPoints(int points)
{
this->points = points;
}
void setRebounds(int rebounds)
{
this->rebounds = rebounds;
}
void setAssists(int assists)
{
this->assists = assists;
}
bool hasMorePointsThan(Player p)
{
if(this->points > p.points)
return true;
else
return false;
}
};
class Team
{
private:
Player pointGuard,shootingGuard, smallForward, powerForward, center;
public:
Team(Player pointGuard,Player shootingGuard, Player smallForward, Player powerForward,Player center)
{
this->pointGuard = pointGuard;
this->shootingGuard = shootingGuard;
this->smallForward = smallForward;
this->powerForward = powerForward;
this->center = center;
}
//get and set Players
Player getPointGuard()
{
return pointGuard;
}
Player getShootingGuard()
{
return shootingGuard;
}
Player getSmallForward()
{
return smallForward;
}
Player getPowerForward()
{
return powerForward;
}
Player getCenter()
{
return center;
}
void setPointGuard()
{
this->pointGuard = pointGuard;
}
void setShootingGuard()
{
this->shootingGuard = shootingGuard;
}
void setSmallForward()
{
this->smallForward = smallForward;
}
void setPowerForward()
{
this->powerForward = powerForward;
}
void setCenter()
{
this->center = center;
}
int totalPoints() //sum of all points by all players
{
return (pointGuard.getPoints()+shootingGuard.getPoints()+smallForward.getPoints()+powerForward.getPoints()+center.getPoints());
}
};
int main() {
Player p1("Garry T.",3,4,7);
Player p2("Tom B",4,2,3);
Player p3("Tony R.",2,6,4);
Player p4("Aaron R.",6,4,2);
Player p5("Roberts D.",4,6,1);
Team t(p1,p2,p3,p4,p5);
cout<<" Total Points of team : "< if(p1.hasMorePointsThan(p2)) cout<<" Garry has more points than Tom"; else cout<<" Garry does not have more points than Tom"; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
