ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:17.01KB ,
资源ID:10019927      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10019927.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c++时间程序.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

c++时间程序.docx

1、c+时间程序/闽南师范大学-数学与统计学院-09/10金融班-吴童鞋#include #include using namespace std;int max=0,31,28,31,30,31,30,31,31,30,31,30,31;/class Date;class Time public: int hour; int minute; int sec; Time(); Time(int h,int m,int s)hour=h;minute=m;sec=s; void get_time(); /void show_time(Date &); int pd_time(int,int,int)

2、;class Date public: int year; int month; int day; Date(); Date(int y,int m, int d)year=y;month=m;day=d; void get_date(); void show_date(); int pd_date(int,int,int); /*友元函数*/ /friend void Time:show_time(Date &);/*由基类Time派生,用来放计算结果几天几小时几分几秒的类*/class Js:public Time public: int tian; Js():Time()tian=0;

3、Js(int t,int h,int m,int s):Time(h,m,s)tian=t; void get_js(); void show_js()couttian天hour小时minute分sec秒;/*由基类Time和基类Date派生的类Timedate,重载运算符函数作为成员函数*/class Timedate:public Date,public Time public: Timedate():Date(),Time() Timedate(int y,int mon,int d,int h,int min,int s):Date(y,mon,d),Time(h,min,s) voi

