c++相关的面向对象编程

img


#include
#include
using namespace std;

class Time
{
public:
int hour;
int minute;
int second;

    Time()
    {
    int totalSeconds=time(0);
    int currentSecond=totalSeconds%60;
    int totalMinutes=totalSeconds/60;
    int totalMinute=int totalMinutes%60;
    int totalHours=totalMinutes/60;
    int currentHour=totallHours%24;
    
    cout<<"Current time is"<return 0;
    }    
    
    Time (int second)
    {
        cin>>second;
            int totalSeconds=second;
    int currentSecond=totalSeconds%60;
    int totalMinutes=totalSeconds/60;
    int totalMinute=int totalMinutes%60;
    int totalHours=totalMinutes/60;
    int currentHour=totallHours%24;
    
    cout<<"New time is 1970 year 1.1"<return 0;
    
    }
    Time(int hour,int minute,int second)
    {
        cin>>hour>>minute>>second;
        cout<<"The time is"<return 0;
    }
    
    int get_hour()
    {
        return hour;
    }
    
    int get_minute()
    {
        return minute;
    }
    
    int get_second()
    {
        return second;
    }
    setTime(int elapseTime)
    {
    
    int totalSeconds=time(0);
    int currentSecond=totalSeconds%60;
    int totalMinutes=totalSeconds/60;
    int totalMinute=int totalMinutes%60;
    int totalHours=totalMinutes/60;
    int currentHour=totallHours%24;
    
    
    int a=elapseTime;
    int da=a%60;
    int b=a/60;
    int db=int b%60;
    int c=b/60;
    int dc=c%24;
    
    cout<<"Current time is"<<(currentHour+dc)<<":"<<(currentMinute+db)<<":"<<(currentSecond+da)<return 0;    
}    
    

};
int main()
{
cout<
cout<

return 0;

}


#include <iostream>
using namespace std;

class Time
{
private:
    int hour;
    int minute;
    int second;

    void sot(int seconds)
    {
        second = seconds % 60;
        int totalMinutes = seconds / 60;
        minute = totalMinutes % 60;
        int totalHours = totalMinutes / 60 + 8; //东8区
        hour = totalHours % 24;
    }

public:
    Time()
    {
        sot(time(0));
    }

    Time(int second)
    {
        sot(second);
    }
    Time(int hour, int minute, int second) : hour(hour), minute(minute), second(second)
    {
    }

    int get_hour()
    {
        return hour;
    }

    int get_minute()
    {
        return minute;
    }

    int get_second()
    {
        return second;
    }

    void setTime(int elapseTime)
    {
        second += elapseTime;
        minute += second / 60;
        second %= 60;
        hour += minute / 60;
        minute %= 60;
        hour %= 24;
    }

    friend ostream &operator<<(ostream &out, Time &time)
    {
        out << time.hour << ":" << time.minute << ":" << time.second;
        return out;
    }
};

int main()
{
    Time time1;
    cout << "Current time is: " << time1 << endl;
    Time time2(555550);
    cout << "New time is 1970 year 1.1: " << time2 << endl;
    time2.setTime(1200);
    cout << "The time is: " << time2 << endl;

    return 0;
}

程序运行不起来还是部分功能没实现?

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632