-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuple.cpp
More file actions
64 lines (54 loc) · 1.15 KB
/
tuple.cpp
File metadata and controls
64 lines (54 loc) · 1.15 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
#include <iostream>
class Pair
{
protected:
int first;
int second;
public:
Pair(int t, int u) : first(t), second(u) {}
bool operator==(const Pair &rhs) const
{
return first == rhs.first && second == rhs.second;
}
friend std::ostream &operator<<(std::ostream &os, const Pair &rhs)
{
os << "(" << rhs.first << ", " << rhs.second << ")";
return os;
}
//TODO: Implement the operator here
void operator=(const Pair &rhs)
{
first = rhs.first;
second = rhs.second;
}
};
class Triple : public Pair
{
protected:
int third;
public:
Triple(int t, int u, int v) : Pair(t, u), third(v) {}
friend std::ostream &operator<<(std::ostream &os, const Triple &rhs)
{
os << "(" << rhs.first << ", " << rhs.second << ", " << rhs.third << ")";
return os;
}
void operator=(const Triple &rhs)
{
first = rhs.first;
second = rhs.second;
third = rhs.third;
}
};
int main()
{
// show a quick demo of class
Pair p(1, 2);
Pair p1(1, 2);
std::cout << p << std::endl;
std::cout << p1 << std::endl;
Triple t1(1, 2, 3);
Triple t2(1, 3, 3);
std::cout << t1 << std::endl;
std::cout << t2 << std::endl;
}