How to use Clock class simulation to realize alarm clock operation in C++
Today, the editor will share with you the relevant knowledge points about how to use Clock to simulate the operation of the alarm clock in C++. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Define a clock class Clock, design the member function SetAlarm (int hour,int minute,int second) to set the ringing time; use the run () member function to simulate the clock operation, and prompt the bell when running to the ringing time.
The current time is set to 02:08:58, the alarm time is set to 03:40:05, and the clock runtime displays the time of each second.
The code is as follows:
# includeusing namespace std;class Clock {private: int Hour,Minute,Second,hour,minute,second;public: Clock (int Hour=0,int Minute=0,int Second=0) {/ / constructor this- > Hour=Hour,this- > Minute=Minute,this- > Second=Second;} ~ Clock () {} / / destructor void SetClock () {/ / set current time (manually entered) coutMinute > > Second } void SetAlarm (int hour,int minute,int second) {/ / set the alarm time (main function) this- > hour=hour,this- > minute=minute,this- > second=second;} void run () {for (; (Hourly hours)) | | (Second++ Second++) {carry Second=0; Minute++ of if (Second==59) {/ / seconds If (Minute==59) {/ / carry Minute=0; Hour++; if (Hour==24) {/ / cyclic Hour=0;} cout