#include <iostream>
using namespace std;
class TimeWithDate
{
private:
int year;
int month;
int day;
int hour;
int minute;
int second;
public:
Time(){year=month=day=hour=minute=second=0;}
TimeWithDate(int y, int m, int d, int h, int min, int s)//建構式
{
y = year;
m = month;
d = day;
h = hour;
min = minute;
s = second;
}
void display() const
{
cout<<year<<"年"<<month<<"月"<<day<<"日"<<hour<<":"<<minute<<":"<<second<<endl;
}
void increment1()//天數增加1
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if (day == 31)
{
day = 1;
if (month == 12)
{
year++;
month = 1;
}
else
month++;
}
else
day++;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day == 30)
{
day = 1;
month++;
}
else
day++;
}
}
void increment2()
{
if (second == 59)
{
if (minute == 59)
{
if (hour == 23)
{
hour = 0; minute = 0; second = 0; increment1();
}
else
{
hour++; minute = 0; second = 0;
}
}
else
{
minute++; second = 0;
}
}
else
{
second++;
}
}
bool equal(TimeWithDate& other_time)//比較是否與某個時間相等。
{
if (year==other_time.year&&month==other_time.month&&day==other_time.day&&hour == other_time.hour && minute == other_time.minute && second == other_time.second)
return true;
else
return false;
}
bool less_than(TimeWithDate& other_time) //比較是否早于某個時間。
{
if (year == other_time.year||
year == other_time.year && month < other_time.month||
year == other_time.year && month == other_time.month && day < other_time.day ||
year == other_time.year && month == other_time.month && day == other_time.day && hour < other_time.hour||
year == other_time.year && month == other_time.month && day == other_time.day && hour == other_time.hour && minute<other_time.minute ||
year == other_time.year && month == other_time.month && day == other_time.day && hour == other_time.hour && minute == other_time.minute && second < other_time.second)
return true;
else
return false;
}
};
int main()
{
int year,month,day,hour,minute,second;
cout<<"請輸入日期:" ;
cin>>year>>month>>day>>hour>>minute>>second;
TimeWithDate d(year,month,day,hour,minute,second);
d.display();
return 0;
}
求助為什么輸出會出現亂碼?
uj5u.com熱心網友回復:
明白了,原來初始化的時候弄錯了
uj5u.com熱心網友回復:
明白了,原來初始化的時候弄錯了
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/84701.html
標籤:C++ 語言
