用类实现的时钟加法函数(C++)
2014-11-02 13:49
239 查看
/**************************************/ /* 程序名:时钟加法 */ /* 功能:带时间加法的时钟类 */ /**************************************/ #include<iostream> using namespace std; class Clock { private: int H,M,S; public: void setTime(int h,int m,int s) { H=h; M=m; S=s; } void showTime() { cout<<"H"<<H<<"M"<<M<<"S"<<S<<endl; } Clock(int h=0,int m=0,int s=0) { H=h; M=m; S=s; } Clock(Clock &p) { H=p.H; M=p.M; S=p.S; } //函数重载 void TimeAdd(Clock *p); void TimeAdd(int h,int m,int s); void TimeAdd(int s); }; void Clock::TimeAdd(Clock *cp) { H=(cp->H+H+(cp->M+M+(cp->S+S)/60)/60)%24; M=(cp->M+M+(cp->S+S)/60)%60; S=(cp->S+S)%60; } void Clock::TimeAdd(int h,int m,int s) { H=(h+H+(M+m+(S+s)/60)/60)%24; M=(M+m+(S+s)/60)%60; S=(S+s)%60; } void Clock::TimeAdd(int s) { H=(H+(M+(S+s)/60)/60)%24; M=(M+(S+s)/60)%60; S=(s+S)%60; }
相关文章推荐
- 在C++中用虚函数及模版实现委托(支持自定义参数)
- 在Delphi与C++之间实现函数与对象共享
- 使用IDispatch::Invoke函数在C++中调用C#实现的托管类库方法
- 抱歉,没分了!!!请教linux下,用C/C++编程,如何知道我要实现某一功能需要用到什么函数
- 用c++函数编程实现三角形的面积
- Delphi与C++之间通过实现函数与对象共享
- 模版函数指针,C++委托的实现
- 如何在C++中实现类似Scanf的变参个数函数
- C++ 初始化函数的实现 - Ling Xu 的 C++ 技术随笔 - C++博客
- 使用IDispatch::Invoke函数在C++中调用C#实现的托管类库方法
- C++中的property库的设计与实现过程(二)——如何为属性指定get_和set_函数?
- C++中虚函数的实现机制
- C++中的虚函数到底怎么实现的?
- 在C中用struct实现C++中class的函数声明和定义
- 在Delphi与C++之间实现函数与对象共享
- 在C++中用虚函数及模版实现委托(支持多播)
- 在Delphi与C++之间实现函数与对象共享
- 在Delphi与C++之间实现函数与对象共享
- Delphi里实现类似于C++ strtok 的函数
- 模版函数指针,C++委托的实现-原创