-
Notifications
You must be signed in to change notification settings - Fork 0
/
26.cpp
112 lines (92 loc) · 2.08 KB
/
26.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
#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 :: 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;
int iN, iD;
iN = (iNum * b.iDen + iDen * b.iNum);
iD = (iDen * b.iDen);
// res.fnShowFraction();
// return res;
FractionType f(iN, iD);
return f;
}
int main(void)
{
FractionType f1,f2(5,6),f3;//,f5;
// f1.fnShowFraction();
// f2.fnShowFraction();
// cout << "\nEnter the first fraction" << endl;
f1.fnSetFraction(3);
f2.fnSetFraction(1,4);
f1.fnShowFraction();
f2.fnShowFraction();
f3 = f1.fnAddFraction(f2);
f3.fnShowFraction();
// FractionType f4(f3);
// f4.fnShowFraction();
// FractionType f5=f4;
// f5.fnShowFraction();
// FractionType f4(2,5);
// f4.fnShowFraction();
return 0;
}