Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Clock class simulation to realize alarm clock operation in C++

Shulou Source: shulou.com Published: 2022-06-01 06:05:53 10月02日 Update

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

Tags: Time run function bell clock knowledge article alarm clock alarm clock content member present tense prompt input different big code most of it Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Shulou Information Apple Xiaomi