定义一个时钟类,并编写一个成员函数模拟时钟运行,当运行到设置时间响铃

#include
using namespace std;

class Clock
{
private:
	int hour,minute,second;
	int Ahour,Aminute,Asecond;
public:
	Clock(int h=0,int m=0,int s=0)
	{
		hour=(h>23?0:h);
		minute=(m>59?0:m);
		second=(s>59?0:s);
	}
	void SetAlarm(int h,int m,int s)
	{
		Ahour=(h>23?0:h);
		Aminute=(m>59?0:m);
		Asecond=(s>59?0:s);
	}
	void run()
	{
		second=second+1;
		if(second>59)
		{
			second=0;
			minute++;
			if(minute>59)
			{
				minute=0;
				hour++;
				if(hour>23)
					hour=0;
				if(hour==Ahour&&minute==Aminute&&second==Asecond)
					cout<< "Plink!plink!plink!..."<


你可能感兴趣的:(c++)