1.write A Program To Implement Inheritance Shown Below Figure - Assume Suitable Member Function
1.write A Program To Implement Inheritance Shown Below Figure - Assume Suitable Member Function
Exercise:
1.Write a program to implement inheritance shown below figure.Assume suitable member
function.
#include<iostream.h>
#include<conio.h>
class furniture
{
char material[20];
float price;
public:
void getdata()
{
cout<<"\n Enter the material:";
cin>>material;
cout<<"\n Enter the price:";
cin>>price;
}
void putdata()
{
cout<<"\n Material is:"<<material;
cout<<"\n Price is:"<<price;
}
};
class table:public furniture
{
float height,surface;
public:
void accept()
{
cout<<"\n table details:";
cout<<"\n Enter the height:";
cin>>height;
cout<<"\n Enter the surface:";
cin>>surface;
}
void display()
{
cout<<"\n height is:"<<height;
cout<<"\n surface is:"<<surface;
}
};
void main()
{
table t;
clrscr();
t.getdata();
t.accept();
t.putdata();
t.display();
getch();
}
Output:
#include<iostream.h>
#include<conio.h>
class employee
{
int emp_no;
char emp_name[20],emp_designation[20];
public:
void input()
{
cout<<"\n Enter the employee no:";
cin>>emp_no;
cout<<"\n Enter the employee name:";
cin>>emp_name;
cout<<"\n Enter the desidnation of employee:";
cin>>emp_designation;
}
void output()
{
cout<<"\n Employee no is:"<<emp_no;
cout<<"\n Employee name is:"<<emp_name;
cout<<"\n Employee designation:"<<emp_designation;
cout<<"\n************************************";
}
};
class salary:public employee
{
float basic,hra,da,gross_sal;
public:
void accept()
{
cout<<"\n Enter the basic salary:";
cin>>basic;
}
void calculate()
{
hra=(15*basic)/100.0;
da=(44.5*basic)/100.0;
gross_sal=basic+da+hra;
cout<<"\n Basic salary:"<<basic;
cout<<"\n HRA:"<<hra;
cout<<"\n DA:"<<da;
cout<<"\n Gross salary:"<<gross_s;
}
};
void main()
{
salary s;
clrscr();
s.input();
s.accept();
s.output();
s.calculate();
getch();
}
Output: