• SDUTOJ 2711 4-2 电子时钟中的运算符重载


    #include<iostream>
    #include<stdio.h>
    using namespace std;
    class Time
    {
    private:
        int h, m, s;
    public:
        Time();
        Time(int,int,int);
        void display();
        void tick();
        Time operator ++();
        bool operator >(Time);
    };
    bool Time::operator >(Time a)
    {
        if(h*3600+m*60+s>a.h*3600+a.m*60+a.s)
            return true;
        else
            return false;
    }
    Time Time::operator ++()
    {
        if(++s>=60)
        {
            s=0;
            if(m++>=60)
            {
                m=0;
                h++;
            }
        }
        return *this;
    }
    void Time::display()
    {
        printf("%02d:%02d:%02d
    ",h,m,s);
    }
    Time::Time()
    {
        h=12;
        m=0;
        s=0;
    }
    Time::Time(int a,int b,int c)
    {
        if(b>=60||b<0)b=0;
        if(c>=60||c<0)c=0;
        h=a;
        m=b;
        s=c;
    }
    int main()
    {
        int a[6];
        for(int i=0;i<6;i++)
            cin>>a[i];
        Time t1(a[0],a[1],a[2]),t2(a[3],a[4],a[5]);
        if(t1>t2)
            cout<<"The begin time is not earlier than the end time!"<<endl;
        else
        {
            while(t2>t1)
            {
                t1.display();
                ++t1;
            }
            t1.display();
        }
        return 0;
    }
    
    
    

  • 相关阅读:
    hide the navigationBar and tabBar
    js
    CATranstion动画
    CASpringAnimation
    UIImageView动画
    打电话发短信
    页面滑动悬停在某个控件(两种做法)
    导航栏相关设置
    ASCII和16进制
    C++中,申请字符串数组可用new实现
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6978570.html
Copyright © 2020-2023  润新知