1、日期和时间课程设计报告 1.功能 1.1 课程设计题目功能: 定义了日期类、 时间类和日期时间综合类, 重载了+、 -、 +、 -、 =、 =、 运算符。 2.5 error 类:为专门处理错误的类,包括对原日期时间少于 1900 的处理,以及在“+” 、 “-” 中结果少于 1900 的处理,以及输出时日期时间少于 1900 的处理。 2.6 main 类:以 swith 型进行菜单的输出,主要是对所有程序的综合处理,对菜单项的编 辑,是最后的运行程序。 3.调试过程 3.1 出现了编译时无问题,而调试时提示没有相关函数的问题,编译结束后载入相关文件解 决了问题。 3.2 无法有效退出,将函
2、数改为 swith 型解决问题。 3.3 出现了输出结果与预期不符的状况,更改了输出变量名解决问题。 3.4 最开始时没有设置对“+”的错误类进行设置,由于不太可能遇到相关情况,没有注意, 后来看课本才发现。 4.输入输出 开始界面 时间格式的更改与否 主操作菜单 时间类操作,以“+”为例 其后继续为主操作菜单 日期类操作,以“-”为例 综合类操作,以比较为例 5.总结 本程序大量运用了运算符的重载, 并且用到了多文件的处理, 对以后处理或创建大程序 很有帮助。而且运算符重载实际上是有很多技巧的,最一般的“+” “-”重载,需要考虑输 入的数据的类型及对输出结果的要求。另外错误处理也是个难关,
3、即“error”类,不仅要考 虑原日期时间的处理,还要考虑对运算符错误的处理,很有可能会落下某些情况,需要不断 调试以保证每种情况都考虑到了。 这个程序对个人对类处理必须相当熟悉, 几乎将所有可能 的情况都涉及了,而且难度不算太大,对于刚接触 c+没有太长时间的我们是个很好的练习 课程。 6.附件 源程序: /cTime_t.h Begin #include #include #ifndef cTime_t_h #define cTime_t_h class cTime_t static int FlagMoreDay; static int FlagLessDay; static int f
4、ormat; int Seconds; int Minutes; int Hours; struct tm *CurrentTime; time_t time_date; public: cTime_t(); cTime_t(const cTime_t cTime_t(int hour,int min=0,int sec=0):Seconds(sec),Minutes(min),Hours(hour) ; cTime_t(); const cTime_t inline void SetSec (int sec) Seconds=sec; inline void SetMin (int min)
5、 Minutes=min; inline void SetHour (int hour) Hours=hour; void print() const; void print1() const; inline int GetSec () const return Seconds; inline int GetMin () const return Minutes; inline int GetHour () const return Hours; int getFlagMoreDay()return FlagMoreDay; int getFlagLessDay()return FlagLes
6、sDay; void resetFlagMoreDay()FlagMoreDay=0; void resetFlagLessDay()FlagLessDay=0; bool operator = (const cTime_t bool operator = (const cTime_t bool operator != (const cTime_t const cTime_t operator + (const cTime_t int operator - (cTime_t const cTime_t operator + (int NewMinutes); const cTime_t operator - (int NewMinutes); int getformat1()return format; void operator + (); void operator - (); static void ChangeFormat() format = (format=1)? 2 : 1 ; /