-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab5.cpp
78 lines (62 loc) · 2.12 KB
/
Lab5.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
75
76
77
78
#include <iostream>
using namespace std;
class point {
int x_coordinate;
int y_coordinate;
public:
point();
point(int, int);
void setx(int x) { x_coordinate = x; }
void sety(int y) { y_coordinate = y; }
int getx() { return x_coordinate; }
int gety() { return y_coordinate; }
void printcoordinates();
};
class rectangle {
point bottomleft;
point bottomright;
point topleft;
point topright;
public:
rectangle();
rectangle(point, point);
void printrect();
};
// Default constructor for the class 'rectangle'
rectangle::rectangle() : bottomright(0, 1), topleft(1, 0), topright(1, 1) {}
// Parameterized constructor for the class 'rectangle'
rectangle::rectangle(point A, point B) : bottomleft(A.getx(), A.gety()), bottomright(B.getx(), A.gety()), topleft(A.getx(), B.gety()), topright(B.getx(), B.gety()) {}
// Print the coordinates of the point
void point::printcoordinates() {
cout << x_coordinate << "," << y_coordinate << endl;
}
// Default constructor for the class 'point'
point::point() {
x_coordinate = 0;
y_coordinate = 0;
}
// Parameterized constructor for the class 'point'
point::point(int a, int b) {
x_coordinate = a;
y_coordinate = b;
}
// Print the coordinates of the rectangle
void rectangle::printrect() {
bottomleft.printcoordinates();
bottomright.printcoordinates();
topleft.printcoordinates();
topright.printcoordinates();
}
int main() {
point A; // Create a point object with default constructor
point B(2, 4); // Create a point object with parameterized constructor
A.printcoordinates(); // Print coordinates of point A
B.printcoordinates(); // Print coordinates of point B
B.sety(5); // Set the y-coordinate of point B to 5
B.printcoordinates(); // Print updated coordinates of point B
rectangle kare; // Create a rectangle object with default constructor
kare.printrect(); // Print coordinates of the rectangle kare
rectangle dikdortgen(A, B); // Create a rectangle object with parameterized constructor
dikdortgen.printrect(); // Print coordinates of the rectangle dikdortgen
return 0;
}