-
Notifications
You must be signed in to change notification settings - Fork 0
/
25.cpp
127 lines (104 loc) · 2.43 KB
/
25.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <cmath>
using namespace std;
class FractionType
{
private:
int iNum, iDen;
public:
// FractionType();
// ~FractionType();
// FractionType(int,int);
// FractionType(int);
// FractionType(FractionType&);
void fnSetFraction(int, int);
void fnSetFraction(int);
void fnShowFraction();
void fnReduceFraction();
FractionType fnAddFraction(FractionType&);
FractionType fnAddFraction(int);
};
int main(void)
{
FractionType f1,f2,f3;
f1.fnShowFraction();
f2.fnShowFraction();
// cout << "\nEnter the first fraction" << endl;
f1.fnSetFraction(1,4);
f2.fnSetFraction(1,4);
f1.fnShowFraction();
f2.fnShowFraction();
f3 = f1.fnAddFraction(f2);
f3.fnShowFraction();
f3 = f1.fnAddFraction(1);
f3.fnShowFraction();
// FractionType f4(f3);
// f4.fnShowFraction();
FractionType f4;
f4.fnShowFraction();
return 0;
}
//FractionType :: FractionType(FractionType &f)
//{
// cout << "\nCopy constructor\n";
// iNum = f.iNum;
// iDen = f.iDen;
//}
//FractionType :: FractionType()
//{
// cout << "\nZero parameter constructor\n";
// iNum = 0;
// iDen = 1;
//}
//FractionType :: ~FractionType()
//{
// cout << "\nDestructor invoked\n";
//}
//FractionType :: FractionType(int iVal1, int iVal2)
//{
// cout << "\nTwo parameter constructor\n";
// iNum = iVal1;
// iDen = iVal2;
//}
//FractionType :: FractionType(int iVal1)
//{
// cout << "\nOne parameter constructor\n";
// iNum = iVal1;
// iDen = 1;
//}
void FractionType :: fnSetFraction(int iN, int iD)
{
iNum = iN;
iDen = iD;
}
void FractionType :: fnSetFraction(int iN)
{
iNum = iN;
iDen = 1;
}
void FractionType :: fnShowFraction()
{
cout << "Fraction : " << "( " << iNum << " / " << iDen << " )" << endl;
}
FractionType FractionType :: fnAddFraction(FractionType &b)
{
FractionType res;
res.iNum = (iNum * b.iDen + iDen * b.iNum);
res.iDen = (iDen * b.iDen);
return res;
}
FractionType FractionType :: fnAddFraction(int b)
{
FractionType res;
res.iNum = (iNum + iDen * b);
res.iDen = (iDen);
return res;
}
//FractionType FractionType :: fnAddFraction(int b)
//{
// FractionType res;
// FractionType sec;
// sec.fnSetFraction(b);
// res = this->fnAddFraction(sec);
// return res;
//}