#include <bits/stdc++.h>
#include <cstdlib>
#include <unistd.h>
using namespace std;
void sleep(){
_sleep(2*1000);
}
void cls(){
system("cls");
}
void dir()
{
system("dir");
}
void echo(const string& message)
{
cout << message << endl;
}
void openProgram(const string& programName)
{
string command = programName + ".exe";
system(command.c_str());
}
void changeDirectory(const string& directory)
{
if (chdir(directory.c_str()) != 0)
{
cout << "Directory does not exist or switch failed 目录不存在或切换失败" << endl;
}
}
void openImage(const string& imagePath)
{
string command = "start " + imagePath; // 在Windows上使用start命令打开图像文件
system(command.c_str());
}
void help()
{
cout << "简化版DOS系统" << endl;
cout << "可用命令:" << endl;
cout << "dir - 显示当前目录的文件列表" << endl;
cout << "echo <message> - 输出指定的消息" << endl;
cout << "open <program_name> - 打开指定的程序" << endl;
cout << "cd <directory> - 切换到指定的目录" << endl;
cout << "openimage <image_path> - 打开指定的图像文件" << endl;
cout << "help - 显示命令帮助" << endl;
cout << "exit - 退出系统" << endl;
}
int main(){
cout<<"Searching for installation program";
sleep();
cls();
cout<<"Welcome to the 550W installation program"<<endl;
cout<<"========================================";
int a;
cout<<endl;
cout<<"Please enter 1 for installation"<<endl;
cout<<"To exit the installation program, please press 2"<<endl;
cin>>a;
if(a==1){
cls();
sleep();
cout<<"please select language English or 简体中文"<<endl;
cout<<"Press 1 for English or 2 for Simplified Chinese"<<endl;
int b;
cin>>b;
cout<<endl;
if(b==2){
cout<<"当前虚拟硬盘总容量为40GB"<<endl;
cout<<"正在分区...";
sleep();
cout<<"正在安装虚拟系统...";
sleep();
cls();
int c;
cout<<" zsc ";
cout<<"请输入密码:";
cin>>c;
cout<<endl;
if(c==12328330){
cout<<"欢迎使用";
system("color a");
cls();
sleep();
system("color 7");
string command;
cout << "欢迎使用DOS命令模拟程序!输入help获取帮助。" << endl;
while (true)
{
cout << "> ";
getline(cin, command);
if (command == "dir")
{
dir();
}
else if (command.substr(0, 4) == "echo")
{
string message = command.substr(5);
echo(message);
}
else if (command.substr(0, 4) == "open")
{
string programName = command.substr(5);
openProgram(programName);
}
else if (command == "help")
{
help();
}
else if (command == "exit")
{
break;
}
else if (command.substr(0, 2) == "cd")
{
string directory = command.substr(3);
changeDirectory(directory);
}
else if (command.substr(0, 9) == "openimage")
{
string imagePath = command.substr(10);
openImage(imagePath);
}
else
{
cout << "无效的命令,请输入help获取帮助。" << endl;
}
}
cout << "感谢使用DOS命令模拟程序,再见!" << endl;
}else{
return 0;
}
}else if(b==1){
cout<<"The current total virtual hard disk capacity is 40GB"<<endl;
cout<<"Partitioning...";
sleep();
cout<<"Installing virtual system...";
sleep();
cls();
int c;
cout<<" zsc ";
cout<<"Please enter the password:";
cin>>c;
cout<<endl;
if(c==12328330){
cout<<"welcome";
system("color a");
cls();
sleep();
system("color 7");
string command;
cout << "Welcome to the DOS command simulation program! Enter help for help." << endl;
while (true)
{
cout << "> ";
getline(cin, command);
if (command == "dir")
{
dir();
}
else if (command.substr(0, 4) == "echo")
{
string message = command.substr(5);
echo(message);
}
else if (command == "help")
{
help();
}
else if (command.substr(0, 4) == "open")
{
string programName = command.substr(5);
openProgram(programName);
}
else if (command == "exit")
{
break;
}
else if (command.substr(0, 2) == "cd")
{
string directory = command.substr(3);
changeDirectory(directory);
}
else if (command.substr(0, 9) == "openimage")
{
string imagePath = command.substr(10);
openImage(imagePath);
}
else
{
cout << "Invalid command, please enter help for assistance." << endl;
}
}
cout << "Thank you for using the DOS command to simulate the program. Goodbye!" << endl;
}else{
return 0;
}
}else{
cout<<"Invalid operation";
sleep();
cls();
return 0;
}
}else if(a==2){
cout<<"Ejecting virtual CD";
cls();
sleep();
return 0;
}else{
cout<<"Invalid operation";
cls();
sleep();
return 0;
}
return 0;
}
代码自取
请用Dev C++