|
| 1 | +#include<iostream> |
| 2 | +using namespace std; |
| 3 | +class employee |
| 4 | +{ |
| 5 | + char name[30]; |
| 6 | + int id; |
| 7 | + char dept[15]; |
| 8 | + float base_salary; |
| 9 | + float DA; |
| 10 | + float HRA; |
| 11 | + float TA; |
| 12 | + |
| 13 | +public: |
| 14 | + employee(); |
| 15 | + employee(employee &obj); |
| 16 | + employee(char[],int,char[],int,float,float,float); |
| 17 | + |
| 18 | +}; |
| 19 | +// Using Default Constructor Logic. |
| 20 | +employee::employee() |
| 21 | +{ |
| 22 | + cout<<"Enter Name:"<<endl; |
| 23 | + cin>>name; |
| 24 | + cout<<"Enter ID:"<<endl; |
| 25 | + cin>>id; |
| 26 | + cout<<"Enter Dept:"<<endl; |
| 27 | + cin>>dept; |
| 28 | + cout<<"Enter Base Salary:"<<endl; |
| 29 | + cin>>base_salary; |
| 30 | + int total; |
| 31 | + DA=0.5*base_salary; |
| 32 | + cout<<"Employee Dearness Allowance is:"<<DA<<endl; |
| 33 | + HRA=0.3*base_salary; |
| 34 | + cout<<"Employee HRA is:"<<HRA<<endl; |
| 35 | + TA=0.1*base_salary; |
| 36 | + cout<<"Employee TA is:"<<endl; |
| 37 | + cout<<"The Total Gross Employee salary is:"<<TA<<endl; |
| 38 | + total=DA+HRA+TA; |
| 39 | + cout<<total<<endl;; |
| 40 | + |
| 41 | +} |
| 42 | +employee::employee(employee &obj) |
| 43 | +{ |
| 44 | + cout<<"Enter Name:"<<endl; |
| 45 | + cin>>name; |
| 46 | + cout<<"Enter ID:"<<endl; |
| 47 | + cin>>id; |
| 48 | + cout<<"Enter Dept:"<<endl; |
| 49 | + cin>>dept; |
| 50 | + cout<<"Enter Base Salary:"<<endl; |
| 51 | + cin>>base_salary; |
| 52 | + int total; |
| 53 | + obj.DA=0.5*obj.base_salary; |
| 54 | + cout<<"Employee Dearness Allowance is:"<<obj.DA<<endl; |
| 55 | + obj.HRA=0.3*obj.base_salary; |
| 56 | + cout<<"Employee HRA is:"<<obj.HRA<<endl; |
| 57 | + obj.TA=0.1*obj.base_salary; |
| 58 | + cout<<"Employee TA is:"<<endl; |
| 59 | + cout<<"The Total Gross Employee salary is:"<<obj.TA<<endl; |
| 60 | + total=obj.DA+obj.HRA+obj.TA; |
| 61 | + cout<<total<<endl; |
| 62 | + |
| 63 | +} |
| 64 | + |
| 65 | +int main() |
| 66 | +{ |
| 67 | + employee e; |
| 68 | + employee e1(e); |
| 69 | + cout<<"--------------------"<<endl; |
| 70 | + employee e2; |
| 71 | + employee e3(e); |
| 72 | + employee e4=e1;//Use of Copy Constructor. |
| 73 | + |
| 74 | + |
| 75 | +} |
0 commit comments