题解 | #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;
}


全部评论

相关推荐

02-22 18:38
门头沟学院 Java
程序员牛肉:标准的NPC简历,一个短链接+12306。你可以在牛客上面搜一搜有多少人的简历和你一样。你自己能不能给出你一个理由让面试官在大家简历高度相同的情况下,选择约面你而不是对应的211,985学生? 是因为你即将拥有的那段小厂实习吗?这种小厂实习真的很有含金量吗?因此你可以找实习,但是你如果只能找到小厂实习的话,其实意义不太大。 但你的时间是充足的,相信我:从现在到今年的九月份大三上你就干两个事情:"写博客"+“参加开源之夏”。这两个搞好了不亚于一段大厂实习的含金量。 想要让自己变得更强,首先就是不要把自己当打工人看待,让自己简历上面的活人气息更多一点,不要让自己成为流水线的产物。你不是在出售你的技能,你是在利用你的技能和公司达成一种合作关系。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客企业服务