Question: Extra Credit: 0 0 P 2 : Derived Classes & Polymorphism Objectives: After performing this lab, the students should be able to - Implement
Extra Credit: P : 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:
Private Member variables:
a int PlayerAge
b Strings LastName and FirstName
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:
Private variables:
a String pNum
Public
a SetPlayerNumber which takes a string player number similar to #
Create a main in which you are able to populate the following players and print:
John Doe, years of Age, Player number
Jane Doe, years of Age, Player number
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 SetLastNamestring lName
lastName lName;
;
Create a new virtual function
here for the base class
protected:
string lastName;
;
class derivedUser : public BaseUser
public:
void SetFirstNamestring 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;
BaseUserPtrSetLastNameLuigi;
derivedUserPtr new derivedUser;
derivedUserPtrSetLastNameMario;
derivedUserPtrSetFirstNameSuper;
userList.pushbackBaseUserPtr;
userList.pushbackderivedUserPtr;
for int i ; i userList.size; i
userList.atiPrintItem;
return ;
SelfLab : OOP
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
