Time类 Date类 TimeWithDate类

感谢党感谢祖国最感谢汪二,帮我指明了错误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

/
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值