当前位置:编程学习 > 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");
}

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,