-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeclaring-function-out-of-class.cpp
69 lines (68 loc) · 1.47 KB
/
declaring-function-out-of-class.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 add ( relactional , relactional );
friend relactional min ( relactional , relactional );
friend relactional multi ( relactional , relactional );
friend relactional div ( relactional , relactional );
};
relactional add ( 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 min ( 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 multi ( relactional a , relactional b)
{
relactional z;
z.num = a.num*b.num;
z.den = a.den*b.den;
return z;
}
relactional div ( 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 = add(a,b);
c.output();
c = min(a,b);
c.output();
c = multi(a,b);
c.output();
c = div(a,b);
c.output();
}