用户:Pixel_Craft查看:0 回复:0 评论:0 创建时间:2020-03-25T14:43:03
代码如下:
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
using namespace std;
string User_name[51]; //所有人的用户名
string Password[51]; //所有人的密码
char restriction[51]; //所有人的限权
string in_User; //目前在哪一个用户
string log_on_User; //用户输入的用户名
string log_on_Password; //用户输入的密码
char in_User_restriction; //目前用户的权限
int i = 0; //目前用户的总数
int id; //用户的ID
char choice; //用户的选择
char bell = 7; //鸣钟控制字符
int break_ = 0; //用于退出循环
string no_log_in = "未注册用户";//未注册的用户名
void run_command()
{
/*
.rbx是运行框架(run box)的缩写(然而并不存在)
.ftf是函数文件(function file)的后缀名(然而并不存在)
.exe是可执行程序
.lgp是语言包(然而并不存在)
*/
cout<<"正在启动登录中..."<<endl;
cout<<"正在下载D:\\命令行系统\\系统程序\\run_box.rbx"<<endl;
cout<<"正在下载D:\\命令行系统\\系统程序\\log_on.ftf"<<endl;
cout<<"正在下载D:\\命令行系统\\系统程序\\run_box.rbx"<<endl;
cout<<"正在下载D:\\命令行系统\\系统程序\\calculator.exe"<<endl;
cout<<"正在下载D:\\命令行系统\\系统程序\\command.ftf"<<endl;
cout<<"正在下载D:\\命令行系统\\系统程序\\log_of.ftf"<<endl;
cout<<"正在下载D:\\命令行系统\\语言\\Chinese.lgp"<<endl;
cout<<"正在下载D:\\命令行系统\\游戏\\game_run.rbx"<<endl;
cout<<"构建完成!"<<endl;
}
void log_on(void) //登录
{
int yes = 0;
cout<<"========================登录========================"<<endl;
cout<<"用户名:";
cin>>log_on_User;
cout<<"密码:";
cin>>log_on_Password;
cout<<"登入中..."<<endl;
for(id=1;id<11;id++)
{
if((User_name[id] == log_on_User)&&(Password[id]==log_on_Password))
{
yes = 1;
in_User=User_name[id];
in_User_restriction=restriction[id];
cout<<"登入成功!"<<endl;
cout<<"你好!"<<in_User<<"!"<<endl;
cout<<"你的权限为:";
switch(in_User_restriction)
{
case 'v':cout<<"访客"<<endl;break;
case 'o':cout<<"普通用户"<<endl;break;
case 'a':cout<<"管喵"<<endl;break;
default:cout<<"无效的数值"<<endl;cout<<"程序出错,请重启此程序"<<endl;break;
}
cout<<"命令行系统 [版本 0.6.0]"<<endl;
cout<<"输入help获得帮助"<<endl;
break;
}
}
if(yes == 0)
{
cout<<"用户名/密码错误!"<<endl;
cout<<"你好!访客!";
}
cout<<endl;
}
void register_(void) //注册
{
cout<<"========================注册========================"<<endl;
cout<<"温馨提示:请不要把用户名设置为未注册用户"<<endl;
cout<<" 最多注册50个用户!当前用户数量:"<<endl;
cout<<" "<<i<<"个。"<<endl;
if (i<= 50)
{
cout<<"用户名:";
cin>>User_name[i];
cout<<"密码:";
cin>>Password[i];
cout<<"限权:"<<endl;
cout<<"[访客(V)] [普通用户(O)] [管喵(A)]"<<endl;
cin>>choice;
if ((((choice == 'V')||(choice == 'v'))||((choice == 'O')||(choice == 'o')))||((choice == 'A')||(choice == 'a')))
{
if ((choice == 'V')||(choice == 'v'))//访客
{
restriction[i] = 'v';
}
if ((choice == 'O')||(choice == 'o'))//普通用户
{
restriction[i] = 'o';
}
if ((choice == 'A')||(choice == 'a'))//管喵
{
restriction[i] = 'a';
}
}
else
{
restriction[i] = 'o';//默认为普通用户
}
if (User_name[i] != no_log_in)//检测用户名是否为未注册用户
{
cout<<"注册成功!"<<endl;
cout<<"用户名:"<<User_name[i]<<endl;
cout<<"密码:"<<Password[i]<<endl;
i++;
}
else
{
cout<<"注册失败!"<<endl;
if (i>1)
{
cout<<bell;
cout<<"正在跳转中...[10%]"<<endl;
cout<<"正在跳转中...[20%]"<<endl;
cout<<"正在跳转中...[30%]"<<endl;
cout<<"正在跳转中...[40%]"<<endl;
cout<<"正在跳转中...[50%]"<<endl;
cout<<"正在跳转中...[60%]"<<endl;
cout<<"正在跳转中...[70%]"<<endl;
cout<<"正在跳转中...[80%]"<<endl;
cout<<"正在跳转中...[90%]"<<endl;
cout<<"正在跳转中...[100%]"<<endl;
log_on(); //进入登录状态
}
else
{
register_();//重新注册
}
}
cout<<endl;
}
else
{
cout<<"用户数量达到最大,即将进入登录状态"<<endl;
cout<<bell;
cout<<"正在跳转中...[10%]"<<endl;
cout<<"正在跳转中...[20%]"<<endl;
cout<<"正在跳转中...[30%]"<<endl;
cout<<"正在跳转中...[40%]"<<endl;
cout<<"正在跳转中...[50%]"<<endl;
cout<<"正在跳转中...[60%]"<<endl;
cout<<"正在跳转中...[70%]"<<endl;
cout<<"正在跳转中...[80%]"<<endl;
cout<<"正在跳转中...[90%]"<<endl;
cout<<"正在跳转中...[100%]"<<endl;
log_on();
}
}
void log_off(void) //注销
{
cout<<"========================注销========================"<<endl;
cout<<bell;
cout<<"正在注销用户"<<in_User<<"中..."<<endl;
cout<<"正在清空屏幕..."<<endl;
system("cls");
in_User = "未注册用户";
cout<<"注销成功!";
cout<<"请选择登录或注册账号"<<endl;
cout<<"[登录(L)] [注册(R)]"<<endl;
cin>>choice;
if((choice =='R')||(choice =='r'))
{
register_();
log_on();
}
else
{
log_on();
}
}
//以下为命令代码
void calculator(void)//计算器
{
cout<<"========================计算器========================"<<endl;
cout<<"正在启动计算器..."<<endl;
cout<<"正在创建运行框架..."<<endl;
cout<<"正在打开本地文件D:\\命令行系统\\系统程序\\run_box.rbx"<<endl;//.rbx是运行框架(run box)的缩写(然而并不存在)
cout<<"正在打开本地文件D:\\命令行系统\\系统程序\\calculator.exe"<<endl; //.exe是可执行程序
cout<<"构建完成!"<<endl;
cout<<"启动完成!"<<endl;
float a,b,jiego;
int yunsuanfu;
char pyunsuanfu;
yunsuanfu = 1;
cout<<"请输入第一个数:";
cin>>a;
cout<<"请输入第二个数:";
cin>>b;
cout<<"请输入运算符号编号\n +:1 -:2 *:3 /:4"<<endl;
cin>>yunsuanfu;
cout<<"正在计算……"<<endl;
switch(yunsuanfu)
{
case 1:jiego = a+b;pyunsuanfu = '+';cout<<a<<pyunsuanfu<<b<<"="<<jiego<<endl;break;
case 2:jiego = a-b;pyunsuanfu = '-';cout<<a<<pyunsuanfu<<b<<"="<<jiego<<endl;break;
case 3:jiego = a*b;pyunsuanfu = '*';cout<<a<<pyunsuanfu<<b<<"="<<jiego<<endl;break;
case 4:jiego = a/b;pyunsuanfu = '/';cout<<a<<pyunsuanfu<<b<<"="<<jiego<<endl;break;
default:cout<<"错误:找不到编号为\""<<yunsuanfu<<"\"的运算符"<<endl;break;
}
}
void list(void)//用户列表
{
int num;
cout<<"========================用户列表========================"<<endl;
for (num=1;num<=50;num++)
{
switch(restriction[num])
{
case 'v':cout<<setw(2)<<num<<" 用户名"<<setw(20)<<User_name[num]<<" 密码"<<setw(20)<<Password[num]<<setw(8)<<"访客"<<endl;break;
case 'o':cout<<setw(2)<<num<<" 用户名"<<setw(20)<<User_name[num]<<" 密码"<<setw(20)<<Password[num]<<setw(8)<<"普通用户"<<endl;break;
case 'a':cout<<setw(2)<<num<<" 用户名"<<setw(20)<<User_name[num]<<" 密码"<<setw(20)<<Password[num]<<setw(8)<<"管喵"<<endl;break;
default:cout<<setw(2)<<num<<" 用户名"<<setw(20)<<User_name[num]<<" 密码"<<setw(20)<<Password[num]<<setw(8)<<"未知限权"<<endl;;break;
}
}
}
void clear(void)
{
cout<<"========================清屏========================"<<endl;
cout<<"正在清空..."<<endl;
cout<<"已清空屏幕"<<endl;
system("cls");
}
void user(void)
{
string command;
int userID,ID;
string parameter,parameter2,parameter3;
char r;
cout<<"========================用户管理========================"<<endl;
cout<<"正在查找现有用户"<<endl;
for (ID=1;ID<=50;ID++)
{
if (User_name[ID] != "")
{
switch(restriction[ID])
{
case 'v':cout<<setw(2)<<ID<<" 用户名"<<setw(20)<<User_name[ID]<<" 密码"<<setw(20)<<Password[ID]<<setw(8)<<"访客"<<endl;break;
case 'o':cout<<setw(2)<<ID<<" 用户名"<<setw(20)<<User_name[ID]<<" 密码"<<setw(20)<<Password[ID]<<setw(8)<<"普通用户"<<endl;break;
case 'a':cout<<setw(2)<<ID<<" 用户名"<<setw(20)<<User_name[ID]<<" 密码"<<setw(20)<<Password[ID]<<setw(8)<<"管喵"<<endl;break;
default:cout<<setw(2)<<ID<<" 用户名"<<setw(20)<<User_name[ID]<<" 密码"<<setw(20)<<Password[ID]<<setw(8)<<"未知限权"<<endl;;break;
}
}
}
cout<<"========================================================"<<endl;
cout<<"查找完毕!"<<endl;
cout<<endl;
cout<<"管理菜单:"<<endl;
cout<<setw(20)<<"password <用户ID:整数> <新密码:字符串>"<<" "<<"更改密码"<<endl;
cout<<setw(20)<<"delete <用户ID:整数>"<<" "<<"删除用户"<<endl;
cout<<setw(20)<<"name <用户ID:整数> <新用户名:字符串>"<<" "<<"更改用户名"<<endl;
cout<<setw(20)<<"new <用户名:字符串> <密码:字符串> <限权:字符串(v:访客,o:普通用户,a:管喵)>"<<" "<<"新建用户"<<endl;
cin>>command;
if (command == "password")
{
cin>>userID>>parameter;
}
if (command == "delete")
{
cin>>userID;
}
if (command == "name")
{
cin>>userID>>parameter;
}
if (command == "new")
{
cin>>parameter>>parameter2>>r;
}
/*
User_name[用户ID]所有人的用户名
Password[用户ID]所有人的密码
restriction[用户ID];所有人的限权
*/
if (command == "password")
{
if (User_name[userID] == "")
{
cout<<"此用户不存在!无法修改密码!"<<endl;
}
else
{
Password[userID] = parameter;
cout<<"更改密码成功!"<<endl;
cout<<"用户名:"<<User_name[userID]<<endl;
cout<<"密码:"<<Password[userID]<<endl;
}
}
if (command == "delete")
{
if (User_name[userID] == in_User)
{
cout<<"你不能删除你的的账号!"<<endl;
}
else
{
cout<<"正在删除..."<<endl;
Password[userID] = "";
cout<<"正在清除用户名..."<<endl;
User_name[userID] = "";
cout<<"正在清除密码..."<<endl;
restriction[userID] = 0;
cout<<"正在清除用户权限..."<<endl;
cout<<"已删除此用户!"<<endl;
cout<<"PS:用户ID还没有完全清除。"<<endl;
}
}
if (command == "name")
{
if (User_name[userID] == "")
{
cout<<"此用户不存在!无法修改密码!"<<endl;
}
else
{
User_name[userID] = parameter;
cout<<"更改用户名成功!"<<endl;
cout<<"用户名:"<<User_name[userID]<<endl;
cout<<"密码:"<<Password[userID]<<endl;
}
}
if (command == "new")
{
cout<<"正在启动登录程序..."<<endl;
cout<<"正在创建运行框架..."<<endl;
cout<<"正在打开本地文件D:\\命令行系统\\系统程序\\run_box.rbx"<<endl;//.rbx是运行框架(run box)的缩写(然而并不存在)
cout<<"正在打开本地文件D:\\命令行系统\\系统程序\\log_on.ftf"<<endl; //.ftf是函数文件(function file)的后缀名(然而并不存在)
cout<<"构建完成!"<<endl;
cout<<"启动完成!"<<endl;//以下代码来自注册代码,已简化
if (i<= 50)
{
User_name[i] = parameter;
Password[i] = parameter2;
choice = r;
if ((((choice == 'V')||(choice == 'v'))||((choice == 'O')||(choice == 'o')))||((choice == 'A')||(choice == 'a')))
{
if ((choice == 'V')||(choice == 'v'))//访客
{
restriction[i] = 'v';
}
if ((choice == 'O')||(choice == 'o'))//普通用户
{
restriction[i] = 'o';
}
if ((choice == 'A')||(choice == 'a'))//管喵
{
restriction[i] = 'a';
}
}
else
{
restriction[i] = 'o';//默认为普通用户
}
if (User_name[i] != no_log_in)//检测用户名是否为未注册用户
{
cout<<"注册成功!"<<endl;
cout<<"用户名:"<<User_name[i]<<endl;
cout<<"密码:"<<Password[i]<<endl;
i++;
}
else
{
cout<<"注册失败!"<<endl;
cout<<bell;
cout<<endl;
}
}
else
{
cout<<"用户数量达到最大!无法注册!"<<endl;
cout<<bell;
}
}
}
void about(void)
{
cout<<"命令行系统 [版本 0.6.0]"<<endl;
cout<<"更新日志:"<<endl;
cout<<"0.1.0:开发此系统,只能登录、注册,且用户名/密码只能为数字"<<endl;
cout<<"0.2.0:新增计数器、帮助、注销命令"<<endl;
cout<<"0.3.0:优化数据结构,用户名/密码都可以输入中文/英文"<<endl;
cout<<"0.4.0:新增访客模式,只能使用log_off(注销)和help(帮助)命令"<<endl;
cout<<"0.5.0:新增用户限权,有访客、普通用户、管喵。"<<endl;
cout<<"0.6.0:新增list(用户列表)和user(用户管理)命令,只能在管喵限权使用"<<endl;
cout<<"0.7.0:优化user(用户管理)命令,可以不注销注册账号,只能在管喵限权使用"<<endl;
cout<<"0.8.0:新增运行其它函数/程序的代码的提示(然而这只是为了好看)"<<endl;
}
void help(void)//帮助
{
cout<<"========================帮助========================"<<endl;
cout<<setw(12)<<"help"<<" "<<"查看帮助"<<endl;
cout<<setw(12)<<"calculator"<<" "<<"计算器"<<endl;
cout<<setw(12)<<"log_off"<<" "<<"注销"<<endl;
cout<<setw(12)<<"list"<<" "<<"查看用户列表"<<endl;
cout<<setw(12)<<"clear"<<" "<<"清屏"<<endl;
cout<<setw(12)<<"user"<<" "<<"用户管理"<<endl;
cout<<setw(12)<<"about"<<" "<<"关于"<<endl;
}
void commands(void)
{
string command; //用于输入的命令
if (in_User == no_log_in)
{
cout<<"访客>";
cin>>command;
cout<<endl;
if(command == "help")
{
cout<<"========================帮助========================"<<endl;
cout<<setw(12)<<"log_off"<<" "<<"注销"<<endl;
}
else
{
if(command == "log_off")
{
log_off();
}
else
{
cout<<"你需要普通用户的权限才能使用此命令!"<<endl;
}
}
}
else
{
if (in_User_restriction == 'v')
{
cout<<in_User<<">";
cin>>command;
cout<<endl;
if(command == "help")
{
cout<<"========================帮助========================"<<endl;
cout<<setw(12)<<"log_off"<<" "<<"注销"<<endl;
}
else
{
if(command == "log_off")
{
log_off();
}
else
{
cout<<"你需要普通用户的权限才能使用此命令!"<<endl;
}
}
}
else
{
cout<<in_User<<">";
cin>>command;
cout<<endl;
if (command == "help")//帮助
{
help();
}
if (command == "calculator")//计算器
{
calculator();
}
if (command == "log_off")//注销
{
log_off();
}
if (command == "list")//用户列表
{
if (in_User_restriction == 'a')
{
list();
}
else
{
cout<<"你需要管喵的权限才能使用此命令!"<<endl;
}
}
if (command == "clear")
{
clear();
}
if (command == "user")//用户管理
{
if (in_User_restriction == 'a')
{
user();
}
else
{
cout<<"你需要管喵的权限才能使用此命令!"<<endl;
}
}
if (command == "about")
{
about();
}
}
}
}
int main()
{
cout<<"正在初始化系统..."<<endl;
cout<<"作者:Pixel_Craft"
run_command();
cout<<endl;
i=1;
in_User=no_log_in;
register_();
log_on();
while (1)
{
commands();
}
return 0;
}
————————分割线————————
代码如上。
最近几个月都没在编程猫里发作品了,这个C++作品希望大家能喜欢。模拟了登录、注册、注销等和账号有关的操作。
PS:管喵可以管理用户。