Program to Shutdown and restart
To shut down or restart your computer, you just have to call the function system() (of stdlib.h) with complete path.
Algorithm
- Create a menu having options shutdown, restart, and exit.
- Users will choose from the options.
- Use a switch case.
Case 1: system(“C:\\windows\\system32\\shutdown /s /t 30 \n\n”)
Case 2: system(“C:\\windows\\system32\\shutdown /r /t 30\n\n”)
Case 3: exit the program.
- The system will perform the chosen option.
Code
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int choice;
cout << "1. Shutdown Your Computer \n";
cout << "2. Restart Your Computer \n";
cout << "3. Exit\n";
cout << "\n Enter your choice : ";
cin >> choice;
switch (choice)
{
case 1:
cout << "System will shutdown after 30 seconds \n";
system("C:\\windows\\system32\\shutdown /s /t 30 \n\n");
break;
case 2:
cout << "System will restart in 30 seconds\n";
system("C:\\windows\\system32\\shutdown /r /t 30\n\n");
break;
case 3:
exit(0);
default:
cout << "Wrong Choice!!\n";
}
return 0;
}
Report Error/ Suggestion