没事的时候随便写点东西,练练逐渐生疏的手!

我只是想在尽我的能力写一个关于秒表的程序,或许只是我的一厢情愿导致这个表只为我而走,我像LOL中的“时光老头”活在自己的时间里。

#include <iostream>
#include <iomanip>
using namespace std;
class Clock
{
public:
    Clock(int hour = 0, int minute = 0, int second = 0  ):m_hour(hour), m_minute(minute),m_second(second)
    {
    };
    friend ostream& operator<<(ostream& out, const Clock& clock);
    Clock& operator=(const Clock& clock);
    Clock& operator++();
    Clock operator++(int);


public:
    int m_hour;
    int m_minute;
    int m_second;
};
ostream& operator<<(ostream& out, Clock &clock)
{
    
out<<setw(2)<<setfill('0')<<clock.m_hour<<":"<<setw(2)<<setfill('0')
        <<clock.m_minute<<":"<<setw(2)<<setfill('0')<<clock.m_second<<'\r';
    return out;
}
Clock& Clock::operator=(const Clock& clock)
{
    m_hour = clock.m_hour;
    m_minute = clock.m_minute;
    m_second = clock.m_second;
    return *this;
}


Clock& Clock::operator++(){
    m_second++; //新增数据成员Second
    if (60 == m_second) {
        m_second = 0;
        m_minute++;
        if (60 == m_minute) {
            m_minute = 0;
            m_hour++;
            if (24 == m_hour) {
                m_hour = 0;
            }
        }
    }
    return *this;
}
Clock Clock::operator++(int) // clock++
{
    Clock c = *this;
    ++(*this); //调用前++  (*this).operator++()
    return c;
}
int sleep()
{
    for ( int i = 0; i< 1000; i++)
    {
        for (int j = 0; j < 1000; j++)
        {
            for( int k = 0; k < 3 ; k++ )
            {
                int ncount = 0;
            }
        }
    }
    return 0;
}
int main()
{
    char ch = 'n';
    cout<<"是否启动时钟?";
    cin>>ch;
    if(ch == 'y')
    {
        Clock c1 ;
        for(int count = 0; count < 7200; count ++ )
        {
            cout<<(++c1);
            sleep();
        }
    }  
    return 0;
}


从我的时间中,你学到了什么,是不是可以将我的时间拿走供你利用呢?加油吧,骚年!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值