#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();
}
时钟类的完整程序
最新推荐文章于 2023-02-08 10:14:37 发布