首支應用程式---關機程式 ===================== ```cpp= //2018/03/24 #include<iostream> #include<string> #include<sstream> using namespace std; int FindnotNumber(string s)//判斷是否全為數字 { for(int j=0;j<s.size();j++) { if(s[j]>39 && s[j]<30){return -1;} } } void cm(string sec) { if(sec=="a")//中斷 { system("shutdown -a"); } else if(sec=="r")//重新啟動 { cout<<"即將執行重新關機"<<endl; cout<<"請操作者保持在電腦前,以利需要相關密碼或選擇介面操作執行"<<endl; system("pause"); system("shutdown -r"); } else if(sec=="0"||sec=="now")//立刻關機 { cout<<"立刻關機?"<<endl; cout<<"輸入 y 以繼續"<<endl; cout<<"輸入 n 以重啟程式"<<endl; string s;cin>>s; if(s=="n"||s=="N"||s=="0") { system("start 關機.exe"); system("exit"); } else if(s=="y"||s=="Y"||s=="1") { system("pause"); system("shutdown -p"); } else { cout<<"無效答案"<<endl; system("pause"); system("start 關機.exe"); system("exit"); } } /*else if(sec=="up")//更新 { system("cd C:/WINDOWS/system32"); system("svchost.exe -k netsvcs"); cout<<"更新程式已啟動"<<endl; cout<<"提醒:更新結束後請務必到"<<endl; cout<<"本機(滑鼠右鍵) >> 管理 >> 服務與應用程式 >> 服務 >> Windows update "<<endl; cout<<"手動關閉自動更新"<<endl; system("pause"); }*/ else if(sec=="h"||sec=="?")//幫助 { cout<<"指令說明:"<<endl; cout<<"1.輸入 數字(正整數) 為該\"秒數\"後關機."<<endl; cout<<"2.輸入 0 或 now 為即刻關機,並會再次確認."<<endl; cout<<"3.輸入 a 為取消該次關機排程."<<endl; // cout<<"4.輸入 up 為進行更新."<<endl; cout<<"5.輸入 h 或 ? 顯示說明."<<endl; cout<<"6.輸入 r 為重新啟動."<<endl; cout<<"7.輸入 bye 或 Ctrl + C 結束程式."<<endl; cout<<"註:其餘指令皆為無效,即刻關閉."<<endl; system("pause"); system("start 關機.exe"); system("exit"); } else if(sec=="bye")//關閉 { system("exit"); } else if(FindnotNumber(sec)==-1)//指令與數字外的處理 { cout<<"無效指令,將重新啟動程式"<<endl; system("pause"); system("start 關機.exe"); system("exit"); } else//時間(數字) { cout<<"將在"<<sec<<"秒後關機"<<endl; cout<<"確定?"<<endl; cout<<"輸入 y 以繼續"<<endl; cout<<"輸入 n 以重啟程式"<<endl; string a;cin>>a; if(a=="n"||a=="N"||a=="0") { system("start 關機.exe"); system("exit"); } else if(a=="y"||a=="Y"||a=="1") { system("cd C:/WINDOWS/System32"); string s="shutdown -s -t "+sec; system(s.c_str()); } else { cout<<"無效答案"<<endl; system("pause"); system("start 關機.exe"); system("exit"); } } } int main() { cout<<"輸入關機時間或其他指令(輸入h或?顯示說明):"<<endl; string sec; cin>>sec; cm(sec); return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up