Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // friend func.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- class abc;
- class xyz
- {
- int a;
- public:
- void enter()
- {
- cout<<"enter the value";
- cin>>a;
- }
- friend void swap(abc, xyz);
- };
- class abc
- {
- int a;
- public:
- void enter()
- {
- cout<<"enter the value";
- cin>>a;
- }
- friend void swap(abc, xyz);
- };
- void swap(abc ab, xyz xy)
- {
- cout<<"\nabc contains"<<ab.a;
- cout<<"\nxyz contains"<<xy.a;
- int temp;
- temp=ab.a;
- ab.a=xy.a;
- xy.a=temp;
- cout<<"\n\nafter swapping\n";
- cout<<"\nabc contains"<<ab.a;
- cout<<"\nxyz contains"<<xy.a<<endl;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- abc a;
- xyz x;
- a.enter();
- x.enter();
- swap(a,x);
- system("pause");
- return 0;
- }
- /*
- enter the value8
- enter the value9
- abc contains8
- xyz contains9
- after swapping
- abc contains9
- xyz contains8
- Press any key to continue . . .
- */
- //fourth program
- // friend func.cpp : Defines the entry point for the console application.
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- class professor;
- class bank
- {
- double monthly;
- char gender;
- public:
- void enter()
- {
- cout<<"enter the gender for bank class";
- cin>>gender;
- cout<<"Enter monthly salary";
- cin>>monthly;
- }
- friend void calc(bank, professor);
- };
- class professor
- {
- double monthly;
- char gender;
- public:
- void enter()
- {
- cout<<"\nenter the gender for bank class";
- cin>>gender;
- cout<<"Enter monthly salary";
- cin>>monthly;
- }
- friend void calc(bank, professor);
- };
- void calc(bank b, professor p)
- {
- double gross_bank=b.monthly*12;
- double gross_prof=p.monthly*12;
- double net_b, net_p;
- //handle bank class
- if(b.gender=='f' || b.gender=='F')
- {
- net_b=gross_bank-190000;
- }
- else
- {
- net_b=gross_bank-180000;
- }
- if(net_b>1000000)
- cout<<"\nIncome tax for bank class is "<<net_b*0.3;
- else if(net_b>500000)
- cout<<"\nIncome tax for bank class is "<<net_b*0.2;
- else if(net_b>300000)
- cout<<"\nIncome tax for bank class is "<<net_b*0.1;
- else
- cout<<"\nfor bank class, NO tax ";
- //handle prof class
- if(p.gender=='f' || p.gender=='F')
- {
- net_p=gross_prof-190000;
- }
- else
- {
- net_p=gross_prof-180000;
- }
- if(b.gender=='f' || b.gender=='F')
- {
- net_b=gross_bank-190000;
- }
- else
- {
- net_b=gross_bank-180000;
- }
- if(net_p>1000000)
- cout<<"\nIncome tax for professor class is "<<net_p*0.3;
- else if(net_p>500000)
- cout<<"\nIncome tax for professor class is "<<net_p*0.2;
- else if(net_p>300000)
- cout<<"\nIncome tax for professor class is "<<net_p*0.1;
- else
- cout<<"For professor class: no tax";
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- bank a;
- professor x;
- a.enter();
- x.enter();
- calc(a,x);
- system("pause");
- return 0;
- }
- /*
- enter the gender for bank class f
- Enter monthly salary40000
- enter the gender for bank class m
- Enter monthly salary60000
- for bank class, NO tax
- Income tax for professor class is 108000
- Press any key to continue . . .
- */
- // friend func.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- class abc;
- class xyz
- {
- int a;
- public:
- void enter()
- {
- cout<<"enter the value";
- cin>>a;
- }
- friend void average(abc, xyz);
- };
- class abc
- {
- int a;
- public:
- void enter()
- {
- cout<<"enter the value";
- cin>>a;
- }
- friend void average(abc, xyz);
- };
- void average(abc ab, xyz xy)
- {
- float c;
- c=(ab.a+xy.a)/2.0;
- cout<<"Average is"<<c;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- abc a;
- xyz x;
- a.enter();
- x.enter();
- average(a,x);
- system("pause");
- return 0;
- }
- /*
- enter the value4
- enter the value5
- Average is4.5Press any key to continue . . .
- */
- program to find greatest of 2 nos using friend functions
- program to find average of 2 nos using friend functions
- program to swap 2 nos using friend functions
- // friend func.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- using namespace std;
- class abc;
- class xyz
- {
- int a;
- public:
- void enter()
- {
- cout<<"enter the value";
- cin>>a;
- }
- friend void greatest(abc, xyz);
- };
- class abc
- {
- int a;
- public:
- void enter()
- {
- cout<<"enter the value";
- cin>>a;
- }
- friend void greatest(abc, xyz);
- };
- void greatest(abc ab, xyz xy)
- {
- if (ab.a>xy.a)
- cout<<"greatest is "<< ab.a;
- else if (ab.a<xy.a)
- cout<<"greatest is "<< xy.a;
- else
- cout<<"both equal";
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- abc a;
- xyz x;
- a.enter();
- x.enter();
- greatest(a,x);
- system("pause");
- return 0;
- }
- /*
- enter the value5
- enter the value10
- greatest is 10Press any key to continue . . .
- */
Advertisement
Add Comment
Please, Sign In to add comment