• 程序中不要出现仅靠大小写区分的相似的标识符


    程序中不要出现仅靠大小写区分的相似的标识符。

     1 #include <iostream>
     2 #include <stdlib.h>
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 
     5 using namespace std;
     6 //定义timer类
     7 class timer{
     8     long minutes;
     9 public:
    10     //无参数构造函数
    11     timer(void) { 
    12         minutes =0;
    13     };
    14     //字符指针参数的构造函数
    15     timer(char *m) { 
    16         minutes = atoi(m);
    17     };
    18     //整数类型的构造函数
    19     timer(int h, int m) { 
    20         minutes = 60*h+m ;
    21     };
    22     //双精度浮点型构造函数
    23     timer(double h) { 
    24         minutes = (int) 60*h ;
    25     };
    26     long getminutes(void) { return minutes ; };
    27 };
    28 
    29 int main(int argc, char** argv) {
    30         //使用double类型的构造函数创建对象
    31     timer start(8.30),finish(17.30);
    32     cout<<"finish(17.30)-start(8.30)=";
    33     cout<<finish.getminutes()-start.getminutes()<<endl;  
    34 
    35     //使用char指针类型的构造函数创建对象
    36     timer start0("500"),finish0("800");   //创建对象
    37     cout<<"finish0("800")-start0("500")=";
    38     cout<<finish0.getminutes()-start0.getminutes()<<endl;  
    39 
    40     //使用无参数构造函数和整型构造函数创建对象
    41     timer start1;   
    42     timer finish1(3,30);  
    43     cout<<"finish1(3,30)-start1=";
    44     cout<<finish1.getminutes()-start1.getminutes()<<endl;  
    45 
    46     return 0;
    47 }
  • 相关阅读:
    [NOIP2012] 开车旅行
    八皇后
    [Noip2014] 解方程
    [Noip2012] 国王游戏
    [JZOJ4685] 【NOIP2016提高A组8.12】礼物
    [JZOJ100043] 【NOIP2017提高A组模拟7.13】第K小数
    大整数类模板
    [BZOJ2460] [BeiJing2011]元素
    [BZOJ5299] [CQOI2018]解锁屏幕
    [JZOJ4737] 【NOIP2016提高A组模拟8.25】金色丝线将瞬间一分为二
  • 原文地址:https://www.cnblogs.com/borter/p/9413397.html
Copyright © 2020-2023  润新知