-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch8 3~4번문제.cpp
41 lines (37 loc) · 1009 Bytes
/
ch8 3~4번문제.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
#include <iostream>
#include <string>
using namespace std;
class Point {
int x, y;
public:
Point() { this->x = 0; this->y = 0; }
Point(int x, int y) { this->x = x; this->y = y; }
int getX() { return x; }
int getY() { return y; }
protected:
void move(int x, int y) { this->x = x; this->y = y; }
};
class ColorPoint : public Point {
string name;
public:
ColorPoint() : Point() { name = "Black"; }
ColorPoint(int x, int y) : Point(x, y) { name = ""; }
ColorPoint(int x, int y, string name) : Point(x, y) { this->name = name; }
void setPoint(int x, int y) { move(x, y); }
void setColor(string name) { this->name = name; }
void show() { cout << name << "색으로 " << "(" << getX() << ',' << getY() << ")에 위치한 점입니다. "<< endl; }
};
int main()
{ /*1번문제
ColorPoint cp(5, 5, "Red");
cp.setPoint(10, 20);
cp.setColor("Blue");
cp.show();
1번문제*/
ColorPoint zeroPoint;
zeroPoint.show();
ColorPoint cp(5, 5);
cp.setPoint(10, 20);
cp.setColor("Blue");
cp.show();
}