Prerequisite: Switch-case in C/C++
Problem Statement:
Write a menu-driven program to control your system such as shutdown, restart, log off, manual shutdown settings, abort the shutdown, and exit, using Switch-case.
Approach: The idea is to use system() in C. This function is used to invoke operating system commands from the C++ program.
In this program to use some system commands listed below:
- Shutdown: To shutdown system, use system() function and command shutdown with option s as:
system("C:\\WINDOWS\\System32\\shutdown/s") - Restart: To restart system, use system() function and command shutdown with option r as:
system("C:\\WINDOWS\\System32\\shutdown/r") - Log off: To logoff system, use system() function and command shutdown with option l as:
system("C:\\WINDOWS\\System32\\shutdown/l") - Manual Shutdown: To manual shutdown system, use system() function and command shutdown with option i as:
system("C:\\WINDOWS\\System32\\shutdown/i") - Abort the Shutdown: To abort the shutdown system, use system() function and command shutdown with option a as:
system("C:\\WINDOWS\\System32\\shutdown/a")
Below implementation of the above system function and commands:
CPP
// Menu driven program in CPP to // system control using system() // function and command with option #include <iostream> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <windows.h> void printMenu(); // Function to shutdown the computer void shutDown() { // Tp clears the screen system("cls"); printf("\nshuttingg down..\n"); // System function call to // shutdown system system("C:\\WINDOWS\\System32\\shutdown /s"); // To clears the screen system("cls"); } // Function to restart the computer void reStart() { // Clears the screen system("cls"); printf("\nRestart in 30 seconds ..."); // System function call to // restart system system("C:\\WINDOWS\\system32\\shutdown /r"); } // Function to log off user void logOff() { // To clears the screen system("cls"); printf("\n Shutting down under 30 seconds... "); // System function call to log off user system("C:\\WINDOWS\\system32\\shutdown /l"); } // Function to open manualShutdown // shutdown dialog box void manualShutdown() { // To clears the screen system("cls"); // System function call to manual shutdown system("C:\\WINDOWS\\System32\\shutdown /i"); } void abortShutdown() { // To clears the screen system("cls"); // System function call to aboart shutdown system("C:\\WINDOWS\\System32\\shutdown /a"); } // Function to take user choices and perform // the appropriate operation void selectMenu() { int choice; printf("\n Enter your choice : "); scanf("%d", &choice;); switch (choice) { case 1: shutDown(); break; case 2: reStart(); break; case 3: logOff(); break; case 4: manualShutdown(); break; case 5: abortShutdown(); break; case 6: printf("\n Exiting... \n\n"); printf("Exiting in 3 seconds...\n"); Sleep(3000); exit(1); default: printf("\ninvalid choice Try again \n"); printMenu(); } } // Function to print all the menus void printMenu() { // Set output color to blue // background and white foreground system("color 1F"); printf("\n"); // Create Menu printf("\xB2 \xB2\xB2\xB2\xB2\xB2\xB2\xB2" "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2" "\xB2\xB2\xB2\xB2\xB2 SYSTEM CONTROL \xB2" "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2" "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2" "\xB2\xB2 \xB2"); printf("\n ______________________________" "_________________________________"); printf("\n|\t\t\t\t\t\t\t\t|"); printf("\n|\t\t\t\t\t\t\t\t|"); printf("\n|\t\t\t 1. Shutdown Computer \t\t\t|"); printf("\n|\t\t\t 2. Restart Computer \t\t\t|"); printf("\n|\t\t\t 3. Log off \t\t\t\t|"); printf("\n|\t\t\t 4. Manual Shutdown Settings\t\t|"); printf("\n|\t\t\t 5. Abort Shutdown \t\t\t|"); printf("\n|\t\t\t 6. Exit \t\t\t\t|"); printf("\n|\t\t\t\t\t\t\t\t|"); printf("\n|\t\t\t\t\t\t\t\t|"); printf("\n|\t\t\t\t\t\t\t\t|"); printf("\n|\t\t\t\t\t\t\t\t|"); printf("\n\xB2_________________________________" "______________________________\xB2\n"); // Function call for select options selectMenu(); } // Driver Code int main() { // Function Call printMenu(); return 0; } |
Output:
Below is the Output of the above program:
Recommended Posts:
- Menu-Driven Program for Bank Management System
- Menu-Driven program using Switch-case in C
- Menu Driven C++ Program for a Simple Calculator
- Menu-Driven program to implement Travel Agency
- Menu-Driven program for Phone Directory
- Project Idea | Traffic Signal Control (Automatic)
- C/C++ program to add N distances given in inch-feet system using Structures
- Program for Deadlock free condition in Operating System
- Program for Employee Management System
- Project Idea | Attendance System Using Smart Card
- Timer in C++ using system calls
- Project Idea | Bus Notification System Using Crowdsourcing
- Python | System hardening and compliance reports using Lynis
- How to check if a directory or a file exists in system or not using Shell Scripting?
- Getting System and Process Information Using C Programming and Shell in Linux
- Voting System Project Using Django Framework
- Pizza Shop Billing System using Java Swing
- Project Idea | (A.T.L.A.S: App Time Limit Alerting System)
- Project Idea | (Personalized real-time update system)
- Project Idea | (Project Approval System)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

