C++ <->

/*

先看别人的,在做自己的;

#include<iostream>

using namespace std;

/*

char *input(char*p)

{

       cout<<"input your name:";

       cin>>p;

       return p;

}

 

int main()

{

       char name[20];

       cout<<input(name)<<endl;

}

 

void show(int &m)

{

       ++m;}

int main()

{

       int a=10;

       show(a);

       cout<<"a="<<a<<endl;

}*/

/*

#include<iostream>

using namespace std;

#include<cstdlib>

#include<ctime>

 

 

struct Time{

       int hour;

       int min;

       int sec;

    void set(int h,int m, int s);

    void tick();

    void show();

    void run();

};

int main()

{

       Time t;

       t.set(10,45,50);

       t.run();

}

 

void Time::set(int h,int m,int s)

{

       hour=h;

       min=m;

       sec=s;

}

void Time::tick()

 {

        long t=time(NULL);

        while(time(NULL)==t);

        if( ++sec>=60){

               sec=0;

               if(++min>=60){

                      min=0;

                      if(++hour>=24){

                             hour=0;

               }

               }

        }

 }

 

void Time::show()

 {

        if(hour<10)

               cout<<0;

        cout<<hour<<":";

        if(min<10)

               cout<<0;

        cout<<min<<":";

        if(sec<10)

               cout<<0;

        cout<<sec<<'\r';

 }

void Time::run()

 {

        for(;;){

               tick();

               show();

 }

 }*/

 

 

//一百秒的秒表

 

/*

#include<iostream>

using namespace std;

#include<ctime>

 

class accout{

  int sec;

public:

   void set(int s);

   void tick();

   void show();

   void run();

};

 

int main()

{

       accout t;

       t.set(10);

       t.run();

}

 

void accout::set(int s)

{

       sec=s;

}

 

void accout::tick()

{

       long t=time(NULL);

       while(t==time(NULL));

       sec--;

}

e

void accout::show()

{

       cout<<sec<<'\r';

       if(sec==0) cout<<"\a\a\a\a\a"<<"    时间到!!!!"<<endl;

}

 

void accout::run()

{

       while(sec>=0){

              tick();

              show();

       }

 

}

*/

/*

#include<iostream>

using namespace std;

#include<ctime>

 

 

class Clock{

private:

       int h;

       int m;

       int s;

public:

       void set(int hour,int minute,int second);

       void tick();

       void show();

       void run();

};

 

   int main()

   {

          Clock t;

          t.set(0,1,23);

          t.run();

   }

   void Clock::set(int hour,int minute,int second)

   {

          h=hour;

          m=minute;

          s=second;

   }

 

   void Clock::tick()

   {

        time_t t=time(NULL);

          while(t==time(NULL));

          if(--s<0){

                 s=59;

                 if(--m<0){

                        m=59;

                        --h;

                 }

          }

   }

 

   void Clock::show()

   {

          if(h<10)  cout<<0;

          cout<<h<<":";

          if(m<10)  cout<<0;

          cout<<m<<":";

          if(s<10)  cout<<0;

          cout<<s<<"\r";

   }

   void Clock::run()

   {

          while(h!=0||m!=0||s!=0)

          {

                 tick();

                 show();

          }

          cout<<"\a\a\a\a\a"<<"  时间到!!!"<<endl;

   }

 

*/

/*

//倒计时时间从键盘输入,每一秒发出滴答声。

#include<iostream>

using namespace std;

#include<ctime>

class Clock{

       int h;

       int m;

       int s;

public:

       void set(int hour,int minute,int second);

       void tick();

       void  show();

       void  run();

};

 

int main()

{

       int hour,second,minute;

       Clock t;

       t.set( hour,minute,second);

       t.run();

}

 

void Clock::set(int hour,int minute,int second)

{

       cout<<"请输入计时时间:";

       cin>>hour>>minute>>second;

       h=hour;

       m=minute;

       s=second;

}

 

void Clock::tick()

{

       time_t t=time(NULL);

       while(t==time(NULL));

       if(--s<0){

              s=59;

              if(--m<0){

                     m=59;

                     --h;

              }

       }

              cout<<"\a";

}

void Clock::show()

{

       if(h<10) cout<<0;

       cout<<h<<":";

       if(m<10) cout<<0;

       cout<<m<<":";

       if(s<10) cout<<0;

       cout<<s<<"\r";

}

 

 

void Clock::run()

{

       while(h!=0||m!=0||s!=0)

       {

              tick();

              show();

       }

       cout<<"\a\a\a    时间到!!!"<<endl;

}

*/

/*

#include<iostream>

using namespace std;

#include<ctime>

class Clock{

       int h;

       int m;

       int s;

public:

    Clock(int hour,int minute,int second);

       void tick();

       void  show();

       void  run();

};

 

int main()

{

 

       Clock t(0,2,0);

       t.run();

}

 

 Clock::Clock(int hour,int minute,int second)

{

       cout<<"请输入计时时间:";

       cin>>hour>>minute>>second;

       h=hour;

       m=minute;

       s=second;

}

 

void Clock::tick()

{

       time_t t=time(NULL);

       while(t==time(NULL));

       if(--s<0){

              s=59;

              if(--m<0){

                     m=59;

                     --h;

              }

       }

              cout<<"\a";

}

void Clock::show()

{

       if(h<10) cout<<0;

       cout<<h<<":";

       if(m<10) cout<<0;

       cout<<m<<":";

       if(s<10) cout<<0;

       cout<<s<<"\r";

}

 

 

void Clock::run()

{

       while(h!=0||m!=0||s!=0)

       {

              tick();

              show();

       }

       cout<<"\a\a\a    时间到!!!"<<endl;

}

*/

/*

转载于:https://www.cnblogs.com/sdluReaLo/archive/2013/03/08/2949862.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值