zoukankan      html  css  js  c++  java
  • 建议 for 语句的循环控制变量的取值采用“半开半闭区间”写法

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

     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 }
  • 相关阅读:
    简单字符串处理应避免使用正则表达式
    提高正则表达式的可读性
    用零宽度断言匹配字符串中的特定位置
    避免不必要的回溯
    预编译正则表达式
    用Text::CSV_XS模块处理csv文件
    Ack 类似grep一样的查找
    Apache压力测试
    仅编译正则表达式一次
    排序上下箭头的是实现
  • 原文地址:https://www.cnblogs.com/borter/p/9413506.html
Copyright © 2011-2022 走看看