日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

C++?Clock類模擬實(shí)現(xiàn)鬧鐘運(yùn)行_C 語(yǔ)言

作者:Come?to?the?Sunday ? 更新時(shí)間: 2022-05-15 編程語(yǔ)言

本文實(shí)例為大家分享了C++ Clock類模擬鬧鐘運(yùn)行的具體代碼,供大家參考,具體內(nèi)容如下

定義一個(gè)時(shí)鐘類Clock,設(shè)計(jì)成員函數(shù)SetAlarm(int hour,int minute,int second)設(shè)置響鈴時(shí)間時(shí)間;用run()成員函數(shù)模擬時(shí)鐘運(yùn)行,當(dāng)運(yùn)行到響鈴時(shí)間時(shí)提示響鈴。

當(dāng)前時(shí)間設(shè)置為2時(shí)8分58秒,鬧鈴時(shí)間設(shè)置為3時(shí)40分5秒,時(shí)鐘運(yùn)行時(shí)顯示每一秒的時(shí)間。

代碼如下:

#include
using namespace std;

class Clock{
private:?
?? ?int Hour,Minute,Second,hour,minute,second;
public:

?? ?Clock(int Hour=0,int Minute=0,int Second=0){ ? //構(gòu)造函數(shù)
?? ??? ?this->Hour=Hour,this->Minute=Minute,this->Second=Second;
?? ?}

?? ?~Clock(){} ?//析構(gòu)函數(shù)

?? ?void SetClock(){ ? ?//設(shè)置現(xiàn)在時(shí)間(手動(dòng)輸入)
?? ??? ?cout<<"請(qǐng)輸入一個(gè)時(shí)間:"<>Hour>>Minute>>Second;
?? ?}

?? ?void SetAlarm(int hour,int minute,int second){ ?//設(shè)置鬧鈴時(shí)間(主函數(shù))
?? ??? ?this->hour=hour,this->minute=minute,this->second=second;
?? ?}

?? ?void run(){?? ?
?? ??? ?for(;(Hour!=hour)||(Minute!=minute)||(Second!=second);Second++){
?? ??? ??? ?if(Second==59){ ? ?//秒的進(jìn)位
?? ??? ??? ??? ?Second=0;
?? ??? ??? ??? ?Minute++;
?? ??? ??? ??? ?if(Minute==59){ ?//分的進(jìn)位
?? ??? ??? ??? ??? ?Minute=0;
?? ??? ??? ??? ??? ?Hour++;
?? ??? ??? ??? ??? ?if(Hour==24){ ?//時(shí)的循環(huán)
?? ??? ??? ??? ??? ??? ?Hour=0;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?cout<

原文鏈接:https://blog.csdn.net/qq_43254640/article/details/83870209

欄目分類
最近更新