自用
明天删
/*
管理员初始用户名和密码: admin 123
在主函数 main函数中设置(程序最后面)
*/
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <fstream>
#include <vector>
#include <sstream>
#include <ctime>
using namespace std;
//工具类
class Tool
{
public:
//画横线 len代表横线长度
static void line(int len)
{
cout << "\t";
if(len > 0) while(len--) cout << "-";
cout << endl;
}
};
class Speaker
{
public:
int id; //选手编号
string name; //选手姓名
vector<double> v; //选手成绩
double ave; //平均分
Speaker()
{
}
Speaker(int id, string name, vector<double> v)
{
this->id = id;
this->name = name;
this->v = v;
}
~Speaker()
{
}
static void showHeader()
{
cout << left << setw(12) << "名次";
cout << left << setw(14) << "选手编号";
cout << left << setw(14) << "姓名";
cout << left << setw(16) << "最后得分" << endl;
}
void showInfo()
{
cout << left << setw(14) << id;
cout << left << setw(14) << name;
cout << left << setw(16) << ave << endl;
}
void showDetail()
{
cout << "\t编号:" << id << endl;
cout << "\t姓名:" << name << endl;
for(int i = 0; i < v.size(); ++i)
{
cout << "\t裁判" << i + 1 << "给分:" << v[i] << endl;
}
cout << "\t最后得分:" << ave << endl;
}
};
class Record
{
public:
//初赛共 n 人参加 选取 m = max( 3, (int)(0.5 * n) ) 人 晋级决赛
vector<Speaker> list1; //每一届的比赛记录(初赛)
//决赛共 m 人参加 选取 前三 作为 冠亚季军
vector<Speaker> list2; //每一届的比赛记录(决赛)
Record()
{
}
Record(vector<Speaker> list1, vector<Speaker> list2)
{
this->list1 = list1;
this->list2 = list2;
}
~Record()
{
}
};
class Person
{
public:
string name; //管理员账号
string pwd; //管理员密码
Person()
{
}
Person(string name, string pwd)
{
this->name = name;
this->pwd = pwd;
}
~Person()
{
}
//输出用户表的某一行
void showInfo()
{
cout << left << setw(30) << name;
cout << left << setw(20) << pwd << endl;
}
//输出表头
static void showHeader()
{
cout << left << setw(30) << "用户名";
cout << left << setw(20) << "密码" << endl;
}
void showDetail()
{
cout << "\t用户名:" << name << endl;
cout << "\t密码:" << pwd << endl;
}
};
class SpeechSystem
{
public:
int n1; //第一轮演讲选手数量
int n2; //第二轮演讲选手数量
int m1; //裁判数量
vector<Speaker> s1; //第一轮演讲选手
vector<Speaker> s2; //第二轮演讲选手
vector<Record> rs; //往届比赛记录
vector<Person> ps; //用户
Person a; //管理员
SpeechSystem()
{
}
SpeechSystem(int n1, int n2, int m1, vector<Speaker> s1, vector<Speaker> s2, vector<Record> rs, vector<Person> ps, Person a)
{
this->n1 = n1;
this->n2 = n2;
this->m1 = m1;
this->s1 = s1;
this->s2 = s2;
this->rs = rs;
this->ps = ps;
this->a = a;
}
~SpeechSystem()
{
}
void init()
{
readFile(); //读取往届的比赛信息数据
}
//设置管理员的账号密码
void setAdmin(string name, string pwd)
{
this->a.name = name;
this->a.pwd = pwd;
}
//登录菜单
void menu()
{
string sel = "0";
system("cls");
cout << "\t\t\t*********欢迎来到演讲比赛管理系统***********" << endl;
cout << "\t\t\t你可以进行以下操作:" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 1 管理员登录 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 2 用户登录 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 3 用户注册 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 0 退出 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t请选择【0-3】:";
cin >> sel;
while(sel != "0" && sel != "1" && sel != "2" && sel != "3")
{
cout << "\t\t\t输入不合法,请重新选择【0-3】:";
cin >> sel;
}
if(sel == "1")
{
this->log(sel);
this->menu();
}
else if(sel == "2")
{
this->log(sel);
this->menu();
}
else if(sel == "3")
{
this->reg();
this->menu();
}
else
{
exit(0);
}
}
//注册
void reg()
{
Person p;
cout<<"\t\t\t请填写用户信息:"<<endl;
cout << "\t\t\t用户名:";
bool check = false;
do
{
check = false;
cin >> p.name;
for(int i = 0; i < ps.size(); ++i)
{
if(p.name == ps[i].name)
{
cout<<"\t\t\t该用户名已存在,请重新输入:";
check = true;
break;
}
}
}
while(check);
cout<<"\t\t\t输入密码:";
cin >> p.pwd;
ps.push_back(p);
writeFile();
cout<<"\t\t\t注册成功!"<<endl;
cout<<"\t\t\t";
system("pause");
}
//登录函数:用户和管理员都通过log函数登录
void log(string sel)
{
Person p;
cout << "\t\t\t请填写用户信息:" << endl;
cout << "\t\t\t输入用户名:";
cin >> p.name;
cout << "\t\t\t输入密码:";
cin >> p.pwd;
if(sel == "1")
{
if(p.name == this->a.name && p.pwd == this->a.pwd)
{
cout<<"\t\t\t管理员登录成功!"<<endl;
this->aMenu(a);
}
else
{
cout<<"\t\t\t用户名或密码输入错误"<<endl;
}
cout<<"\t\t\t";
system("pause");
}
else if(sel == "2")
{
bool flag = false;
for(int i = 0; i < this->ps.size(); ++i)
{
if(p.name == ps[i].name && p.pwd == ps[i].pwd)
{
flag = true;
cout<<"\t\t\t用户登录成功!"<<endl;
this->pMenu(p);
}
}
if(!flag) cout<<"\t\t\t用户名或密码输入错误!"<<endl;
cout<<"\t\t\t";
system("pause");
}
}
//用户菜单
void pMenu(Person& p)
{
string sel = "0";
system("cls");
cout << "\t\t\t********欢迎来到北极星影楼预约系统**********" << endl;
cout << "\t\t\t当前用户:" << p.name <<"(普通用户)"<< endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 1 查看往届演讲比赛成绩 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 2 修改密码 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t| 0 注销登录 |" << endl;
cout << "\t\t\t|------------------------------------------|" << endl;
cout << "\t\t\t请选择【0-2】:";
cin >> sel;
while(sel != "0" && sel != "1" && sel != "2")
{
cout << "\t\t\t输入不合法,请重新选择【0-2】:";
cin >> sel;
}
if(sel == "1")
{
this->history(); //查看往届演讲比赛成绩
this->pMenu(p);
}
else if(sel == "2")
{
this->updatePwd(p); // 修改密码
this->pMenu(p);
}
else if(sel == "0") //注销登录
{
this->menu();
}
}
//修改用户密码
void updatePwd(Person& p)
{
while(true)
{
string sel = "0";
system("cls");
cout << "\t****************************************欢迎来到修改密码功能*******************************************" << endl;
cout << "\t当前用户:" << p.name <<"(普通用户)"<< endl;
cout << "\t------------------" << endl;
cout << "\t1 修改密码" << endl;
cout << "\t2 返回主菜单" << endl;
cout << "\t------------------" << endl;
cout << "\t请选择【1-2】:";
cin >> sel;
while(sel != "1" && sel != "2")
{
cout << "\t输入不合法,请重新输入【1-2】:";
cin >> sel;
}
if(sel == "1")
{
cout <<"\t输入当前密码:";
string tmpPwd;
cin>>tmpPwd;
while(tmpPwd != p.pwd)
{
cout<<"\t输入错误,请重新输入:";
cin>>tmpPwd;
}
cout<<"\t输入新密码:";
string newPwd;
cin >> newPwd;
cout << "\t确认修改?(1 是 0 否)" << endl;
cout << "\t请进行选择【0-1】:";
string ch = "0";
cin >> ch;
while(ch != "0" && ch != "1")
{
cout << "\t输入不合法,请重新选择【0-1】:";
cin >> ch;
}
if(ch == "1")
{
for(int i = 0; i < ps.size(); i++)
{
if(ps[i].name == p.name && ps[i].pwd == p.pwd)
{
ps[i].pwd = newPwd;
break;
}
}
writeFile();
cout << "\t修改成功!自动返回登录界面!"<<endl;
cout << "\t";
system("pause");
this->menu();
}
}
else if(sel == "2")
{
break;
}
}
}
//管理员菜单
void aMenu(Person& a)
{
string sel = "0";
system("cls");
cout << "\t\t\t***********欢迎来到演讲比赛流程管理系统************" << endl;
cout << "\t\t\t当前用户:" << a.name <<"(管理员)"<< endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t| 1 设置比赛规则 |" << endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t| 2 开始演讲比赛 |" << endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t| 3 查看往届记录 |" << endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t| 4 清空比赛记录 |" << endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t| 5 管理用户信息 |" << endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t| 0 注销登录 |" << endl;
cout << "\t\t\t|-------------------------------------------------|" << endl;
cout << "\t\t\t开始演讲比赛前请确保已经设置比赛规则!!!" << endl;
cout << "\t\t\t请选择【0-5】:";
cin >> sel;
while(sel != "0" && sel != "1" && sel != "2" && sel != "3" && sel != "4" && sel != "5")
{
cout << "\t\t\t输入不合法,请重新选择【0-5】:";
cin >> sel;
}
if(sel == "1")
{
this->setRule();
this->aMenu(a);
}
else if(sel == "2")
{
this->contest();
this->aMenu(a);
}
else if(sel == "3")
{
this->history();
this->aMenu(a);
}
else if(sel == "4")
{
this->clearSystem();
this->aMenu(a);
}
else if(sel == "5")
{
this->managePs();
this->aMenu(a);
}
else if(sel == "0")
{
this->menu();
}
}
//读取文件
void readFile()
{
//读取文件rs.txt 对应容器 rs
ifstream ifs;
ifs.open("rs.txt", ios::in);
int n = 0;
ifs >> n;
for(int i = 0; i < n; i++)
{
Record r;
int n1 = 0;
ifs >> n1;
for(int j = 0; j < n1; j++)
{
Speaker s;
ifs >> s.id >> s.name;
int vn = 0;
ifs >> vn;
for(int k = 0; k < vn; k++)
{
double score = 0;
ifs >> score;
s.v.push_back(score);
}
ifs >> s.ave;
r.list1.push_back(s);
}
int n2 = 0;
ifs >> n2;
for(int j = 0; j < n2; j++)
{
Speaker s;
ifs >> s.id >> s.name;
int vn = 0;
ifs >> vn;
for(int k = 0; k < vn; k++)
{
double score = 0;
ifs >> score;
s.v.push_back(score);
}
ifs >> s.ave;
r.list2.push_back(s);
}
rs.push_back(r);
}
ifs.close();
//读取文件ps.txt 对应容器 ps
ifstream jfs;
jfs.open("ps.txt", ios::in);
int m = 0;
//读取用户数量
jfs >> m;
for(int i = 0; i < m; i++)
{
Person p;
//按行读取管理员的信息
jfs >> p.name >> p.pwd;
ps.push_back(p);
}
jfs.close();
}
//写入文件
void writeFile()
{
//写入文件rs.txt 对应容器 rs
ofstream ofs;
ofs.open("rs.txt", ios::out);
//写入往届举办的数量(多少届)
ofs << rs.size() << endl;
for (int i = 0; i < rs.size(); i++)
{
ofs << rs[i].list1.size() << endl;
for(int j = 0; j < rs[i].list1.size(); j++)
{
ofs << rs[i].list1[j].id << " " << rs[i].list1[j].name << " " << rs[i].list1[j].v.size() << " ";
for(int k = 0; k < rs[i].list1[j].v.size(); k++) ofs << rs[i].list1[j].v[k] << " ";
ofs << rs[i].list1[j].ave << endl;
}
ofs << rs[i].list2.size() << endl;
for(int j = 0; j < rs[i].list2.size(); j++)
{
ofs << rs[i].list2[j].id << " " << rs[i].list2[j].name << " " << rs[i].list2[j].v.size() << " ";
for(int k = 0; k < rs[i].list2[j].v.size(); k++) ofs << rs[i].list2[j].v[k] << " ";
ofs << rs[i].list2[j].ave << endl;
}
}
ofs.close();
//写入文件ps.txt 对应容器 ps
ofstream pfs;
pfs.open("ps.txt", ios::out);
pfs << ps.size() << endl; //写入注册人数
for (int i = 0; i < ps.size(); i++)
{
pfs << ps[i].name << " " << ps[i].pwd << endl;
}
pfs.close();
}
//设置比赛规则
void setRule()
{
while(true)
{
system("cls");
cout << "\t***********************欢迎来到设置比赛规则功能************************" << endl;
string sel = "0";
Tool::line(20);
cout << "\t1 自定义比赛规则" << endl;
cout << "\t2 使用默认规则" << endl;
cout << "\t3 返回主菜单" << endl;
Tool::line(20);
cout << "\t请进行选择【1-3】:";
cin >> sel;
while(sel != "1" && sel != "2" && sel != "3")
{
cout << "\t输入不合法,请重新选择【1-3】:";
cin >> sel;
}
if(sel == "1")
{
cout << "\t提前说明:" << endl;
cout << "\t1.初赛晋级决赛的选手数量为:50%参加初赛人数 和 3人 中的较大者;" << endl;
cout << "\t2.参加初赛的演讲选手数量需不少于3人;" << endl;
cout << "\t3.裁判的数量不少于1人;" << endl;
cout << "\t4.按平均分从高到低排序,决赛前三名分别为冠军、亚军、季军。" << endl;
cout << "\t输入演讲选手的数量(至少为 3 人 ,建议为 8-12 人):";
cin >> n1;
while(n1 < 3)
{
cout << "\t演讲选手数量过少,需不少于3人!" << endl;
cout << "\t请重新输入演讲选手的数量:";
cin >> n1;
}
//第二轮
n2 = max((int)(0.5 * n1), 3);
cout << "\t输入裁判的数量(建议为 1-3 人):";
cin >> m1;
while(n1 < 1)
{
cout << "\t裁判数量过少,建议为 1-3 人!" << endl;
cout << "\t请重新输入裁判的数量:";
cin >> m1;
}
s1.resize(n1);
for(int i = 0; i < n1; ++i)
{
vector<double> v(m1);
int id = i + 1;
string name = "选手";
name += to_string(id);
Speaker speaker(id, name, v);
s1[i] = speaker;
}
s2.resize(n2);
for(int i = 0; i < n2; ++i)
{
vector<double> v(m1);
int id = 0;
string name = "选手";
name += to_string(id);
Speaker speaker(id, name, v);
s2[i] = speaker;
}
cout << "\t自定义规则设置成功!" << endl;
cout << "\t";
system("pause");
}
else if(sel == "2")
{
cout << "\t默认规则如下:" << endl;
cout << "\t1.一共12名参赛选手,编号为1-12;" << endl;
cout << "\t2.一共3名裁判,编号为1-3;" << endl;
cout << "\t3.按平均分从高到低排序,初赛前6名晋级决赛,决赛前三名分别为冠军、亚军、季军。" << endl;
n1 = 12, m1 = 3, n2 = 6;
cout << "\t默认规则设置成功!" << endl;
s1.resize(n1);
for(int i = 0; i < n1; ++i)
{
vector<double> v(m1);
int id = i + 1;
string name = "选手";
name += to_string(id);
Speaker speaker(id, name, v);
s1[i] = speaker;
}
s2.resize(n2);
for(int i = 0; i < n2; ++i)
{
vector<double> v(m1);
int id = 0;
string name = "选手";
name += to_string(id);
Speaker speaker(id, name, v);
s2[i] = speaker;
}
cout << "\t";
system("pause");
}
else
{
break;
}
}
}
//洗牌算法
void shuffle(vector<int>& v)
{
int n = v.size();
if(n <= 0) return;
srand(time(0));
for(int i = 0; i < n; i++)
{
//保证每次第i位的值不会涉及到第i位以前
int index = i + rand() % (n - i);
swap(v[index], v[i]);
}
}
//遍历Speaker容器
void traverseS(vector<Speaker>& s)
{
int len = 50;
//画横线
Tool::line(len);
cout << "\t";
Speaker::showHeader();
Tool::line(len);
for (int i = 0; i < s.size(); i++)
{
cout << "\t";
cout << left << setw(12) << i + 1;
s[i].showInfo();
}
Tool::line(len);
}
//sort函数的参数
static bool cmp(const Speaker& s1, const Speaker& s2)
{
return s1.ave > s2.ave;
}
//演讲比赛正式流程 : 初赛 + 决赛
void contest()
{
while(true)
{
system("cls");
cout << "\t***************************欢迎来到比赛现场****************************" << endl;
string sel = "0";
Tool::line(20);
cout << "\t1 开始比赛" << endl;
cout << "\t2 返回主菜单" << endl;
Tool::line(20);
cout << "\t请进行选择【1-2】:";
cin >> sel;
while(sel != "1" && sel != "2")
{
cout << "\t输入不合法,请重新选择【1-2】:";
cin >> sel;
}
if(sel == "1")
{
cout << "\t初赛开始!选手正在抽签......" << endl;
vector<int> t1(n1);
for(int i = 0; i < t1.size(); ++i) t1[i] = s1[i].id;
shuffle(t1);
cout << "\t抽签后演讲顺序如下:" << endl << "\t";
for(int i = 0; i < t1.size(); ++i) cout << t1[i] << " ";
cout << endl;
for(int i = 0; i < t1.size(); ++i)
{
double total = 0;
cout << "\t" << t1[i] << "号选手演讲结束!" << endl;
cout << "\t请" << m1 << "位裁判为" << t1[i] << "号选手打分:" << endl;
for(int j = 0; j < m1; ++j)
{
cout << "\t请" << j + 1 << "号裁判为" << t1[i] << "号选手打分 <= 100):";
cin >> s1[t1[i] - 1].v[j];
//判断分数是否在0-100之间,如果不是则重新输入
while(s1[t1[i] - 1].v[j] > 100 || s1[t1[i] - 1].v[j] < 0)
{
cout << "\t请重新输入范围在0-100的分数!!!" << endl;
cout << "\t" << j + 1 << "号裁判给" << t1[i] << "号选手的分数为( <= 100):";
cin >> s1[t1[i] - 1].v[j];
}
//加到总分中 便于后面计算平均分
total += s1[t1[i] - 1].v[j];
}
// 计算平均分
s1[t1[i] - 1].ave = total / m1;
cout << endl;
}
sort(s1.begin(), s1.end(), cmp);
cout << "\t初赛排名如下:" << endl;
traverseS(s1);
cout << "\t初赛结束!取前" << n2 << "名进入决赛!" << endl;
for(int i = 0; i < n2; ++i)
{
s2[i] = s1[i];
}
cout << "\n\t决赛开始!选手正在抽签......" << endl;
vector<int> t2(n2);
for(int i = 0; i < t2.size(); ++i) t2[i] = s2[i].id;
shuffle(t2);
cout << "\t抽签后演讲顺序如下:" << endl << "\t";
for(int i = 0; i < t2.size(); ++i) cout << t2[i] << " ";
cout << endl;
for(int i = 0; i < t2.size(); ++i)
{
double total = 0;
cout << "\t" << t2[i] << "号选手演讲结束!" << endl;
cout << "\t请" << m1 << "位裁判为" << t2[i] << "号选手打分:" << endl;
int cnt = 0;
for(int k = 0; k < n2; k++)
{
if(s2[k].id == t2[i])
{
cnt = k;
break;
}
}
for(int j = 0; j < m1; ++j)
{
cout << "\t请" << j + 1 << "号裁判为" << t2[i] << "号选手打分 <= 100):";
cin >> s2[cnt].v[j];
total += s2[cnt].v[j];
}
s2[cnt].ave = total / m1;
cout << endl;
}
sort(s2.begin(), s2.end(), cmp);
cout << "\t决赛排名如下:" << endl;
traverseS(s2);
cout << "\t决赛结束!本届比赛结果已经存档!" << endl;
Record r(s1, s2);
rs.push_back(r);
writeFile();
cout << "\t";
system("pause");
break;
}
else
{
break;
}
}
}
//查询往届历史记录
void history()
{
while (true)
{
system("cls");
cout << "\t***********************欢迎来到查询往届记录功能************************" << endl;
int n = rs.size();
if(n > 0) cout << "\t已举办 1-" << n << " 共 " << n << " 届演讲比赛!" << endl;
else cout << "\t截至目前未举办任何一届演讲比赛!" << endl;
Tool::line(20);
cout << "\t1 按届数查询" << endl;
cout << "\t2 返回主菜单" << endl;
Tool::line(20);
cout << "\t请进行选择【1-2】:";
string sel = "0";
cin >> sel;
while(sel != "1" && sel != "2")
{
cout << "\t输入不合法,请重新选择【1-2】:";
cin >> sel;
}
if (sel == "1")
{
int key = 0;
bool flag = false;
cout << "\t请输入想要查询的届数(1-" << n << "):";
cin >> key;
cout << "\t查询结果如下:" << endl;
if(1 <= key && key <= rs.size())
{
cout << "\t初赛排名:" << endl;
traverseS(rs[key - 1].list1);
cout << "\t决赛排名:" << endl;
traverseS(rs[key - 1].list2);
}
else
{
cout << "\t没有查询到第" << key << "届的记录!" << endl;
}
cout << endl;
cout << "\t";
system("pause");
}
else
{
break;
}
}
}
//清空往届比赛记录
void clearSystem()
{
while (true)
{
string sel = "0";
system("cls");
cout << "\t***********************欢迎来到清空比赛记录功能************************" << endl;
cout << "\t------------------" << endl;
cout << "\t1 确认清空比赛记录" << endl;
cout << "\t2 返回主菜单" << endl;
cout << "\t------------------" << endl;
cout << "\t请慎重选择【1-2】:";
cin >> sel;
while(sel != "1" && sel != "2")
{
cout << "\t输入不合法,请重新输入【1-2】:";
cin >> sel;
}
if (sel == "1")
{
rs.clear();
cout << "\t清空成功!" << endl;
cout << "\t";
system("pause");
writeFile();
}
else
{
break;
}
}
}
//遍历用户信息 主要用于其它函数调用
void traversePs()
{
int n = 40;
Tool::line(n);
cout << "\t";
Person::showHeader();
Tool::line(n);
for(int i = 0; i < ps.size(); i++)
{
cout<<"\t";
ps[i].showInfo();
}
Tool::line(n);
}
//管理用户功能:包含添加新用户和删除用户 管理员特有权限
void managePs()
{
while(true)
{
system("cls");
cout << "\t**************************欢迎来到管理用户功能*************************" << endl;
cout << "\t普通用户信息表" << endl;
this->traversePs();
string sel = "0";
cout << "\t-----------------" << endl;
cout << "\t1 添加新用户" << endl;
cout << "\t2 删除用户" << endl;
cout << "\t3 返回主菜单" << endl;
cout << "\t-----------------" << endl;
cout << "\t请进行选择【1-3】:";
cin >> sel;
while(sel != "1" && sel != "2" && sel != "3")
{
cout << "\t输入不合法,请重新选择【1-3】:";
cin >> sel;
}
if(sel == "1")
{
Person p;
cout << "\t输入用户名:";
bool check = false;
do
{
check = false;
cin >> p.name;
for(int i = 0; i < ps.size(); ++i)
{
if(p.name == ps[i].name)
{
cout<<"\t该用户名已存在,请重新输入:";
check = true;
break;
}
}
}
while(check);
cout << "\t输入密码:";
cin >> p.pwd;
ps.push_back(p);
writeFile();
cout<<"\t添加成功!"<<endl;
cout<<"\t";
system("pause");
}
else if(sel == "2")
{
string key;
bool flag = false;
cout << "\t请输入待删除的用户名:";
cin >> key;
for (vector<Person>::iterator it = ps.begin(); it != ps.end(); ++it)
{
if (it->name == key)
{
flag = true;
cout << "\t待删除用户的基本信息如下:" << endl;
Tool::line(40);
it->showDetail();
Tool::line(40);
cout << "\t是否确认删除该用户?(1 是 0 否)" << endl;
cout << "\t请进行选择【0-1】:";
string ch = "0";
cin >> ch;
while(ch != "0" && ch != "1")
{
cout << "\t输入不合法,请重新选择【0-1】:";
cin >> ch;
}
if (ch == "0") break;
else
{
ps.erase(it);
writeFile();
cout << "\t删除成功!" << endl;
break;
}
}
}
if (!flag) cout << "\t查无此人,无法删除!\n" << endl;
cout << "\t";
system("pause");
}
else
{
break;
}
}
}
};
int main()
{
SpeechSystem ssm;
//设置管理员账号:admin 密码:123
ssm.setAdmin("admin", "123");
ssm.init(); //初始化
ssm.menu(); //登录菜单
return 0;
}