#include<iostream.h>
#include<conio.h>
class person
{
protected:
int sno;
char sname[10];
public:
void getps()
{
cout<<"\t\t VIRTUAL BASE CLASS \n";
cout<<"\t\t ---------------------\n";
cout<<"\n Enter the Sno:";
cin>>sno;
cout<<"\n Enter the Name:";
cin>>sname;
}
};
class salary:virtual public person
{
protected:
float sal;
public:
void getsalary()
{
cout<<"\n Enter the Salary:";
cin>>sal;
}
};
class bonus:virtual public person
{
protected:
float bonus;
public:
void getbonus()
{
cout<<"\n Enter the bonus:";
cin>>bonus;
}
};
class salesperson:public salary,public bonus
{
protected:
float totsal;
public:
void calculate()
{
totsal=sal+bonus;
}
void distotsal()
{
cout<<"\t\t EMPLOYEE DETAILS \n";
cout<<"\t\t -------------------\n";
cout<<"\n Sno :"<<sno<<"\n";
cout<<"\n Sname :"<<sname<<"\n";
cout<<"\n Salary :"<<sal<<"\n";
cout<<"\n Bonus :"<<bonus<<"\n";
cout<<"\n Total Salary :"<<totsal<<"\n";
}
};
void main()
{
salesperson p;
clrscr();
p.getsalary();
p.getbonus();
p.calculate();
p.distotsal();
getch();
}
------------
OUTPUT:
------------
VIRTUAL BASE CLASS
-------------------------------
Enter the Sno :111
Enter the Name : Ashok
Enter the Salary : 500000
Enter the bonus :5000
EMPLOYEE DETAILS
-----------------------------
Sno :111
Sname :Arun
Salary : 500000
Bonus : 5000
Total salary:505000
#include<conio.h>
class person
{
protected:
int sno;
char sname[10];
public:
void getps()
{
cout<<"\t\t VIRTUAL BASE CLASS \n";
cout<<"\t\t ---------------------\n";
cout<<"\n Enter the Sno:";
cin>>sno;
cout<<"\n Enter the Name:";
cin>>sname;
}
};
class salary:virtual public person
{
protected:
float sal;
public:
void getsalary()
{
cout<<"\n Enter the Salary:";
cin>>sal;
}
};
class bonus:virtual public person
{
protected:
float bonus;
public:
void getbonus()
{
cout<<"\n Enter the bonus:";
cin>>bonus;
}
};
class salesperson:public salary,public bonus
{
protected:
float totsal;
public:
void calculate()
{
totsal=sal+bonus;
}
void distotsal()
{
cout<<"\t\t EMPLOYEE DETAILS \n";
cout<<"\t\t -------------------\n";
cout<<"\n Sno :"<<sno<<"\n";
cout<<"\n Sname :"<<sname<<"\n";
cout<<"\n Salary :"<<sal<<"\n";
cout<<"\n Bonus :"<<bonus<<"\n";
cout<<"\n Total Salary :"<<totsal<<"\n";
}
};
void main()
{
salesperson p;
clrscr();
p.getsalary();
p.getbonus();
p.calculate();
p.distotsal();
getch();
}
------------
OUTPUT:
------------
VIRTUAL BASE CLASS
-------------------------------
Enter the Sno :111
Enter the Name : Ashok
Enter the Salary : 500000
Enter the bonus :5000
EMPLOYEE DETAILS
-----------------------------
Sno :111
Sname :Arun
Salary : 500000
Bonus : 5000
Total salary:505000
0 comments:
Post a Comment