Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C++ WITH 3 HEADER FILES, 3 IMPLEMENTATION FILES AND ONE MAIN FILE (athlete.h,

ID: 3873375 • Letter: I

Question

IN C++ WITH 3 HEADER FILES, 3 IMPLEMENTATION FILES AND ONE MAIN FILE

(athlete.h, athleteImp.cpp, baseball.h, baseballImp.cpp, basketball.h, basketballImp.cpp, main.cpp)

Polymorphism, Pointers, and Virtual Functions

Construct a base class called athlete. This class should have a member attribute called sport which contains the name of the sport the athlete plays. This class should have two virtual functions called scorePoints() and move().

Write two derived classes from the base athlete class. These classes should pertain to a particular sport. For example, basketballPlayer or baseballPlayer would be subclasses of the athlete class. The derived classes should put the name of the sport by default into the sport member attribute. Additionally, they should redefine the scorePoints() and move() functions with information related that particular sport. For example, a hockeyPlayer class could have “I score points by shooting the puck in the net” for its scorePoints() function and “I move by skating on ice skates” for its move() function.

Your driver file should include a processAthlete() function which accepts as a parameter an object of the base athlete class. In the function, you should call the accessor for the sport attribute, as well as the two virtual functions. The proper information related to the class should be displayed (the name of the sport, how points are scored, and how the athlete moves). This function should be called twice, once for each object of the two different derived classes.

You are required to write header files for the base athlete class as well as the derived athlete classes. Function bodies need to be defined in implementation files and the main function will be in main.cpp. Make sure your program is properly documented.

Explanation / Answer

Hi,
here are all the files you can use,
Here is the breakup of files
header files(.h)- should only contain definition
cpp files - should have the functions declared in header files
main- driver class to test.
header files are as below-

class athlete {
private:
string sport;
public:
/* virtual functions */
virtual void scorePoints();
virtual void move();
}
class hockeyPlayer : public athlete {
private :
string sport="hockey";
void scorePoints();
void move();
};

class basketballPlayer : public athlete {
private :
string sport="basketball";
void scorePoints();
void move();
};
cpp files

void athlete::scorePoints(){
}
void athlete::move(){
}


void hockeyPlayer::scorePoints(){
cout<<"I score points by shooting the puck in the net"<<endl;
}
void hockeyPlayer::move(){
cout<<"I move by skating on ice skate"<<endl;
}
//
void basketballPlayer::scorePoints(){
cout<<"I score points by putting ball in basket"<<endl;
}
void basketballPlayer::move(){
cout<<"I move by running on court"<<endl;
}
main files
#include <iostream>
/* including header files */
#include "athlete.h"
#include "hockeyPlayer.h"
#include "basketballPlayer.h"
using namespace std;
processAthlete(athlete a){ //fucntion to print class meaning
cout<<a.sport<<endl;
cout<<a.scorePoints()<<endl;
cout<<a.move()<<endl;
  
}
int main()
{
athlete a;//base class object
//derived class objects
hockeyPlayer h;
basketballPlayer b;
a=h;
processAthlete(a);//calling for each derived class object
a=b;
processAthlete(a);
return 0;
}

I have added comments everywhere to help you understand,
Thumbs up if this was helpful, otherwise let me know in comments