zoukankan      html  css  js  c++  java
  • 习题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;
    }

  • 相关阅读:
    团队冲刺第八天
    团队冲刺第七天
    团队冲刺第六天
    团队冲刺第五天
    找水王
    团队冲刺第四天
    团队冲刺第三天
    团队冲刺第二天
    团队冲刺第一天
    spring冲刺计划
  • 原文地址:https://www.cnblogs.com/orangebook/p/3409801.html
Copyright © 2011-2022 走看看