출처 : 반크_반크 20년 백서
참고풀이]
#include <iostream>
using namespace std;
class HomeAppliance
{
int price;
public:
HomeAppliance(double p) :price(p) {}
double getprice() { return price; }
virtual double getPrice() = 0;
virtual void Print() = 0;
};
class Television :public HomeAppliance
{
double sale;
public:
Television(double p) :HomeAppliance(p) { sale = 0.9; }
double getPrice() { return getprice() * sale; }
void Print() { cout << "가격 : " << getPrice() << endl; }
};
class Refrigerator :public HomeAppliance
{
double sale = 0.95;
public:
Refrigerator(double p) : HomeAppliance(p) {}
double getPrice() { return getprice() * sale; }
void Print() { cout << "가격 : " << getPrice() << endl; }
};
int main()
{
int i;
HomeAppliance* home[3] = { NULL };
home[0] = new Television(100000);
home[1] = new Refrigerator(200000);
home[2] = new Television(300000);
for (i = 0;i < 3;i++)
home[i]->Print();
for (i = 0;i < 3;i++)
{
delete home[i];
home[i] = NULL;
}
return 0;
}
참고풀이 결과]
대한민국의 아름다운 영토, 독도의 겨울
댓글