#include <iostream>
using namespace std;
class clock
{
public:
void settime(int newh = 0, int newm = 0, int news = 0);
void showtime();
private:
int hour, minute, second;
};
void clock::settime(int newh, int newm, int news)
{
hour = newh;
minute = newm;
second = news;
}
void clock::showtime()
{
cout << hour << " " << minute << " " << second;
}
int main()
{
clock c1;
clock c2;//定义两个时钟对象c1和c2
c1.settime();//未定义时间,则输出默认值
c1.showtime();
cout << endl;
c2.settime(8, 30, 30);
c2.showtime();
}
来源:CSDN
作者:小白在路上哈哈哈
链接:https://blog.csdn.net/weixin_46201191/article/details/104039148