程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> c++處女類

c++處女類

編輯:C++入門知識

#include <iostream>
#include <ctime>
using namespace std;

class Alarm{
private:
      unsigned int h;
      unsigned int m;
      unsigned int s;
      unsigned int hh;
      unsigned int mm;
      void talk();//走動
      void show();//顯示
public:
       Alarm(unsigned int hour, unsigned int minute, unsigned int second, unsigned int hour_a, unsigned int minute_a);//時鐘初始化
       void run();//運行
};

Alarm::Alarm(unsigned int hour, unsigned int minute, unsigned int second, unsigned int hour_a, unsigned int minute_a){
     this->h=hour;
     this->m=minute;
     this->s=second;
     this->hh=hour_a;
     this->mm=minute_a;
}

void Alarm::talk(){
     time_t t=time(NULL);
     while(time(NULL)==t);
     if(++this->s > 59){
           this->s=0;
           if(++this->m > 59){
                 this->m=0;
                 if(++this->h == 24)
                      this->s = 0;
           }
     }
}

void Alarm::show(){
     cout<<"";
     if(this->h<10) cout<<0;
     cout<<this->h<<:;
     if(this->m<10) cout<<0;
     cout<<this->m<<:;
     if(this->s<10) cout<<0;
     cout<<this->s<<flush;
}

void Alarm::run(){
     for(;;){
        if(this->hh==this->h && this->mm==this->m){
             /*cout<<""<<"a";
             cout<<"時間到……"<<endl;
             break;*/
             cout<<"a";
        }
        this->talk();
        this->show();
     }
}

int main(){
    Alarm t(10,10,55,10,11);
    t.run();
    system("PAUSE");
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved