- #include
-
- using namespace std;
- class shape
- {
- protected:
- int c;
- int s;
- public:
- shape(){}
- shape(int c,int s):c(c),s(s)
- {
- cout<<"有参构造"<
- }
- ~shape()
- {
- cout<<"析构函数"<
- }
- void show()
- {
- cout<<"周长="<
" 面积="< - }
- };
- class circle:public shape
- {
- private:
- int ri;
- public:
- circle(){}
- circle(int r):ri(r)
- {
- c=2*3.14*ri;
- s=3.14*ri*ri;
- cout<<"有参构造"<
- }
- ~circle()
- {
- cout<<"析构函数"<
- }
- void display()
- {
- cout<<"circle::周长="<
" circle::面积="< - }
- };
- class rect:public circle
- {
- private:
- int len;
- int high;
- public:
- rect(){}
- rect(int l,int h):len(l),high(h)
- {
- c=2*(len+high);
- s=len*high;
- cout<<"有参构造"<
- }
- ~rect()
- {
- cout<<"析构函数"<
- }
- void display1()
- {
- cout<<"rect::周长="<
" rect::面积="< - }
- };
-
- int main()
- {
- shape s1(5,6);
- s1.show();
- circle s2(4);
- s2.display();
- rect s3(5,6);
- s3.display1();
- return 0;
- }

-
相关阅读:
Linux系统管理
业务出海,灵感乍现前要先「把手弄脏」
SpringBoot 统一功能处理
记一次缓存失效引发的惨案!
Redis 底层的数据结构
metrology
基于三维GIS开发的水电工程建设方案
C++之特殊函数成员
【JVM】JVM详解
浅谈进程与其创建方式
-
原文地址:https://blog.csdn.net/weixin_69452640/article/details/132838887