-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path17_coordinate.cpp
74 lines (61 loc) · 1.58 KB
/
17_coordinate.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
// // Create a Coordinate class for 3 variables x,y and z and overload comma operator such that when you write c3 = (c1 , c2 ) then c2 is assigned to c3. Where c1,c2 and c3 are objects of 3D coordinate class.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Coordinate
class Coordinate
{
private:
// // instance memeber variable
int x, y, z;
public:
// // constructors
Coordinate()
{
x = y = z = 0;
}
Coordinate(int x, int y, int z)
{
this->x = x;
this->y = y;
this->z = z;
}
// // instance memebr function to set coordinates
void setCoordinates(int x, int y, int z)
{
this->x = x;
this->y = y;
this->z = z;
}
// // instance memebr function to show coordinates
int showCoordinates()
{
cout << "\nx => " << x;
cout << "\ny => " << y;
cout << "\nz => " << z;
}
// overload comma (,) operator
Coordinate operator,(Coordinate p)
{
Coordinate temp;
temp.x = p.x;
temp.y = p.y;
temp.z = p.z;
return temp;
}
};
int main()
{
Coordinate c1(2, 4, 6), c2(4, 2, 135), c3; // create objects of Coordinate class
c3 = (c1, c2);
cout << "\n\n>>>>>>>>>>> Coordinates of c1 <<<<<<<<<<<";
c1.showCoordinates();
cout << "\n\n>>>>>>>>>>> Coordinates of c2 <<<<<<<<<<<";
c2.showCoordinates();
cout << "\n\n>>>>>>>>>>> Coordinates of c3 <<<<<<<<<<<";
c3.showCoordinates();
cout << endl; // Add new line
cin.ignore();
return 0;
}