-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPRA_21
53 lines (49 loc) · 997 Bytes
/
PRA_21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* A program to overload binary operators using friend function */
#include<iostream>
using namespace std;
class Inr
{
float rs;
public:
void avail()
{
cout << "Enter available money :";
cin >> rs;
}
void price()
{
cout << "Enter Item Price : ";
cin >> rs;
}
void remain()
{
cout <<endl<< "You have only " << rs<<" INR"<<endl;
}
friend Inr operator-(Inr &,Inr &);//declaring friend function
};
Inr operator-(Inr &a,Inr &b) // defining friend function to overload binary operator
{
Inr c;
c.rs = a.rs - b.rs; // calculating remaining money
return c;
}
int main()
{
Inr avai,i_1,rema;
cout << "\tREMAINING MONEY"<<endl<<endl;
avai.avail();
i_1.price();
rema=avai-i_1;// overloading binary operator
rema.remain();
return 0;
}
/*
Output:
REMAINING MONEY
Enter available money :5555
Enter Item Price : 1224
You have only 4331 INR
--------------------------------
Process exited after 10.24 seconds with return value 0
Press any key to continue . . .
*/