Create a class named 'Member' having the following members
1 data member
2 name
3 age
4 phone number
5 address
6 salary
It also has method named 'print salary' of the members. Two classes'employes ' & ' manager' inherits the 'member' classes . The 'employee' & 'manger' speclization and ' department ' respectively . Now, assign name , age , phone number, address & salary to an employer & a manger by making an object of both of these classes and print.
#include <iostream>
using namespace std;
//define member class
class Member{
public:
string name;
int age;
string phoneNo;
string address;
double salary;
void printSalary(){
cout<<salary<<endl;
}
};
//define employee classs
class Employee: public Member{
private:
string specialization;
};
//define manager class
class Manager: public Member{
private:
string department;
};
int main()
{
Employee e;
Manager m;
e.name="John";
e.age=29;
e.phoneNo="234-23-43";
e.address="4352-43";
e.salary=500000;
m.name="James";
m.age=32;
m.phoneNo="222-123-5";
m.address="6542-34";
m.salary=700000;
cout<<m.salary;
return 0;
}
Comments
Leave a comment