PLEASE HELP THIS C++ Create an inheritance hierarchy for Person / Employee / Man
ID: 3688421 • Letter: P
Question
PLEASE HELP THIS C++
Create an inheritance hierarchy for Person / Employee / Manager
Person
Data members
- first name
- last name
- age
Employee
Data members
- salary
Manager
Data members
- bonus
1. Instantiate an Employee object and a Manager object.
2. Provide data to initialize the data members as appropriate.
3. Write getter functions that will display all the information stored in each object.
Employee: First Name, Last Name, Age, Salary
Manager: First Name, Last Name, Age, Salary, Bonus
4. Use the getter function written in step 3 to display the information stored in the
objects.
Explanation / Answer
Answer -
#include <iostream>
#include <string.h>
using namespace std;
class Person
{
public :
char first_name[20],Last_name[20];
int age;
};
class Employee : public Person
{
public :
int salary;
Employee()
{
}
Employee(char f_name[20],char L_name[20],int age1,int salary1)
{
strcpy (first_name,f_name);
strcpy (Last_name,L_name);
age=age1;
salary=salary1;
}
void getter()
{
cout<<"------Employee Details-----";
cout<<" First Name : "<<first_name;
cout<<" Last Name : "<<Last_name;
cout<<" Age : "<<age;
cout<<" Salery : "<<salary;
}
};
class Manager : public Employee
{
public :
int bonus;
Manager(char f_name[20],char L_name[20],int age1,int salary1,int bonus1)
{
strcpy (first_name,f_name);
strcpy (Last_name,L_name);
age=age1;
salary=salary1;
bonus=bonus1;
}
void getter()
{
cout<<" ------Manager Details-----";
cout<<" First Name : "<<first_name;
cout<<" Last Name : "<<Last_name;
cout<<" Age : "<<age;
cout<<" Salery : "<<salary;
cout<<" Bonus : "<<bonus;
}
};
int main()
{
char Fname[20]="Rohit";
char Lname[20]="Kumar";
Employee emp(Fname,Lname,25,20000);
emp.getter();
Manager man(Fname,Lname,25,20000,2000);
man.getter();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.