Consider a class network as shown in figure given below. The class Employee derives information from both Account and Admin classes which in turn derive information from the class Person. Define all the four classes and write a program to input and display the information of an Employee.
#include<iostream.h>
#include<conio.h>
class person
{
public:
char name[10];
int code;
void getp()
{
cout<<"Enter Name : ";
cin>>name;
cout<<"\nEnter Code : ";
cin>>code;
}
};
class account : virtual public person
{
public:
double pay;
void getac()
{
cout<<"\nEnter Salary : ";
cin>>pay;
}
};
class admin : virtual public person
{
public:
double exp;
void getad()
{
cout<<"\nEnter Experience : ";
cin>>exp;
}
};
class employee : public account, public admin
{
public:
void disp()
{
cout<<"\n=========================\nName\t\t: "<<name;
cout<<"\nCode\t\t: "<<code;
cout<<"\nSalary\t\t: "<<pay;
cout<<"\nExperience\t: "<<exp;
cout<<"\n=========================";
}
};
void main()
{
clrscr();
employee e1;
e1.getp();
e1.getac();
e1.getad();
e1.disp();
getch();
}
Output :
No comments:
Post a Comment