时间管理时间和日期报告xym

上传人:冯** 文档编号:139485986 上传时间:2020-07-22 格式:DOCX 页数:21 大小:22.21KB
返回 下载 相关 举报
时间管理时间和日期报告xym_第1页
第1页 / 共21页
时间管理时间和日期报告xym_第2页
第2页 / 共21页
时间管理时间和日期报告xym_第3页
第3页 / 共21页
时间管理时间和日期报告xym_第4页
第4页 / 共21页
时间管理时间和日期报告xym_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《时间管理时间和日期报告xym》由会员分享,可在线阅读,更多相关《时间管理时间和日期报告xym(21页珍藏版)》请在金锄头文库上搜索。

1、Visual C+课程设计报告 时间和日期电子工程与光电技术学院通信工程(1)班Xxx0904220xxx2010年4月一、 程序功能简介:定义了日期类、时间类和日期时间综合类,重载了+,-,+,- -,= ,= ,= ,= =,!=等运算符,可以设置时间、日期,比较时间和日期的大小,进行时间、日期对象的运算,并输出多种格式的结果。二、 课程设计说明:1、 原程序日期类中输出星期几的函数有误,不能输出星期五,现修改如下:int cDate_t:GetDayOfWeek() /starting point : 1/1/1900 was Monday (Saturday=0,Sunday=1,.)

2、/1/1/1900是星期一,根据这个日期推断当前日期是星期几int weekday=2 ; /in 1/1/1900/从1/1/1900开始计算for(int TheYear=1900;TheYearYear;+TheYear) /loop to know the day in 1/1/this yearif(IsLeapYear(TheYear)weekday=(weekday+366)%7; elseweekday=(weekday+365)%7;/until here we found the correct day in 1/1/this yearfor(int TheMonth=1;

3、TheMonthMonth;+TheMonth)/年份计算完后,计算月份天数weekday=(weekday+GetDaysInMonth(TheMonth,Year)%7;/until here we found the correct day in 1/this monthif(weekday+Day)%7=0)return 6;elsereturn(weekday+Day)%7-1);/正确显示星期几/return (weekday+Day)%7-1;(修改前的,无法正确显示星期五) /the correct day in THIS day.2、根据要求在日期类中修改日期对象减去日期对象

4、的重载运算符-,使得结果不是另一个日期,而是天数:int cDate_t:operator - (cDate_t &D)/重载-运算符/修改为日期对象减去日期对象,结果不是另一个日期对象,而是天数int Temp1,Temp2,NewDays=0;Temp1=GetDayOfYear(Year,Month,Day); Temp2=D.GetDayOfYear(D.Year,D.Month,D.Day);if(Year=D.Year)NewDays=max(Temp1,Temp2)-min(Temp1,Temp2);elsefor(int Temp3=min(Year,D.Year);Temp3

5、D.Year)NewDays=NewDays+Temp1-Temp2;elseNewDays=-(NewDays+Temp2-Temp1);return NewDays;/-/*const cDate_t cDate_t:operator - (const cDate_t &D) /operator - function(修改前的函数,结果为另一个日期对象)int YearTemp,MonthTemp,DayTemp,NewDays,Temp1,Temp2; /variables to store to new date object if(Error | D.Error)/ if no le

6、ss then 1 object have orror dataError4();/ print orror messegereturn (cDate_t (-1,-1,-1) ); /return error classYearTemp=Year-D.Year;/substraction of THIS and second yearif(YearTemp1900) / error Error1();/print error messegereturn (cDate_t (-1,-1,-1) ); /return error classTemp1=GetDayOfYear(Year,Mont

7、h,Day); / get days of year of THIS objectif(Temp10) /errorError5();/print error messegereturn (cDate_t (-1,-1,-1) );/return error classTemp2=GetDayOfYear(D.Year,D.Month,D.Day);/ get days of year of second objectif(Temp20)/errorError5();/print error messegereturn (cDate_t (-1,-1,-1) );/return error c

8、lassNewDays= Temp1 - Temp2; /if the data ok get their substractionif(NewDays0) / the substraction is less then zeroNewDays = NewDays + (IsLeapYear(YearTemp)? 366 : 365); / set days for previous yearYearTemp-=1; /sub 1 yearDayTemp=RetriveDay(NewDays,YearTemp); /retrive the current day in the specific

9、 monthMonthTemp=RetriveMonth(NewDays,YearTemp);/same with monthreturn (cDate_t (YearTemp,MonthTemp,DayTemp) );/return local class */3、根据要求在时间类中修改时间对象减去时间对象的重载运算符-,使得结果不是另一个时间,而是分钟数:int cTime_t:operator - (cTime_t &T)/重载-运算符(结果不是另一个时间对象,而是分钟数)int newhour,newminute;newhour=Hours-T.Hours;newminute=Minu

10、tes-T.Minutes;return newhour*60+newminute;/-/*const cTime_t cTime_t:operator - (const cTime_t &T) const /operaor - function/重载-运算符/修改前的,结果为时间对象int HourTemp,MinuteTemp,SecondTemp;/define 3 temp variables to get time data/定义三个时间变量HourTemp = Hours-T.Hours;if(HourTemp0)/T class hour was bigger than THIS

11、 classFlagLessDay=1; /to cut 1 day form date class/小时相减为负数,将少于1天的标志置1HourTemp+=24;/ add 24 hours to previous day/加24小时到前一天MinuteTemp=Minutes-T.Minutes;if(MinuteTemp0)/same for minutes/分钟相减为负MinuteTemp+=60;-HourTemp;SecondTemp=Seconds-T.Seconds;if(SecondTemp0)/same for seconds/秒数相减为负SecondTemp+=60;-M

12、inuteTemp;return ( cTime_t ( HourTemp,MinuteTemp,SecondTemp) );/return local class */4、修改综合类cTDmanage的结构,重新定义为日期类和时间类的派生类,并定义构造函数、各种运算符重载函数,重载输入输出函数:#ifndef TDmanage_h#define TDmanage_hclass cTDmanage:public cTime_t,public cDate_tpublic:cTDmanage ():cTime_t(),cDate_t()/构造函数cTDmanage (int year,int mo

13、nth,int day,int hour,int minute,int second):cDate_t(year,month,day),cTime_t(hour,minute,second)cTDmanage (int hour,int minute,int second):cTime_t(hour,minute,second) void operator = (const cTDmanage& M);/OK/option to put all get and set function of date and time class void print();/operator:bool operator (const cTDmanage& M)const; bool operator (const cTDmanage& M)const; bool operator = (const cTDmanage& M)const; bool operator = (const cTDmanage& M)const; bool operator != (const cTDmanage& M)const; const cTDmanage operator + (const cTDmanage& M) ;int operator - (co

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 企业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号