每个 case 语句的结尾不要忘了加 break,否则将导致多个分支重叠

每个 case 语句的结尾不要忘了加 break,否则将导致多个分支重叠 (除非有意使多个分支重叠)。

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 //定义一个枚举类型
 6 enum Color {Red,Yellow,Green,White};
 7 //圆类Circle的定义
 8 class Circle {  
 9     float radius;
10 public:
11     Circle(float r) {
12         radius=r;
13         cout<<"Circle initialized!"<<endl;
14     }
15     ~Circle() {  //析构函数
16           cout<<"Circle  destroyed!"<<endl;
17     }
18     float Area() {
19         return 3.1416*radius*radius;
20     }
21 };
22 //桌子类Table的定义
23 class Table {  
24     float height;
25 public:
26     Table(float h) {
27         height=h;
28         cout<<"Table initialized!"<<endl;
29     }
30     ~Table() {  //构造函数
31         cout<<"Table destroyed!"<<endl;
32     }
33     float Height() {
34         return height;
35     }
36 };
37 //圆桌类RoundTable的定义
38 class RoundTable:public Table,public Circle {
39     Color color;
40 public:
41     RoundTable(float h,float r,Color c); //构造函数
42     int GetColor() {
43        return color;
44     }
45     ~RoundTable() {  //构造函数
46         cout<<"RoundTable destroyed!"<<endl;
47     }
48 };
49 //圆桌构造函数的定义
50 RoundTable::RoundTable(float h,float r,Color c):Table(h),Circle(r)
51 {
52     color=c;
53     cout<<"RoundTable initialized!"<<endl;
54 }
55 //测试多继承中构造函数和析构函数的执行方式
56 
57 int main(int argc, char** argv) {
58     
59         RoundTable cir_table(15.0,2.0,Yellow);
60     
61     cout<<"The table properties are:"<<endl;
62     //调用Height类的成员函数
63     cout<<"Height="<<cir_table.Height()<<endl;
64 
65     //调用circle类的成员函数
66     cout<<"Area="<<cir_table.Area()<<endl; 
67 
68     //调用RoundTable类的成员函数
69     cout<<"Color="<<cir_table.GetColor()<<endl;  
70     return 0;
71 }

 

转载于:https://www.cnblogs.com/borter/p/9413514.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值