您的位置:首页 > 编程语言 > C语言/C++

C++写出关机、重启、注销、休眠等操作:

2013-11-08 15:39 609 查看
C++写出关机、重启、注销、休眠等操作,上代码:

#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
	int i;
	cout<<"1、关机"<<endl
		<<"2、重启"<<endl
		<<"3、注销"<<endl
		<<"4、休眠"<<endl
		<<"5、取消"<<endl;
	cin>>i;
	switch(i)
	{
	case 1:{
		int j;
		cout<<"1、关机"<<endl
			<<"2、定时关机"<<endl
			<<"3、取消定时关机"<<endl
			<<"4、取消"<<endl;
		cin>>j;
		switch(j)
		{
		case 1:
			system("shutdown -s -t 0");
			break;
		case 2:{
			int t;
			cout<<"1、30分钟后关机"<<endl
				<<"2、60分钟后关机"<<endl
				<<"3、90分钟后关机"<<endl
				<<"4、120分钟后关机"<<endl
				<<"5、取消"<<endl;
			cin>>t;
			switch(t)
			{
			case 1:
				system("shutdown -s -t 1800");
				break;
			case 2:
				system("shutdown -s -t 3600");
				break;
			case 3:
				system("shutdown -s -t 5400");
				break;
			case 4:
				system("shutdown -s -t 7200");
				break;
			case 5:
				return 0;
			default:
				return 0;
			}
			break;
		}
		case 3:
			system("shutdown -a");
			break;
		case 4:
			return 0;
		default:
			return 0;
		}
		break;
	}
    case 2:
		system("shutdown -r");
		break;
    case 3:
		system("shutdown -l");
		break;
    case 4:
		system("shutdown -h");
		break;
    case 5:
		return 0;
	default:
		return 0;
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: