Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

//Problem no:

/*
Write a program C++ to demonstrate the feature of
hierarchical inheritance of class baseemp and
customer and print the customer account no,balance
,basic salary,dearnessallowance,house rent allowance
and gross allowance.
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
classbaseemp
{
private:
intempcode;
charempname[25];
charempdesig[15];
public:
voidinput_data(void);
void display(void);
};
classderivedemp:publicbaseemp
{
private:
doublesalary,gross;
floatda,hra;
public:
voidinput_salary(void);
doublecal_da(void);
doublecal_hra(void);
doublecal_gross(void);
voidprint_salary(void);
};
classderivedcust:publicbaseemp
{
private:
longintacc_no;
float balance;
public:
voidread_cust();
voidshow_cust();
};
voidbaseemp::input_data(void)
{
cout<<endl<<" Enter code: ";
cin>>empcode;
cout<<endl<<" Enter name: ";
gets(empname);
cout<<endl<<" Enter designation: ";
gets(empdesig);
}
voidbaseemp::display(void)
{
cout<<endl<<" code= "<<empcode<<endl;
cout<<" name= "<<empname<<endl;
cout<<" designation="<<empdesig<<endl;
}
voidderivedemp::input_salary(void)
{
cout<<endl<<" Enter Employee information"<<endl;
input_data();
cout<<" Enter salary: ";
cin>>salary;
da=cal_da();
hra=cal_hra();
gross=cal_gross();
}
doublederivedemp::cal_da(void)
{
return(1.20*salary);
}
doublederivedemp::cal_hra(void)
{
return(0.15*salary);
}
doublederivedemp::cal_gross(void)
{
return(salary+da+hra);
}
voidderivedemp::print_salary(void)
{
display();
cout<<" Basic salary= "<<salary<<endl;
cout<<" Dearness Allowance= "<<da<<endl;
cout<<" House Rent Allowance= "<<hra<<endl;
cout<<" Gross Salary= "<<gross<<endl;
}
voidderivedcust::read_cust(void)
{
cout<<"\n Enter information for customer";
input_data();
cout<<endl<<" Enter the account number: ";
cin>>acc_no;
cout<<"\n Enter the balance amount: ";
cin>>balance;
}
voidderivedcust::show_cust(void)
{
display();
cout<<"\n Customer account no: "<<acc_no;
cout<<"\n Customer Balance: "<<balance;
}
void main()
{
clrscr();
derivedempemp;
derivedcustcust;
emp.input_salary();
cust.read_cust();
cout<<"\n ----------Here is the employee information----------";
emp.print_salary();
cout<<"\n ----------Here is customer information----------";
cust.show_cust();
getch();
}

You might also like