我是靠谱客的博主 洁净小笼包,这篇文章主要介绍建议 for 语句的循环控制变量的取值采用“半开半闭区间”写法,现在分享给大家,希望可以做个参考。

建议 for 语句的循环控制变量的取值采用“半开半闭区间”写法。

 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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) {radius=r;} 12 float Area() { 13 return 3.1416*radius*radius; 14 } 15 }; 16 //桌子类Table的定义 17 class Table { 18 float height; 19 public: 20 Table(float h) {height=h;} 21 float Height() { 22 return height; 23 } 24 }; 25 //圆桌类RoundTable的定义 26 class RoundTable:public Table,public Circle { 27 Color color; 28 public: 29 RoundTable(float h,float r,Color c); //构造函数 30 int GetColor() { 31 return color; 32 } 33 }; 34 //圆桌构造函数的定义 35 RoundTable::RoundTable(float h,float r,Color c):Table(h),Circle(r) 36 { 37 color=c; 38 } 39 //main()函数的定义 40 41 int main(int argc, char** argv) { 42 RoundTable cir_table(15.0,2.0,Yellow); 43 44 cout<<"The table properties are:"<<endl; 45 //调用Height类的成员函数 46 cout<<"Height="<<cir_table.Height()<<endl; 47 48 //调用circle类的成员函数 49 cout<<"Area="<<cir_table.Area()<<endl; 50 51 //调用RoundTable类的成员函数 52 cout<<"Color="<<cir_table.GetColor()<<endl; 53 return 0; 54 }

 

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

最后

以上就是洁净小笼包最近收集整理的关于建议 for 语句的循环控制变量的取值采用“半开半闭区间”写法的全部内容,更多相关建议内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(85)

评论列表共有 0 条评论

立即
投稿
返回
顶部