题解 | KiKi设计类继承

KiKi设计类继承

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

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

class shape
{
    private:
    int x = 0;
    int y = 0;
    
};

class Rectangle:public shape
{
    public: 
    int length;
    int wide;
    void GetArea(int s,int t);

};
void Rectangle::GetArea(int s, int t)
{
   cout<<s*t<<endl ;
}

class Circle:public shape
{
    public:
    int r;
    void GetArea(int r);
    
};
void Circle::GetArea(int r)
{
    cout<<3.14*r*r<<endl;
}
class Square : public Rectangle {
public:
    // 重写 GetArea,只需要一个参数
    void GetArea(int s) {
        cout<< s * s;
    }
};


int main() 
{
    int a,b,c,d;
    Rectangle s1;
    Circle    s3;
    Square    s2;
    cin>>a>>b;
    s1.GetArea(a, b);

    cin>>c;
    s3.GetArea(c);

    cin>>d;
    s2.GetArea(d);

}












全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:24
大家还是用ai改吧,我心疼得要死,就当花钱买教训吧,人家直接拿完钱就跑路了
程序员小白条:简历修改700....神奇,又不是帮你面试,咋的,简历修改从双非变92了还是没实习变成有大厂实习了
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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