Question: For questions 5 - 9 , consider the following two classes, Player and BasketballPlayer: class Player { protected: string name; double weight; double height; public:
For questions consider the following two classes, Player and BasketballPlayer:
class Player
protected:
string name;
double weight;
double height;
public:
Playerstring n double w double h
name n; weight w; height h;
string getName const
return name;
virtual void printStats const ;
;
class BasketballPlayer : public Player
private:
int fieldgoals;
int attempts;
public:
BasketballPlayerstring n double w
double h int fg int a : Playern w h
fieldgoals fg; attempts a;
void printStats const
cout name endl;
cout "Weight: weight;
cout Height: height endl;
cout FG: fieldgoals;
cout attempts: attempts;
cout Pct: double fieldgoals attempts endl;
;
int main
Player ptr;
BasketballPlayer johnsonMagic Johnson", ;
ptr &johnson;
ptrprintStats;
return ;
What does after function printStats do
Would the following line in main compile: Player p; why or why not?
Could I remove the printStats member function from BasketballPlayer? Why or why not?
Would the following line in main compile: Player ptr; why or why not?
Write code which creates a Player pointer eg Player p creates an object of class BasketballPlayer, and assigns the address of the object to the pointer. Why does this work?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
