最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++實現(xiàn)秒表功能

 更新時間:2022年06月14日 10:31:33   作者:被迫敲代碼的張先森  
這篇文章主要為大家詳細介紹了C++實現(xiàn)秒表功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C++實現(xiàn)秒表功能的具體代碼,供大家參考,具體內(nèi)容如下

抽象出CLOCK類來制作一個電子秒表,能夠自動跳轉(zhuǎn)

代碼中有些陌生的庫函數(shù),順便介紹一下:

1.system(“cls”)函數(shù)

system函數(shù)代表執(zhí)行系統(tǒng)命令,system(“cls”)就是執(zhí)行命令”清屏“的意思。

#include <windows.h>
system("cls"); ?

2.setw()與setfill()函數(shù)

在C++中,setw(int n)用來控制輸出間隔。setw()默認填充的內(nèi)容為空格,可以setfill()配合使用設置其他字符填充。注意:setw和setfill 被稱為輸出控制符,使用時需要在程序開頭寫上#include “iomanip.h”,否則無法使用。

3.Sleep()函數(shù)

功 能: 執(zhí)行掛起一段時間
用 法: unsigned sleep(unsigned n);//n為毫秒
使用時帶上頭文件#include <windows.h>

整個程序代碼如下:

#include<iostream>
#include<iomanip>
#include <windows.h>
using ?namespace ?std;
class CLOCK
{
private:
? ? int hour;
? ? int minute;
? ? int second;
public:
? ? CLOCK(int newh=0,int newm=0, int news=0);
? ? ~CLOCK();
? ? void init(int newh,int newm, int news);
? ? void run();
};

CLOCK::CLOCK(int newh,int newm, int news)
{
? ? hour=newh;
? ? minute=newm;
? ? second=news;
}
void CLOCK::init(int newh,int newm, int news)
{
? ? hour=newh;
? ? minute=newm;
? ? second=news;
}
void CLOCK::run()
{
? ? while(1)
? ? {
? ? ? ? system("cls");
? ? ? ? cout<<setw(2)<<setfill('0')<<hour<<":";
? ? ? ? cout<<setw(2)<<setfill('0')<<minute<<":";
? ? ? ? cout<<setw(2)<<setfill('0')<<second;
? ? ? ? Sleep(1000);
? ? ? ? if(++second==60)
? ? ? ? {
? ? ? ? ? ? second=0;
? ? ? ? ? ? minute=minute+1;
? ? ? ? ? ? if(minute==60)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? minute=0;
? ? ? ? ? ? ? ? hour=hour+1;
? ? ? ? ? ? ? ? if(hour==24)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? hour=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
CLOCK::~CLOCK()
{
}
int main()
{
? ? CLOCK c;
? ? c.init(23,59,55);
? ? c.run();
? ? system("pause");
? ? return 0;

}

代碼執(zhí)行如下

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

察隅县| 新安县| 元氏县| 白玉县| 玉林市| 株洲县| 冷水江市| 琼海市| 郎溪县| 阜康市| 郎溪县| 黄陵县| 墨竹工卡县| 呼伦贝尔市| 古交市| 揭西县| 巨野县| 东光县| 娄底市| 皋兰县| 慈利县| 新河县| 舞钢市| 渭南市| 固原市| 垫江县| 舒兰市| 沛县| 红桥区| 隆化县| 天峻县| 德兴市| 抚顺市| 长治县| 临夏县| 固阳县| 久治县| 搜索| 康马县| 苍梧县| 太湖县|