题解 | #KiKi设计类继承#

KiKi设计类继承

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

#include <iostream>
using namespace std;

class shape
{
    int x,y;
};

class Rectangle:public shape
{
    int length,width;
    public:
    Rectangle(int l, int w);
    void GetArea();
};

class Circle:public shape
{
    int radius;
    public:
    Circle(int r);
    void GetArea();
};

class Square:public Rectangle
{
    public:
    Square(int a);
};

Rectangle::Rectangle(int l,int w):length(l),width(w){}
void Rectangle::GetArea()
{
    cout<<length*width<<endl;
}

Circle::Circle(int r)
{
    radius=r;   
}
void Circle::GetArea()
{
    cout<<radius*radius*3.14<<endl;
}
Square::Square(int a):Rectangle(a,a){}

int main()
{
    int l,w,r,a;
    cin>>l>>w>>r>>a;
    Rectangle chang(l,w);
    Circle yuan(r);
    Square fang(a);
    chang.GetArea();
    yuan.GetArea();
    fang.GetArea();
    return 0;
}


全部评论

相关推荐

coffrar:全都是已读😅沟通一千五百多个了
点赞 评论 收藏
分享
Lyxiho:浙江大学 加大加粗
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客企业服务