-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberObject.cpp
More file actions
107 lines (91 loc) · 2.03 KB
/
NumberObject.cpp
File metadata and controls
107 lines (91 loc) · 2.03 KB
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
#include "NumberObject.h"
void Integer::operator=(BigInt& rhs)
{
setType(0);
setDigits(rhs.getDigits());
setSign(rhs.getSign());
setDotPlace(rhs.getDotPlace());
checkType();
}
ostream& operator<<(ostream& strm, Integer& rhs)
{
rhs.checkType();
if (rhs.getSign() == 1)
strm << "-";
strm << rhs.getDigits();
return strm;
}
istream& operator>>(istream& strm, Integer& rhs)
{
string to_process;
getline(strm, to_process);
rhs.setDigits(to_process);
rhs.setSign(0);
rhs.setType(1);
rhs.setDotPlace(string::npos);
return strm;
/*
string i;
strm >> i;
if (i[0] == '-') {
i.erase(0, 1);
rhs.setSign(1);
}
else
rhs.setSign(0);
int dotPt = i.find('.');
if (dotPt != string::npos)
{
i.erase(dotPt);
}
rhs.setType(0);
rhs.setDotPlace(string::npos);
rhs.setDigits(i);
rhs.checkType();
return strm;
*/
}
void Decimal::operator=(BigInt& rhs)
{
setType(1);
setDigits(rhs.getDigits());
setSign(rhs.getSign());
setDotPlace(rhs.getDotPlace());
checkType();
}
void Decimal::operator=(const char* rhs)
{
setType(1);
setDigits(string(rhs));
}
void Integer::operator=(const char* rhs)
{
setType(0);
setDigits(string(rhs));
}
ostream& operator<<(ostream& strm, Decimal& rhs)
{
rhs.checkType();
if (rhs.getSign() == 1)
strm << "-";
strm << rhs.getDigits();
return strm;
}
istream& operator>>(istream& strm, Decimal& rhs)
{
string to_process;
getline(strm, to_process);
rhs.setDigits(to_process);
rhs.setSign(0);
rhs.setType(1);
rhs.setDotPlace(string::npos);
return strm;
}
BigInt operator+(const Integer i, const Decimal d) { return i + d; }
BigInt operator-(const Integer i, const Decimal d) { return i - d; }
BigInt operator+(const Decimal d, const Integer i) { return d + i; }
BigInt operator-(const Decimal d, const Integer i) { return d - i; }
BigInt operator*(const Integer i, const Decimal d) { return i * d; }
BigInt operator/(const Integer i, const Decimal d) { return i / d; }
BigInt operator*(const Decimal d, const Integer i) { return d * i; }
BigInt operator/(const Decimal d, const Integer i) { return d / i; }