题解 | 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);

}












全部评论

相关推荐

想按时下班的大菠萝在...:隔壁学校的,加油多投, 实在不好找可以下个学期开学找,把算法八股准备好,项目有空再换换
投了多少份简历才上岸
点赞 评论 收藏
分享
码农索隆:卡学历都不行了,开始卡颜值了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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