习题7-5

#include<iostream>
using namespace std;
class Shape
{
public:void getArea(){cout<<"this is Shape class"<<endl;}
};
class Rectangle:public Shape
{
private:double x,y;
public:
    void putbox(const int newx,const int newy){x=newx;y=newy; cout<<"x,y="<<x<<","<<y<<endl;}
    double getArea(){cout<<"x*y="<<x*y<<endl; return x*y;}
};
class Circle:public Shape
{
private:double r;
public:
    void putbox(const int newr){r=newr;}
    double getArea(){return 3.14*r*r;}
};
class Square:protected Rectangle
{
public:
    void putbox(const int newx){Rectangle::putbox(newx,newx);}
    double getArea(){double area=Rectangle::getArea();return area;}
};

int main()
{
    Square test1;
    test1.putbox(2.0);
    double t=test1.getArea();
    cout<<t<<endl;
}

posted @ 2013-11-20 19:45  退之  阅读(157)  评论(0编辑  收藏  举报