33,311
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class Clock{
public:
Clock(int newH = 0,int newM = 0,int newS = 0);//缺少一个默认构造函数
void setTime(int newH=0,int newM=0,int newS=0);
void showTime();
private:
int hour,minute,second;
};
Clock::Clock(int newH,int newM,int newS){
hour=newH;
minute=newM;
second=newS;
}
void Clock::setTime(int newH,int newM,int newS){
hour=newH;
minute=newM;
second=newS;
}
inline void Clock::showTime(){
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
int main(){
Clock myClock;
cout<<"first time set and output"<<endl;
myClock.setTime();
myClock.showTime();
cout<<"second time set and output"<<endl;
myClock.setTime(8,0,0);
myClock.showTime();
return 0;
}