Home > Back-end >  What code is wrong?
What code is wrong?

Time:04-01

# include & lt; iostream>
using namespace std;
The class Clock
{
Public:
Clock (int h, int m, int s)
{
Hour=(h> 23? Zero: h);
Minute=(m> 59? Zero: m);
The second (s> 59? Zero: s);
}
Void SetAlarm (int h, int m, int s)
{
Ahour=(h> 23? Zero: h);
Aminute=(m> 59? Zero: m);
Asecond=(s> 59? Zero: s); }
Void ShowTime ()
{
cout<" Now: "& lt; }
Void the run ()
{
Second=second + 1;
If (second> 59)
{
Second=0;
Minute=0;
Minute=minute + 1;
}
If (minute> 59)
{
Minute=0;
Hour=+ 1 hour;
}
If (minute> 23)
Hour=0;
If (hour==Ahour& & Minute==Aminute& & Second==Asecond)
{
cout<" Dangdang when "& lt; }
}
Private:
Int hour;
Int minute;
Int seond;
Int Ahour;
Int Aminute.
Int Asecond;
};
Int main ()
{Clock D1 (7,59,57);
D1. ShowTime ();
D1. SetAlarm (0, 8);
for(int i=0; i<3600 * 24 * 3 + 100; I++)
D1. The run ();
D1. ShowTime ();
return 0;
}

CodePudding user response:

"Why" as if the output, four times for reference:
 # include & lt; iostream> 
using namespace std;
The class Clock
{
Public:
Clock (int h, int m, int s)
{
Hour=(h> 23? Zero: h);
Minute=(m> 59? Zero: m);
Second=(s> 59? Zero: s);//second (s> 59? Zero: s);
}
Void SetAlarm (int h, int m, int s)
{
Ahour=(h> 23? Zero: h);
Aminute=(m> 59? Zero: m);
Asecond=(s> 59? Zero: s);
}
Void ShowTime ()
{
cout<" Now: "& lt; }
Void the run ()
{
Second=second + 1;
If (second> 59)
{
Second=0;
//minute=0;
Minute=minute + 1;
}
If (minute> 59)
{
Minute=0;
Hour=+ 1 hour;
}
If (hour> 23)//if (minute> 23)
Hour=0;
If (hour==Ahour& & Minute==Aminute& & Second==Asecond)
{
cout<" Dangdang when "& lt; }
}
Private:
Int hour;
Int minute;
Int second;//int seond;
Int Ahour;
Int Aminute.
Int Asecond;
};

Int main ()
{
Clock (7 D1,59,57);
D1. ShowTime ();
D1. SetAlarm (0, 8);
for(int i=0; i<3600 * 24 * 3 + 100; I++)
D1. The run ();
D1. ShowTime ();

return 0;
}

//Now: 7:59:57
//dangdang when
//dangdang when
//dangdang when
//dangdang when
//Now: 8:1:37
//please press any key to continue...
  • Related