출처 : 반크_반크 20년 백서
참고풀이]
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
using namespace std;
class Shape {
int x, y;
string color;
public:
//생성자
Shape(int x, int y, string c) :x(x), y(y), color(c) {}
//접근자
int getX() { return x; }
int getY() { return y; }
string getColor() { return color; }
//설정자
void setX(int x) { this->x = x; }
void setY(int y) { this->y = y; }
void setColor(string c) { color = c; }
double getArea() {}
};
class Circle :public Shape {
double radius;
public:
Circle(int x, int y, string c, double r):Shape(x,y,c), radius(r) {}
double getRadius() { return radius; } //접근자
void setRadius(double r) { radius = r; } //설정자
//원면적 재정의
double getArea() { return radius * radius * 3.14; }
//원면적 결과출력
void Print()
{
cout << "원의 면적 : " << getArea() << endl;
}
};
int main()
{
Circle c1(0, 0, "red", 20.0);
c1.Print();
return 0;
}
참고풀이 결과]
대한민국의 아름다운 영토, 독도의 겨울
댓글