Question: Extra Credit: 0 0 P 2 : Derived Classes & Polymorphism Objectives: After performing this lab, the students should be able to - Implement

Extra Credit: 00P 2: Derived Classes \& Polymorphism
Objectives:
After performing this lab, the students should be able to
- Implement derived class
- Understand and use polymorphism in your code
Activities
Part A: Inheritance
You have been hired by the Chaffey football team to create a roster of players for display during sporting events regardless of sport (football, soccer, etc).
Create a Base class called basePlayer with the following:
1) Private Member variables:
a. int PlayerAge
b. Strings LastName and FirstName
2) Public Member functions:
a. SetName which takes the players first and last name
b. SetPlayerAge which takes an int player age
c. Print which prints
Create a derived class called SportsPlayer with the following:
1) Private variables:
a. String pNum
2) Public
a. SetPlayerNumber which takes a string player number similar to "\#42"
Create a main in which you are able to populate the following players and print:
John Doe, 20 years of Age, Player number 42
Jane Doe, 21 years of Age, Player number 22
Part B: Use Polymorphism
Write a new virtual print function for the base class below. ```
#include
#include
#include
using namespace std;
class BaseUser {
public:
void SetLastName(string lName){
lastName = lName;
};
/* Create a new virtual function
/* here for the base class*/
protected:
string lastName;
};
class derivedUser : public BaseUser {
public:
void SetFirstName(string fName){
firstName = fName;
};
void PrintItem(){
cout "Player First and last name: ";
cout firstName "" lastName endl;
};
private:
string firstName;
};
int main()
{
cout "====== welcome player =======
";
BaseUser* BaseUserPtr = nullptr;
derivedUser* derivedUserPtr = nullptr;
vector userList;
BaseUserPtr = new BaseUser();
BaseUserPtr->SetLastName("Luigi");
derivedUserPtr = new derivedUser();
derivedUserPtr->SetLastName("Mario");
derivedUserPtr->SetFirstName("Super");
userList.push_back(BaseUserPtr);
userList.push_back(derivedUserPtr);
for (int i =0; i userList.size(); ++i){
userList.at(i)->PrintItem();
}
return 0;
}
``` Self-Lab 10: OOP
Extra Credit: 0 0 P 2 : Derived Classes \ &

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!