-
Notifications
You must be signed in to change notification settings - Fork 1
/
friend-function.cpp
69 lines (68 loc) · 1.48 KB
/
friend-function.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<iostream>
using namespace std;
class relactional
{
int num,den;
public:
relactional(int x = 0,int y = 1)
{
num = x;
den = y;
}
void output()
{
cout << num << "/" << den << endl;
}
void input()
{
cout << "Pleas enter num and den :: ";
cin >> num >> den ;
}
relactional sort( relactional);
friend relactional operator + ( relactional , relactional );
friend relactional operator - ( relactional , relactional );
friend relactional operator * ( relactional , relactional );
friend relactional operator / ( relactional , relactional );
};
relactional operator + ( relactional a , relactional b)
{
relactional z;
z.num = a.num*b.den + b.num * a.den;
z.den = a.den*b.den;
return z;
}
relactional operator - ( relactional a , relactional b)
{
relactional z;
z.num = a.num*b.den - b.num * a.den;
z.den = a.den*b.den;
return z;
}
relactional operator * ( relactional a , relactional b)
{
relactional z;
z.num = a.num*b.num;
z.den = a.den*b.den;
return z;
}
relactional operator / ( relactional a , relactional b)
{
relactional z;
z.num = a.num * b.den;
z.den = b.num * a.den;
return z;
}
main()
{
relactional a(34,65),b(12,32),c;
a.output();
b.output();
c = 25+a;
c.output();
c = a-b;
c.output();
c = a*b;
c.output();
c = a/b;
c.output();
}