C++定时关机程序,指定时间关机

  • 时间:2025-12-03 22:08 作者: 来源: 阅读:0
  • 扫一扫,手机访问
摘要:直接上代码 #include <iostream> #include <windows.h> #include <string> #include <conio.h> using namespace std; int main() { int min; int sec; int he_sec; string i

直接上代码


#include <iostream>
#include <windows.h>
#include <string>
#include <conio.h>

using namespace std;

int main()
{
    int min;
    int sec;
    int he_sec;
    string ishut ="";
    string ml ="";

    cout<<"欢迎使用定时关机精灵!";
    Sleep(1500);
    system("cls");
    Sleep(300);

    cout<<"您想要多长时间后关机?
分:";
    cin>>min;
    cout<<"秒:";
    cin>>sec;

    if(min*60+sec>=315360000)
    {
	cout<<"您指定的时间太大了,为了保护程序,程序即将关闭!";
	Sleep(1500);
	exit(0);
    }
    else if(min<0||sec<0)
    {
	cout<<"您指定的时间太小了,为了保护程序,程序即将关闭!";
	Sleep(1500);
	exit(0);
    }

    system("cls");
    cout<<"您确定要在"<<min<<"分"<<sec<<"秒后关机吗?(输入yes为确认,其他为否)
";
    cin>>ishut;
    if(ishut=="yes")
    {
	system("cls");
	he_sec=min*60+sec;
	ml = "shutdown -s -t "+to_string(he_sec);
	system(ml.c_str());
	cout<<"您的电脑将在"<<min<<"分"<<sec<<"秒后关机!";
	int que=getch();
	if(que=='s')
	{
	    que =getch();
	    if(que=='t')
	    {
		que=getch();
	        if(que=='o')
		{
		    que=getch();
		    if(que=='p')
		    {
			system("shutdown -a");
			system("cls");
			cout<<"恭喜您发现了彩蛋,关机已取消!";
			Sleep(1500);
		    }
		}
	    }
	}	
    }
    else
    {
	system("cls");
	cout<<"欢迎您再次使用定时关机精灵!";
	Sleep(1000);
    }
    return 0;
}
    
    
    
  • 全部评论(0)
最新发布的资讯信息
【系统环境|】创建一个本地分支(2025-12-03 22:43)
【系统环境|】git 如何删除本地和远程分支?(2025-12-03 22:42)
【系统环境|】2019|阿里11面+EMC+网易+美团面经(2025-12-03 22:42)
【系统环境|】32位单片机定时器入门介绍(2025-12-03 22:42)
【系统环境|】从 10 月 19 日起,GitLab 将对所有免费用户强制实施存储限制(2025-12-03 22:42)
【系统环境|】价值驱动的产品交付-OKR、协作与持续优化实践(2025-12-03 22:42)
【系统环境|】IDEA 强行回滚已提交到Master上的代码(2025-12-03 22:42)
【系统环境|】GitLab 15.1发布,Python notebook图形渲染和SLSA 2级构建工件证明(2025-12-03 22:41)
【系统环境|】AI 代码审查 (Code Review) 清单 v1.0(2025-12-03 22:41)
【系统环境|】构建高效流水线:CI/CD工具如何提升软件交付速度(2025-12-03 22:41)
手机二维码手机访问领取大礼包
返回顶部