-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog7.cpp
More file actions
39 lines (30 loc) · 726 Bytes
/
prog7.cpp
File metadata and controls
39 lines (30 loc) · 726 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
/*
Write a C++ program to demostrate the working od a copy constructor. Implement a
class ccalled Point with private data members x and y as the points and getX()
and getY() are the getter functions to get the values and print the same using
the main() function
*/
#include <iostream>
using namespace std;
class Point {
private:
int x, y;
public:
Point(int x, int y) {
this->x = x;
this->y = y;
}
Point(Point &p) {
x = p.x;
y = p.y;
}
int getX() { return x; }
int getY() { return y; }
};
int main() {
Point p1(10, 15);
Point p2 = p1;
cout << "p1.x: " << p1.getX() << "\np1.y: " << p1.getY() << endl;
cout << "p2.x: " << p2.getX() << "\np2.y: " << p2.getY() << endl;
return 0;
}