-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperatoroverloading.cpp
More file actions
156 lines (112 loc) · 2.12 KB
/
operatoroverloading.cpp
File metadata and controls
156 lines (112 loc) · 2.12 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
using namespace std;
class Point {
friend Point operator*(const Point&, int);
friend ostream& operator<<(ostream &, const Point& );
friend istream& operator>>(istream &, Point&);
friend Point operator--(Point &p);
friend Point operator--(Point &p, int i);
friend Point operator*(int, const Point&);
int x;
int y;
static int count;
public:
Point(int X = 0, int Y = 0)
:x(X), y(Y) {
count++;
}
~Point(){
count--;
}
void print() const {
cout << "(" << x << ", " << y << ")" << endl;
}
Point& setXY(int X, int Y) {
x = X;
y = Y;
return *this;
}
static void printCount() {
cout << "Count: " << count <<endl;
}
void printC() {
cout << "Count: " << count << endl;
}
Point operator-(const Point &p) {
Point tmp;
tmp.x = x - p.x;
tmp.y = y - p.y;
return tmp;
}
Point operator++() {
x++;
y++;
return *this;
}
Point operator++(int i) {
Point tmp = *this;
x++;
y++;
return tmp;
}
int operator[](int i) {
if (i == 1)
return x;
else if (i == 2)
return y;
else {
cout << "indeks hatali..." << endl;
return 0;
}
}
};
Point operator*(const Point& p, int i)
{
Point tmp;
tmp.x = p.x*i;
tmp.y = p.y*i;
return tmp;
}
Point operator*(int i,const Point& p)
{
Point tmp;
tmp.x = p.x*i;
tmp.y = p.y*i;
return tmp;
}
ostream& operator<<(ostream &out, const Point& p) {
out << "(" << p.x << "," << p.y << ")" << endl;
return out;
}
istream& operator>>(istream &in, Point& p) {
in >> p.x >> p.y;
return in;
}
Point operator--(Point &p) {
p.x--;
p.y--;
return p;
}
Point operator--(Point &p,int i) {
Point tmp = p;
p.x--;
p.y--;
return tmp;
}
int Point::count = 0;
int main() {
Point p1(3, 5), p2(1, 2), p3;
p2 = (++p1);
p3 = (p1++);
p2 = (--p1);
p3 = (p1--);
cin >> p1;
cout << p1;
p3 = p1 - p2;
p3 = p1 * 5;
p3 = 5 * p1;
cout << "p1[1]= (x)"<<p1[1] << endl;
cout << "p1[2]= (y)" << p1[2] << endl;
cout << "p1[3]= (hatali)" << p1[3] << endl;
return 0;
}