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