4、d show_timedate()printf(%04d-%02d-%02d_%02d:%02d:%02d,year,month,day,hour,minute,sec); Timedate operator + (Js a); Timedate operator - (Js b); Js operator - (Timedate td);/*时间的成员函数*/Time:Time() hour=0; minute=0; sec=0;void Time:get_time() int h,m,s; cout请输入时、分、秒:hms; while(!pd_time(h,m,s) cout输入有误,正

5、确格式为:00:00:00-23:59:59。endl; cout请再一次输入时、分、秒:hms; hour=h; minute=m; sec=s;/*void Time:show_time(Date &d) printf(%04d-%02d-%02d,d.year,d.month,d.day); printf(%02d:%02d:%02dn,hour,minute,sec);*/int Time:pd_time(int h,int m,int s) /*判断时间*/ if(h=23&m=59&s=59)return 1; else return 0;/*年月日的成员函数*/Date:Date

6、() year=0; month=0; day=0;void Date:get_date() int y,x,z; cout请输入年、月、日:yxz; while(!pd_date(y,x,z) cout请再一次输入年、月、日:yxz; year=y; month=x; day=z;void Date:show_date() coutyear-month-12|x=0) cout月份的格式输入有误,正确格式为:1-12。endl; return 0; if(xmaxx) cout日期的格式输入有误x月的日期正确格式为:1-maxxendl; return 0; else return 1;/派

7、生类Js的成员函数void Js:get_js() int x1,x2,x3,x4; cout请输入要计算的天数、时数、分钟数及秒数x1x2x3x4; tian=x1;hour=x2;minute=x3;sec=x4;/*派生类timedate的成员函数;重载运算符函数*/Timedate Timedate:operator + (Js a) /*加法:一段时间后的日期是d*/ Timedate td; td.sec=sec+a.sec; if(td.sec=60)td.sec=td.sec-60;td.minute=td.minute+1; td.minute=td.minute+minut

8、e+a.minute; if(td.minute=60)td.minute=td.minute-60;td.hour=td.hour+1; td.hour=td.hour+hour+a.hour; if(td.hour=24)td.hour=td.hour-24;td.day=td.day+1; td.day=td.day+day+a.tian; td.month=month; td.year=year; if(td.year%4=0&td.year%100!=0|td.year%400=0)max2=29;else max2=28; while(td.daymaxtd.month) if(t

9、d.year%4=0&td.year%100!=0|td.year%400=0)max2=29;else max2=28; td.day=td.day-maxtd.month; td.month+; if(td.month=13) td.month=1; td.year+; return td;Timedate Timedate:operator - (Js b) /*减法:一段时间前的日期是d*/ Timedate td; td.sec=sec-b.sec; if(td.sec0)td.sec=td.sec+60;td.minute=td.minute-1; td.minute=td.min

10、ute+minute-b.minute; if(td.minute=0)td.minute=td.minute+60;td.hour=td.hour-1; td.hour=td.hour+hour-b.hour; if(td.hour=0)td.hour=td.hour+24;td.day=td.day-1; td.day=td.day+day-b.tian; td.month=month; td.year=year; while(td.day=0) td.month-; if(td.month=0) td.month=12; td.year-; if(td.year%4=0&td.year%

11、100!=0|td.year%400=0)max2=29;else max2=28; td.day=td.day+maxtd.month; return td;Js Timedate:operator - (Timedate td) /*减法:2个时间点相距多长时间*/ Js j; int i; int a1=0;int a2=0;int a3=0; if(yeartd.year) for(i=year+1;itd.year;i+) if(i%4=0&i%100!=0|i%400=0)a1=a1+366; else a1=a1+365; if(year%4=0&year%100!=0|year

12、%400=0)max2=29;else max2=28; for(i=month+1;i=1;i-) a3=a3+maxi; a3=a3+td.day; j.sec=(60-sec)+td.sec; if(j.sec=60)j.sec=j.sec-60;j.minute=j.minute+1; j.minute=j.minute+(60-minute-1)+td.minute; if(j.minute=60)j.minute=j.minute-60;j.hour=j.hour+1; j.hour=j.hour+(24-hour-1)+td.hour; if(j.hour=24)j.hour=j

13、.hour-24;j.tian=j.tian+1; if(yeartd.year) for(i=td.year+1;iyear;i+) if(i%4=0&i%100!=0|i%400=0)a1=a1+366; else a1=a1+365; if(td.year%4=0&td.year%100!=0|td.year%400=0)max2=29;else max2=28; for(i=td.month+1;i=1;i-) a3=a3+maxi; a3=a3+day; j.sec=(60-td.sec)+sec; if(j.sec=60)j.sec=j.sec-60;j.minute=j.minu

14、te+1; j.minute=j.minute+(60-td.minute-1)+minute; if(j.minute=60)j.minute=j.minute-60;j.hour=j.hour+1; j.hour=j.hour+(24-td.hour-1)+hour; if(j.hour=24)j.hour=j.hour-24;j.tian=j.tian+1; if(year=td.year) while(year%4=0&year%100!=0|year%400=0) max2=29; if(monthtd.month) for(i=month+1;i=60)j.sec=j.sec-60

15、;j.minute=j.minute+1; j.minute=j.minute+(60-minute-1)+td.minute; if(j.minute=60)j.minute=j.minute-60;j.hour=j.hour+1; j.hour=j.hour+(24-hour-1)+td.hour; if(j.hour=24)j.hour=j.hour-24;j.tian=j.tian+1; if(monthtd.month) for(i=td.month+1;i=60)j.sec=j.sec-60;j.minute=j.minute+1; j.minute=j.minute+(60-td

16、.minute-1)+minute; if(j.minute=60)j.minute=j.minute-60;j.hour=j.hour+1; j.hour=j.hour+(24-td.hour-1)+hour; if(j.hour=24)j.hour=j.hour-24;j.tian=j.tian+1; if(month=td.month) if(day=60)j.sec=j.sec-60;j.minute=j.minute+1; j.minute=j.minute+(60-minute-1)+td.minute; if(j.minute=60)j.minute=j.minute-60;j.

17、hour=j.hour+1; j.hour=j.hour+(24-hour-1)+td.hour; if(j.hour=24)j.hour=j.hour-24;j.tian=j.tian+1; if(daytd.day) a3=day-td.day-1; j.sec=(60-td.sec)+sec; if(j.sec=60)j.sec=j.sec-60;j.minute=j.minute+1; j.minute=j.minute+(60-td.minute-1)+minute; if(j.minute=60)j.minute=j.minute-60;j.hour=j.hour+1; j.hou

18、r=j.hour+(24-td.hour-1)+hour; if(j.hour=24)j.hour=j.hour-24;j.tian=j.tian+1; if(day=td.day) if(hourtd.hour) j.sec=sec-td.sec; if(j.sec0)j.sec=j.sec+60;j.minute=j.minute-1; j.minute=j.minute+minute-td.minute; if(j.minute0)j.minute=j.minute+60;j.hour=j.hour-1; j.hour=j.hour+hour-td.hour; if(hourtd.hou

19、r) j.sec=td.sec-sec; if(j.sec0)j.sec=j.sec+60;j.minute=j.minute-1; j.minute=j.minute+td.minute-minute; if(j.minutetd.minute) j.sec=sec-td.sec; if(j.sec0)j.sec=j.sec+60;j.minute=j.minute-1; j.minute=j.minute+minute-td.minute; if(minutetd.minute) j.sec=td.sec-sec; if(j.sec=td.sec)j.sec=sec-td.sec; els

20、e j.sec=td.sec-sec; j.minute=0; j.hour=0; j.tian=0; j.tian=j.tian+a1+a2+a3; return j;/*主函数*/int main() Js j1,j2; Timedate td1,td2,tda,tdb; cout1、计算某个时间点加上一段时间后是什么时候;endl; cout时间点a:;td1.get_date(); /*调用基类Date中的函数*/ cout时间点a:;td1.get_time(); /*调用基类Time中的函数*/ j1.get_js(); system(cls); cout1、计算某个时间点加上一段

21、时间后是什么时候;endl; cout时间点a为:;td1.show_timedate();cout;endl; cout*endlendl; tda=td1+j1; cout ;td1.show_timedate();coutendl; cout + ;j1.show_js();coutendl; cout ;coutendl; cout = ;tda.show_timedate();coutendlendl; cout*endlendl; cout2、计算某个时间点减去一段时间后是什么时候;endl; cout时间点a:;td1.get_date(); /*调用基类Date中的函数*/ c

22、out时间点a:;td1.get_time(); /*调用基类Time中的函数*/ j1.get_js(); system(cls); cout2、计算某个时间点减去一段时间后是什么时候;endl; cout时间点a为:;td1.show_timedate();cout;endl; cout*endlendl; tda=td1-j1; cout ;td1.show_timedate();coutendl; cout - ;j1.show_js();coutendl; cout ;coutendl; cout = ;tda.show_timedate();coutendlendl; cout*e

23、ndlendl; cout3、计算2个时间点相差多少时间。endl; cout时间点a:;td1.get_date(); /*调用基类Date中的函数*/ cout时间点a:;td1.get_time(); /*调用基类Time中的函数*/ cout时间点b:;td2.get_date(); /*调用基类Date中的函数*/ cout时间点b:;td2.get_time(); /*调用基类Time中的函数*/ system(cls); cout3、计算2个时间点相差多少时间。endl; cout时间点a为:;td1.show_timedate();cout; cout时间点b为:;td2.show_timedate();coutendl; cout*endlendl;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1