Menu driven program for system control using C++ Last Updated : 13 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Comment More infoAdvertise with us Next Article Timer in C++ using system calls H helloajaysingh1 Follow Improve Article Tags : C++ Practice Tags : CPP Similar Reads Menu-Driven Program for Bank Management System Prerequisite: Switch Case in C/C++Problem Statement: Write a program to build a simple Bank Management System using C++ which can perform the following operations: Open accountDeposit MoneyWithdraw MoneyDisplay Account Approach: Below is the approach to do the above operations: Open Account: This me 10 min read Introduction to C++ Programming Language C++ is a general-purpose programming language that was developed by Bjarne Stroustrup as an enhancement of the C language to add object-oriented paradigm. It is a high-level programming language that was first released in 1985 and since then has become the foundation of many modern technologies like 4 min read Introduction to GUI Programming in C++ In C++, Graphical User Interface (GUI) programming is important in modern application development where users have nice graphics to work with. Although C++ is commonly linked with system programming and game development, it can be an excellent alternative for GUI development. In this article, we wil 5 min read C++ Programming Multiple Choice Questions C++ is the most used and most popular programming language developed by Bjarne Stroustrup. C++ is a high-level and object-oriented programming language. This language allows developers to code clean and efficient code for large applications and software like software/Application development, game de 1 min read Timer in C++ using system calls The task is to create timer without using any graphics or animation. The timer will be made using system calls wherever necessary. Timer in this context means a stopwatch with up-counting of time.The timer is created in Linux. Following system calls of Linux are used: sleep() : It will make the prog 2 min read Basic Graphic Programming in C++ Introduction So far we have been using C language for simple console output only.  Most of us are unaware that using C++, low level graphics program can also be made. This means we can incorporate shapes,colors and designer fonts in our program. This article deals with the steps to enable the DevC++ 2 min read Like