網課c++第一次作業,學到了iomanip庫檔案里的setw(),setfill()等函式,自己完成作業時搜著學到了Windows.h庫檔案里的sleep(),system("cls")兩個函式的用法,下面是最終實作的結果,丑到可以忽略代碼,,

代碼(含注釋)如下:
1 /* project:ugly clock 2 * auther :ugly mb 3 * dispaly: 4 * ------------ 5 * ||xx:xx:xx|| 6 * ------------ 7 */ 8 #include <iostream> 9 #include <iomanip> //呼叫setw,setfill 10 #include <windows.h> //呼叫sleep,system 11 using namespace std; 12 13 int main(void) 14 { 15 /***************設定當前時間****************/ 16 int hour=23,min=59,sec=50; 17 /*****************計時程序*****************/ 18 while(1){ 19 sec++; 20 if(sec==60){ //秒鐘記到60清0,分鐘進1位 21 sec=0;min++; 22 if(min==60){ //分鐘記到60清0,時鐘進3位 23 min=0;hour++; 24 if(hour==24){hour=0;}//時鐘記到24時清0 25 } 26 } 27 Sleep(1000);system("cls"); //sleep(x):延時x毫秒,system("cls"):清屏,這里清上一秒的內容 28 /*****************顯示函式*****************/ 29 cout<<"--------------"<<endl; 30 cout<<"|| "<<setfill('0')<<setw(2)<<hour<<":"<<setw(2)<<min<<":"<<setw(2)<<sec<<" ||"<<endl; 31 cout<<setw(14)<<setfill('-')<<"-"<<endl; 32 } 33 }
互動環節:求各位施舍我點改進建議,如有詳細方案,甚是感激
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/67289.html
標籤:C++
上一篇:二叉搜索樹3
下一篇:洛谷P1014 Cantor表
