题解 | #KiKi设计类继承#

KiKi设计类继承

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

#include <iostream>
using namespace std;
class shape{
    protected:
    double x,y;
    public:
    shape(double x,double y):x(x),y(y){}
    virtual double GetArea(){
        return 0.0;
    }
};
class Rectangle:public shape{
    protected:
        double len,wid;
    public:
        Rectangle(double x,double y,double len,double wid):shape(x,y),len(len),wid(wid){}
        double GetArea() override{
            return len*wid;
        }
};
class circle:public shape{
    private:
    double redius;
    public:
    circle(double x,double y,double redius):shape(x,y),redius(redius){}
    double GetArea() override{
        return 3.14*redius*redius;
    }
};
class squre:public Rectangle{
    protected:
        double side;
        public:
        squre(double x,double y,double side):Rectangle( x, y,  side, side){}


};
int main() {
    double len,wid,redius,side;
    cin>>len>>wid;
    cin>>redius;
    cin>>side;
    Rectangle a(0,0,len,wid);
    circle b(0,0,redius);
    squre c(0,0,side);
    cout<<a.GetArea()<<endl;
    cout<<b.GetArea()<<endl;
    cout<<c.GetArea()<<endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

11-08 16:53
门头沟学院 C++
投票
滑模小马达:第三个如果是qfqc感觉还行,我签的qfkj搞电机的,违约金也很高,但公司感觉还可以,听说之前开过一个试用转正的应届生,仅供参考。
点赞 评论 收藏
分享
10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务