-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint.cpp
More file actions
50 lines (38 loc) · 830 Bytes
/
int.cpp
File metadata and controls
50 lines (38 loc) · 830 Bytes
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
#include <iostream>
class Int {
public:
int m_n;
Int() {
m_n = 0;
}
Int(int n) {
m_n = n;
}
float operator/(const Int & rhs) {
return (float) m_n / rhs.m_n;
}
Int operator&(const Int & rhs) {
return m_n / rhs.m_n;
}
Int operator*(const Int & rhs) {
return m_n * rhs.m_n;
}
Int operator+(const Int & rhs) {
return m_n + rhs.m_n;
}
Int operator-(const Int & rhs) {
return m_n - rhs.m_n;
}
};
std::ostream & operator<<(std::ostream & o, Int const & rhs) {
o << rhs.m_n;
return o;
}
int main(void) {
Int n = 1;
Int n2 = 2;
std::cout << n << " / " << n2 << ": " << n / n2 << "\n";
std::cout << n << " * " << n2 << ": " << n * n2 << "\n";
std::cout << n << " + " << n2 << ": " << n + n2 << "\n";
std::cout << n << " - " << n2 << ": " << n - n2 << "\n";
}