본문 바로가기

언어/C++

점 상속 받은 불꽃놀이 !

#include <iostream>
#include <string>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class Point {
	int x;
	int y;
public:
	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(int x=0, int y=0, string name="BLACK") : 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(int argc, char** argv) {
	
	ColorPoint zeroPoint;
	zeroPoint.show();

	ColorPoint cp(5,5);
	cp.setPoint(10,20);
	cp.setColor("BLUE");
	cp.show();
	
	return 0;
}
#include <iostream>
#include <string>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class Point {
	int x;
	int y;
public:
	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(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(int argc, char** argv) {
	
	ColorPoint cp(5,5,"RED");
	cp.setPoint(10,20);
	cp.setColor("BLUE");
	cp.show();
	
	return 0;
}