感谢党感谢祖国最感谢汪二,帮我指明了错误T_T(抹泪)
然后废话不多说直接上题目要求加代码
题目 :
1)定义一个时间类Time,实现:时间的比较(==、!=、>、>=、<、<=)、时间增加/减少若干秒(+=、-=)、时间增加/减少一秒(++、--)以及两个时间相差的秒数(-)
2)定义一个日期类Date,它能表示:年、月、日。为其设计一个成员函数increment,它能把某个日期增加一天。
3) 定义一个带日期的时间类TimeWithDate。对该类对象能进行比较、增加(增加值为秒数)、相减(结果为秒数)等操作
代码:
头文件中文件清单:Time.h Date.h TimeWithDate.h
源文件中文件清单 Time.cpp Date.cpp TimeWithDate.cpp
Time.h
#include <iostream>
using namespace std;
class Time{
private:
int hour;
int minute;
int second;
public:
Time (){hour = 0;minute=0;second=0;}
Time(int h,int m,int s){
if ((h>=0&&h<=23)&&(m>=0&&m<=59)&&(s>=0&&s<=59))
{
hour = h;
minute = m;
second = s;
}else{
cout<<"时间的格式不正确。"<<endl;
}
}
bool operator ==(Time &t);
bool operator !=(Time &t);
bool operator >(Time &t);
bool operator >=(Time &t);
bool operator <(Time &t);
bool operator <=(Time &t);
Time & operator +=(int s);
Time & operator -=(int s);
Time & operator ++();
Time & operator --();
int operator -(Time &t);
void showTime();
};
Date.h
#include <iostream>
using namespace std;
class Date{
private:
int year;
int month;
int day;
public:
Date(){year = 2000;month = 1;day = 1;}
Date(int y,int m,int d);
bool operator >(Date &d);
bool operator >=(Date &d);
bool operator <(Date &d);
bool operator <=(Date &d);
bool operator ==(Date &d);
bool operator !=(Date &d);
Date & increment();
int operator -(Date &d);
void showDate();
};
TimeWithDate.h
/