救助:这个程序是书上的,我改动了哈,就有问题,请教哈
救助:这个程序是书上的,我改动了哈,就有问题,请教哈//4_1.cpp
#include<iostream>
using namespace std;
class Clock //时钟类型声明
{
public: //外部接口,公有成员函数
Clock(int H,int M,int S); //构造函数
Clock(Clock &); //拷贝构造函数
~Clock(); //析构函数
void SetTime(int NewH = 0,int NewM = 0,int NewS = 0);
void ShowTime();
private: //私有数据成员
int Hour,Minute,Second;
};
//时钟类成员函数具体实现
Clock::Clock(int H,int M,int S)
{
Hour = H;
Minute = M;
Second = S;
}
void Clock::SetTime(int NewH = 0,int NewM = 0,int NewS = 0) //"SetTime":重新定义默认参数:参数3
{
Hour = NewH;
Minute = NewM;
Second = NewS;
}
inline void Clock::ShowTime()
{
cout << Hour << ":" << Minute << ":" << Second << endl;
}
//主函数
void main()
{
Clock myClock(0,0,0);
cout << "First time set and output:" << endl;
myClock.SetTime(); //默认
myClock.ShowTime();
cout << "Second time set and output:" << endl;
myClock.SetTime(8,30,30);
myClock.ShowTime();
}