Define a class Person with members name,age,gender and location type. Define another
class which is derived from Person named Salary with members basic,da and hra .Calculate
net salary of a person . HRA depends on the location type. Location type can be 'A','B',or 'C'.
For 'A' hra is 500, for 'B' hra is 1000, and for 'C' it is 1500.
#include <iostream>
using namespace std;
// Person class
class Person
{
char name[30];
int age;
char gender[6];
char locationType[10];
public:
void getDetails()
{
cout<<"\n\n ------Please enter person details---";
cout<<"\n Person Name:";
cin>>name;
cout<<"\n Person age(in digit):";
cin>>age;
cout<<"\n Gender:";
cin>>gender;
cout<<"\n Location Type:";
cin>>locationType;
}
void displayDetails()
{
cout <<"\n Person Name:"<<name;
cout <<"\n Person age:"<<age;
cout <<"\n Gender:"<<gender;
cout <<"\n Location Type:"<<locationType;
}
};
class Salary: public Person
{
float basic, da, hra, netPayout;
public:
void getPayDetails()
{
getDetails();
cout << "Enter the Basic pay:";
cin>>basic;
cout << "Enter the Humen Resource Allowance:";
cin>>hra;
cout << "Enter the Dearness Allowance :";
cin>>da;
}
void calculate()
{
netPayout = basic + hra + da;
}
void display() {
displayDetails();
cout <<"\nEmployee Basic pay:"<<basic;
cout <<"\nEmployee Humen Resource Allowance:"<<hra;
cout <<"\nEmployee Dearness Allowance:"<<da;
cout <<"\nEmployee Net Pay:"<<netPayout<<endl;
}
};
int main() {
int i, n;
char ch;
Salary s[10];
cout << "Number of available person:";
cin>>n;
for (i = 0; i < n; i++) {
cout << "\nPerson Details # "<<(i+1)<<" : ";
s[i].getPayDetails();
s[i].calculate();
}
for (i = 0; i < n; i++) {
s[i].display();
}
return 0;
}
Comments
Leave a comment