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 }
  • 相关阅读:
    第一个反汇编程序
    边缘网关协议(BGP)
    Servlet 学习小结之doPost()方法和doGet()方法
    extern "C"
    工欲善其事 必先利其器
    我是一个混蛋程序员
    KMP 算法——C
    二分查找——C语言
    大整数加法——C语言
    子字符串查找——C语言
  • 原文地址:https://www.cnblogs.com/borter/p/9413506.html
Copyright © 2011-2022 走看看