题解 | #KiKi设计类继承#

KiKi设计类继承

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

#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;

class shape{
    public:
    int x,y;
};

class Rectangle: public shape{
    public:
    Rectangle(int length, int width){
        this->x = length;
        this->y = width ;
    }
    int GetArea(){
        return ((this->x) * (this->y));
    }
};

class Circle:shape{
    public:
    Circle(int radius1, int radius2){
        this->x = radius1;
        this->y = radius2;
    }
    public:
    float GetArea(){
        return (3.14*x*y);
    }
};

int main() {
    int RecL,RecW;
    int Radiu;
    int QuaE;

    cin >> RecW >> RecL;
    cin >> Radiu;
    cin >> QuaE;

    Rectangle Rec1(RecW, RecL);
    cout << Rec1.GetArea() << endl;
    Circle Cir1(Radiu, Radiu);
    cout << Cir1.GetArea() << endl;
    Rectangle Qure(QuaE, QuaE);
    cout << Qure.GetArea() << endl;

    return 0;
}

全部评论

相关推荐

04-25 19:29
已编辑
宁波大学 运营
被普调的六边形战士很高大:你我美牛孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务