Sunday, January 1, 2012

Calculate income tax for each of given calss(doctor,scientist,teacher) object by use of friend function concept. in 'C++'

Example



#include<iostream.h>
#include<conio.h>
#include<math.h>
class doctor;
class scientist;
class teacher
{


float hra,bs,da,c;
public:
    // friend void getdata(teacher t,doctor d,scientist s);
void getdata()
{
cout<<">>>>>ENTER TEACHER SALARY DETAILS"<<endl;
cout<<"------------------------------------"<<endl;
cout<<"Enter house rent allowance:";
cin>>hra;
cout<<"Enter basic salary:";
cin>>bs;
cout<<"Enter dearness allowance:";
cin>>da;
}
friend void calculate(teacher t,doctor d,scientist s);


};
class doctor
{


float hra,bs,da,c;
public:
  // friend void getdata(teacher t,doctor d,scientist s);
void getdata()
{
cout<<">>>>ENTER DOCTOR SALARY DETAILS"<<endl;
cout<<"------------------------------------"<<endl;
cout<<"Enter house rent allowance:";
cin>>hra;
cout<<"Enter basic salary:";
cin>>bs;
cout<<"Enter dearness allowance:";
cin>>da;
}
friend void calculate(teacher t,doctor d,scientist s);


};
class scientist
{


float hra,bs,da,c;


public:
// friend void getdata(teacher t,doctor d,scientist s);
void getdata()
{
cout<<">>>>ENTER SCIENTIST SALARY DETAILS"<<endl;
cout<<"------------------------------------"<<endl;
cout<<"Enter house rent allowance:";
cin>>hra;
cout<<"Enter basic salary:";
cin>>bs;
cout<<"Enter dearness allowance:";
cin>>da;
}
friend void calculate(teacher t,doctor d,scientist s);


};
void calculate(teacher t,doctor d,scientist s)
{
t.c=(t.hra+t.bs+t.da)*0.12;
cout<<"------------------------------------"<<endl;
cout<<"TEACHER TOTAL INCOME TAX IS::"<<t.c<<endl;
d.c=(d.hra+d.bs+d.da)*0.11;
cout<<"DOCTOR TOTAL INCOME TAX IS::"<<d.c<<endl;
s.c=(s.hra+s.bs+s.da)*0.10;
cout<<"SCIENTIST TOTAL INCOME TAX IS::"<<s.c<<endl;
}


int main()
{
teacher t;
doctor d;
scientist s;
clrscr();
t.getdata();
d.getdata();
s.getdata();
       calculate(t,d,s);
getch();
return 0;
}
/*===================================================
OUTPUT
>>>>>ENTER TEACHER SALARY DETAILS
------------------------------------
Enter house rent allowance:1200
Enter basic salary:3340
Enter dearness allowance:200
>>>>ENTER DOCTOR SALARY DETAILS
------------------------------------
Enter house rent allowance:2390
Enter basic salary:5000
Enter dearness allowance:222
>>>>ENTER SCIENTIST SALARY DETAILS
------------------------------------
Enter house rent allowance:5690
Enter basic salary:7000
Enter dearness allowance:2345
------------------------------------
TEACHER TOTAL INCOME TAX IS::568.799988
DOCTOR TOTAL INCOME TAX IS::837.320007
SCIENTIST TOTAL INCOME TAX IS::1503.5
*/

No comments:

Post a Comment