题解 | #KiKi设计类继承#

KiKi设计类继承

http://www.nowcoder.com/practice/699ba050e2704591ae3e62401a856b0e

运行速率极快

using namespace std;
#define pi 3.14
class shape{
public:
private:
    double x;
    double y;
};
class Rectangle:public shape
{
public:
    double len,wid;
    void GetArea(double len,double wid){
         cout<<len*wid<<endl;
    }
};
class Circle:public shape
{
public:
    double r;
    void GetArea(double r){
        cout<<r*r*pi<<endl;
    }
};
class Square:public Rectangle
{
public:
    double s_len;
};
void test(){
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    Rectangle r;
    Square s;
    Circle e;
    r.GetArea(a, b);
    e.GetArea(c);
    s.GetArea(d, d);
}
int main(){
    test();
    return 0;
}







全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务