我们在入门C++后都会自己设计一个系统,来检验自己的c++基础是否牢固。而博主最近在某站上跟着黑马一起看视频学习c++,其中有个机房预约系统,博主也跟着敲了一下,接下来让我们一起来看看程序吧。
在设计一个系统之前我们应该思考系统的结构,系统的功能以及客户的需求等等。我设计的这个系统有以下功能:学生,老师及管理员三种身份登入,学生功能:申请预约,查看预约,取消预约
老师功能:查看预约,处理预约信息
管理员功能:添加用户成员,查看机房信息,清空订单信息,查看成员信息。
有任何问题请在下面评论,谢谢。
接下来直接上代码:
#pragma once
#include
#include
#include
#include "filename.h"
#include"order.h"
using namespace std;
class computerroom
{
public:
computerroom();
~computerroom();
int m_num;
int m_size;
int m_capatity;
vector<computerroom> vCmp;//存储机房信息
};
#pragma once
#define ROOTNAME "root.txt"
#define TEACHERNAME "teacher.txt"
#define STUDENTNAME "student.txt"
#define COMPUTERNAME "computer.txt"
#define ORDERNAME "order.txt"
#pragma once
#include
#include
using namespace std;
class identity
{
public:
virtual void m_login() = 0;
virtual ~identity();
string m_name;
string m_password;
};
#pragma once
#include
#include
#include
#include
#include
#include"computerroom.h"
#include"filename.h"
using namespace std;
class Order
{
public:
Order();
~Order();
void update_order();//更新预约信息
map<int, map<string, string>> M;//存储订单信息
};
#pragma once
#include "identity.h"
#include "filename.h"
#include "teacher.h"
#include "student.h"
#include "computerroom.h"
#include
#include
#include
#include
using namespace std;
class root :public identity
{
public:
root();
~root();
root(string name,string password);
virtual void m_login();//登入菜单
void addroot();//添加账号
void showroot();//查看账号
void showcomputer();//查看机房信息
void clearfile();//清理预约信息
};
#pragma once
#include "identity.h"
#include"order.h"
#include
#include
#include
#include"computerroom.h"
#include "filename.h"
#include
using namespace std;
class student :public identity
{
public:
student();
~student();
student(int id, string name, string password);
virtual void m_login();//登入菜单
void order();//预约机房
void show_my();//查看自身预约
void show_all();//查看所有预约
void delete_order();//取消预约
int m_id;
};
#pragma once
#include "identity.h"
#include "filename.h"
#include "order.h"
#include
#include
#include
using namespace std;
class teacher :public identity
{
public:
teacher();
~teacher();
teacher(int id,string name, string password);
virtual void m_login();//登入菜单
void showorder();//查看所有预约信息
void dealorder();//处理预约信息
int m_id;
};
#include"computerroom.h"
computerroom::computerroom() {
Order D;
fstream file;
int num, capatity, size;
file.open(COMPUTERNAME, ios::in);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
int i;
while (file >> num && file >> size && file >> capatity)
{
int n = 0;
this->m_num = num;
string str = to_string(num);
for (i = 0; i < D.M.size(); i++)
{
if((!D.M[i]["computer"].compare(str))&& (D.M[i]["status"].compare("3") && (D.M[i]["status"].compare("4"))))
n++;
}
this->m_capatity = capatity;
this->m_size = this->m_capatity - n;
vCmp.push_back(*this);
}
file.close();
}
computerroom::~computerroom() {
}
#include "identity.h"
identity::~identity()
{
}
#include "filename.h"
#include "root.h"
#include "teacher.h"
#include "student.h"
void login(string FILENAME,int n)
{
identity* p=NULL;
int key=0;
string name,Fname,password,Fpassword;
fstream file;
file.open(FILENAME.c_str(),ios::in);
if (!file.is_open())
{
cout << "文件未打开!"<<endl;
return;
}
int id,Fid;
if (n == 1)
{
cout << "请输入学号:";
cin >> id;
if(cin.fail())
{
cout << "输入错误!"<<endl;;
cin.clear();
rewind(stdin);
return;
}
cout << "请输入姓名:";
cin >> name;
cout << "请输入密码:";
cin >> password;
while (file >> Fid && file >> Fname && file >> Fpassword)
{
if (id == Fid && (!name.compare(Fname)) && (!password.compare(Fpassword)))
{
p = new student(id, name, password);
cout << "登入成功!" << endl;
system("pause");
system("cls");
key = 1;
p->m_login();
}
}
if (key != 1)
{
cout << "登入失败!" << endl;
}
}
else if (n == 2)
{
cout << "请输入编号:";
cin >> id;
rewind(stdin);
if(cin.fail())
{
cout << "输入错误!"<<endl;;
cin.clear();
rewind(stdin);
return;
}
cout << "请输入姓名:";
cin >> name;
cout << "请输入密码:";
cin >> password;
while (file >> Fid && file >> Fname && file >> Fpassword)
{
if (id==Fid&& (!name.compare(Fname)) && (!password.compare(Fpassword)))
{
p = new teacher(id, name, password);
cout << "登入成功!" << endl;
system("pause");
system("cls");
key = 1;
p->m_login();
}
}
if(key!=1)
{
cout << "登入失败!" << endl;
}
}
else if(n == 3)
{
cout << "请输入姓名:";
cin >> name;
cout << "请输入密码:";
cin >> password;
while (file >> Fname && file >> Fpassword)
{
if ((!name.compare(Fname)) && (!password.compare(Fpassword)))
{
p = new root(name, password);
cout << "登入成功!" << endl;
system("pause");
system("cls");
key = 1;
p->m_login();
}
}
if (key != 1)
{
cout << "登入失败!" << endl;
}
}
else
{
cout << "输入错误!" << endl;
return;
}
file.close();
}
int main()
{
while (true)
{
int ch;
cout << "\t\t----------欢迎来到机房预约系统----------------" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "\t\t\t\t1.学生身份登入" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t2.教师身份登入" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t3.管理员身份登入" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t0.退出系统" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "请输入:";
cin >> ch;
if(cin.fail())
{
cout << "输入错误!"<<endl;;
cin.clear();
rewind(stdin);
system("pause");
system("cls");
continue;
}
switch (ch)
{
case 1:login(STUDENTNAME, 1); break;
case 2:login(TEACHERNAME, 2); break;
case 3:login(ROOTNAME, 3); break;
case 0:
cout << "欢迎下次光临!" << endl;
exit(0);
default:cout << "输入错误请重新输入!" << endl;
fflush(stdin);
break;
}
system("pause");
system("cls");
}
}
#include "order.h"
void find_order(map<string, string>& m, string& str)
{
int start = 0;
int pos = str.find(":");
string a;
a = str.substr(start, pos - start);
string b;
b = str.substr(pos + 1, str.size() - pos - 1);
if (pos != -1)
{
m.insert(make_pair(a, b));
}
}
Order::Order()
{
fstream file;
string str;
string Fid, Fname, Fweek, Fday, Fstatus, Fcmp;
file.open(ORDERNAME, ios::in);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
int i = 0;
while (file >> Fid && file >> Fname && file >> Fcmp && file >> Fweek && file >> Fday && file >> Fstatus)
{
map<string, string> m;
find_order(m, Fid);
find_order(m, Fname);
find_order(m, Fcmp);
find_order(m, Fweek);
find_order(m, Fday);
find_order(m, Fstatus);
this->M.insert(make_pair(i, m));
i++;
}
file.close();
}
Order::~Order()
{
}
void Order::update_order()
{
computerroom T;
ofstream file1(COMPUTERNAME, ios::out | ios::trunc);
if (!file1.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
for (vector<computerroom>::iterator it = T.vCmp.begin(); it != T.vCmp.end(); it++)
{
file1 << it->m_num << " " << it->m_size << " " << it->m_capatity << endl;
}
file1.close();
ofstream file;
file.open(ORDERNAME, ios::out | ios::trunc);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
int i = 0;
for (i = 0; i < this->M.size(); i++)
{
file << "num:" << this->M[i]["num"] << " " << "name:" << this->M[i]["name"] << " " << "computer:" << this->M[i]["computer"] << " " << "week:" << this->M[i]["week"] << " " << "day:" << this->M[i]["day"] << " " << "status:" << this->M[i]["status"] << endl;
}
file.close();
}
#include "root.h"
root::~root()
{
}
root::root(string name, string password)
{
this->m_name = name;
this->m_password = password;
}
bool check_same(string FILENAME,int id,string name)
{
ifstream file;
int n = 0;
file.open(FILENAME.c_str(), ios::in);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return 0;
}
string Fname,pwd;
int Fid;
while (file>>Fid&&file>>Fname&&file>>pwd)
{
if (((Fid==id) || (!Fname.compare(name))))
{
file.close();
return false;
}
}
file.close();
return true;
}
void root::m_login()
{
int ch;
while (true)
{
cout << "\t\t----------"<<this->m_name<<"欢迎来到机房预约系统----------------" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "\t\t\t\t1.添加账号" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t2.查看账号" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t3.查看机房信息" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t4.清空预约信息" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t0.返回" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "请输入:";
cin >> ch;
if(cin.fail())
{
cout << "输入错误!"<<endl;;
cin.clear();
rewind(stdin);
return;
}
switch (ch)
{
case 1:this->addroot(); break;
case 2:this->showroot(); break;
case 3:this->showcomputer(); break;
case 4:this->clearfile(); break;
case 0:delete this; return;
default:cout << "输入错误,请重新输入!" << endl;
break;
}
system("pause");
system("cls");
}
}
void root::addroot()
{
ofstream file;
int ch=0;
int id;
string name, password;;
cout << "1.添加学生账号" << endl;
cout << "2.添加教师账号" << endl;
cout << "0.返回" << endl;
cout << "请输入:" ;
cin >> ch;
if (cin.fail())
{
cin.clear();
rewind(stdin);
cout << "输入错误!" << endl;
return;
}
if (ch == 1)
{
cout << "请输入学生学号:";
cin >> id;
cout << "请输入学生姓名:";
cin >> name;
cout << "请输入学生密码:";
cin >> password;
bool temp = check_same(STUDENTNAME, id, name);
file.open(STUDENTNAME, ios::out|ios::app);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
if (temp)
{
file << id << " " << name << " " << password << endl;
}
else
{
cout << "学号/姓名已存在" << endl;
return;
}
}
else if (ch == 2)
{
cout << "请输入教师编号:";
cin >> id;
cout << "请输入教师姓名:";
cin >> name;
cout << "请输入教师密码:";
cin >> password;
bool temp = check_same(TEACHERNAME, id, name);
file.open(TEACHERNAME, ios::out | ios::app);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
if (temp)
{
file << id << " " << name << " " << password << endl;
}
else
{
cout << "教师编号/姓名已存在" << endl;
return;
}
}
else
{
return;
}
cout << "添加成功!" << endl;
file.close();
}
void root::showroot()
{
int ch;
int id;
string name, password;
ifstream file;
cout << "1.查看学生账号信息" << endl;
cout << "2.查看老师账号信息" << endl;
cout << "0.返回" << endl;
cout << "请输入:";
cin >> ch;
if (cin.fail())
{
cin.clear();
rewind(stdin);
cout << "输入错误!" << endl;
return;
}
if (ch == 1)
{
file.open(STUDENTNAME,ios::in);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
cout << "所有学生账号信息如下:" << endl;
while (file >> id && file >> name && file >> password)
{
cout << "学生学号:" <<id << "\t学生姓名:" << name << "\t学生密码:" << password << endl;
}
file.close();
return;
}
else if (ch == 2)
{
file.open(TEACHERNAME, ios::in);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
cout << "所有教师账号信息如下:" << endl;
while (file >> id && file >> name && file >> password)
{
cout << "教师编号:" << id << "\t教师姓名:" << name << "\t教师密码:" << password << endl;
}
file.close();
return;
}
else
{
return;
}
}
void root::showcomputer()
{
computerroom T;
for (vector<computerroom>::iterator it = T.vCmp.begin(); it != T.vCmp.end(); it++)
{
cout <<"机房编号:\t"<< it->m_num << "\t机房剩余容量:\t" << it->m_size <<"\t机房大小:"<< it->m_capatity << endl;
}
}
void root::clearfile()
{
fstream file;
file.open(ORDERNAME,ios::out|ios::trunc);
if (!file.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
cout << "清空成功!" << endl;
file.close();
}
#include "student.h"
student::~student()
{
}
student::student(int id, string name, string password)
{
this->m_name = name;
this->m_password = password;
this->m_id = id;
}
void student::m_login()
{
int ch;
// Order D;
while (true)
{
cout << "\t\t----------" << this->m_name << "欢迎来到机房预约系统----------------" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "\t\t\t\t1.预约机房" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t2.查看自身预约 " << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t3.查看所有预约" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t4.取消预约 " << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t0.返回" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "请输入:";
cin >> ch;
if(cin.fail())
{
cout << "输入错误!"<<endl;;
cin.clear();
rewind(stdin);
return;
}
switch (ch)
{
case 1:this->order(); break;
case 2:this->show_my(); break;
case 3:this->show_all(); break;
case 4:this->delete_order();break;
case 0:delete this; return;
default:cout << "输入错误,请重新输入!" << endl;
break;
}
system("pause");
system("cls");
}
}
void student::order()
{
//ofstream file;
Order D;
computerroom T;
int week=0,cmp_id=0;
int day= 0;
cout << "1.星期一" << endl;
cout << "2.星期二" << endl;
cout << "3.星期三" << endl;
cout << "4.星期四" << endl;
cout << "5.星期五" << endl;
cout << "请输入:";
cin >> week;
if (cin.fail())
{
cin.clear();
cout << "输入错误,请重新输入!" << endl;
rewind(stdin);
return;
}
if (week != 1 && week != 2 && week != 3 && week != 4 && week != 5)
{
cout << "输入错误,请重新输入!" << endl;
return;
}
cout << "1.上午" << endl;
cout << "2.下午" << endl;
cout << "请输入:";
cin >> day;
if (cin.fail())
{
cin.clear();
cout << "输入错误,请重新输入!" << endl;
rewind(stdin);
return;
}
if (day != 1 && day != 2)
{
cout << "输入错误,请重新输入!" << endl;
return;
}
for (vector<computerroom>::iterator it = T.vCmp.begin(); it != T.vCmp.end(); it++)
{
cout << "机房编号:" << it->m_num << "\t\t机房剩余容量:" << it->m_size << "\t\t机房大小:" << it->m_capatity << endl;
}
cout << "请输入机房编号:";
cin >> cmp_id;
int n=0;
for (vector<computerroom>::iterator it = T.vCmp.begin(); it != T.vCmp.end(); it++)
{
if (cmp_id == it->m_num)
{
n = 1;
it->m_size--;
if (it->m_size < 0)
{
cout << "此机房已满!" << endl;
return;
}
break;
}
}
if (n != 1)
{
cout << "输入错误!未查到该机房!" << endl;
return;
}
if (cin.fail())
{
cin.clear();
cout << "输入错误,请重新输入!" << endl;
rewind(stdin);
return;
}
cout << "\t\t\t\t预约审核中......" << endl;
map<string, string> m;
string id=to_string(this->m_id) ;
string Week = to_string(week);
string Day = to_string(day);
string Cmp_id = to_string(cmp_id);
m.insert(make_pair("num",id));
m.insert(make_pair("name", this->m_name));
m.insert(make_pair("computer", Cmp_id));
m.insert(make_pair("week", Week));
m.insert(make_pair("day", Day));
m.insert(make_pair("status", "1"));
D.M[D.M.size()] = m;
D.update_order();
}
void student::show_my()
{
string week, status, str;
int i = 0;
Order D;
for (i = 0; i < D.M.size(); i++)
{
if (!D.M[i]["name"].compare(this->m_name))
{
if (!D.M[i]["week"].compare("1"))
week = "星期一";
else if (!D.M[i]["week"].compare("2"))
week = "星期二";
else if (!D.M[i]["week"].compare("3"))
week = "星期三";
else if (!D.M[i]["week"].compare("4"))
week = "星期四";
else if (!D.M[i]["week"].compare("5"))
week = "星期五";
else
week = D.M[i]["week"];
if (!D.M[i]["status"].compare("1"))
status = "审核中";
else if (!D.M[i]["status"].compare("2"))
status = "预约成功";
else if (!D.M[i]["status"].compare("3"))
status = "预约失败";
else if (!D.M[i]["status"].compare("4"))
status = "已取消";
else
status = "不明确";
cout << "学生学号:" << D.M[i]["num"] << "\t"
<< "学生姓名:" << D.M[i]["name"] << "\t"
<< "机房编号:" << D.M[i]["computer"] << "\t"
<< "week:" << week << "\t"
<< "day:" << (D.M[i]["day"].compare("1") ? "下午" : "上午") << "\t"
<< "status:" << status << endl;
}
}
}
void student::show_all()
{
string week,status,str;
int i=0;
Order D;
cout<<"\t\t\t\t一共有"<< D.M.size() <<"条记录"<<endl;
for (i = 0; i < D.M.size(); i++)
{
if (!D.M[i]["week"].compare("1"))
week = "星期一";
else if (!D.M[i]["week"].compare("2"))
week = "星期二";
else if (!D.M[i]["week"].compare("3"))
week = "星期三";
else if (!D.M[i]["week"].compare("4"))
week = "星期四";
else if (!D.M[i]["week"].compare("5"))
week = "星期五";
else
week = D.M[i]["week"];
if (!D.M[i]["status"].compare("1"))
status = "审核中";
else if (!D.M[i]["status"].compare("2"))
status = "预约成功";
else if (!D.M[i]["status"].compare("3"))
status = "预约失败";
else if (!D.M[i]["status"].compare("4"))
status = "已取消";
else
status = "不明确";
cout << "学生学号:" << D.M[i]["num"] << "\t"
<< "学生姓名:" << D.M[i]["name"] << "\t"
<< "机房编号:" << D.M[i]["computer"] << "\t"
<< "week:" << week << "\t"
<< "day:" << (D.M[i]["day"].compare("1")?"下午" : "上午") << "\t"
<< "status:" << status << endl;
}
}
void student::delete_order()
{
Order D;
string week, status, str;
int i = 0, j = 1;
vector<int> v;
computerroom T;
if (D.M.size() == 0)
{
cout << "该学生还没有预约!" << endl;
return;
}
for (i = 0; i < D.M.size(); i++)
{
if (!D.M[i]["name"].compare(this->m_name))
{
v.push_back(i);
if (!D.M[i]["week"].compare("1"))
week = "星期一";
else if (!D.M[i]["week"].compare("2"))
week = "星期二";
else if (!D.M[i]["week"].compare("3"))
week = "星期三";
else if (!D.M[i]["week"].compare("4"))
week = "星期四";
else if (!D.M[i]["week"].compare("5"))
week = "星期五";
else
week = D.M[i]["week"];
if (!D.M[i]["status"].compare("1"))
status = "审核中";
else if (!D.M[i]["status"].compare("2"))
status = "预约成功";
else if (!D.M[i]["status"].compare("3"))
status = "预约失败";
else if (!D.M[i]["status"].compare("4"))
status = "已取消";
else
status = "不明确";
cout<<j<<":"<< "\t学生学号:" << D.M[i]["num"] << "\t"
<< "学生姓名:" << D.M[i]["name"] << "\t"
<< "机房编号:" << D.M[i]["computer"] << "\t"
<< "week:" << week << "\t"
<< "day:" << (D.M[i]["day"].compare("1") ? "下午" : "上午") << "\t"
<< "status:" << status << endl;
j++;
}
}
int ch=0;
while (true)
{
cout << "请输入要取消预约的编号:";
cin >> ch;
rewind(stdin);
if (cin.fail() || ch > i + 1||ch<=0)
{
cout << "输入错误!" << endl;
cin.clear();
rewind(stdin);
continue;
}
else
{
if (D.M[v[ch - 1]]["status"] == "4")
{
cout << "预约已取消,无需再次操作!" << endl;
return;
}
D.M[v[ch - 1]]["status"] = "4";
string cmp_id= D.M[v[ch - 1]]["computer"];
for (vector<computerroom>::iterator it = T.vCmp.begin(); it != T.vCmp.end(); it++)
{
if (atoi(cmp_id.c_str()) == it->m_num)
{
it->m_size++;
}
}
cout << "取消成功!" << endl;
break;
}
}
D.update_order();
}
#include "teacher.h"
teacher::teacher(int id,string name, string password)
{
this->m_name = name;
this->m_password = password;
this->m_id = id;
fstream file;
}
teacher::~teacher()
{
}
void teacher::m_login()
{
int ch;
while (true)
{
cout << "\t\t----------" << this->m_name << "欢迎来到机房预约系统----------------" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "\t\t\t\t1.查看所有预约信息" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t2.处理预约信息" << endl;
cout << "\t\t\t" << endl;
cout << "\t\t\t\t0.返回" << endl;
cout << "\t\t\t-------------------------------" << endl;
cout << "请输入:";
cin >> ch;
if(cin.fail())
{
cout << "输入错误!"<<endl;;
cin.clear();
rewind(stdin);
return;
}
switch (ch)
{
case 1:this->showorder(); break;
case 2:this->dealorder(); break;
case 0:delete this; return;
default:cout << "输入错误,请重新输入!" << endl;
break;
}
system("pause");
system("cls");
}
}
void teacher::showorder()
{
string week, status, str;
int i = 0;
Order D;
cout << "\t\t\t\t一共有" << D.M.size() << "条记录" << endl;
for (i = 0; i < D.M.size(); i++)
{
if (!D.M[i]["week"].compare("1"))
week = "星期一";
else if (!D.M[i]["week"].compare("2"))
week = "星期二";
else if (!D.M[i]["week"].compare("3"))
week = "星期三";
else if (!D.M[i]["week"].compare("4"))
week = "星期四";
else if (!D.M[i]["week"].compare("5"))
week = "星期五";
else
week = D.M[i]["week"];
if (!D.M[i]["status"].compare("1"))
status = "审核中";
else if (!D.M[i]["status"].compare("2"))
status = "预约成功";
else if (!D.M[i]["status"].compare("3"))
status = "预约失败";
else if (!D.M[i]["status"].compare("4"))
status = "已取消";
else
status = "不明确";
cout << "学生学号:" << D.M[i]["num"] << "\t"
<< "学生姓名:" << D.M[i]["name"] << "\t"
<< "机房编号:" << D.M[i]["computer"] << "\t"
<< "week:" << week << "\t"
<< "day:" << (D.M[i]["day"].compare("1") ? "下午" : "上午") << "\t"
<< "status:" << status << endl;
}
}
void teacher::dealorder()
{
Order D;
string week, status, str;
int i = 0, j = 1;
vector<int> v;
computerroom T;
if (D.M.size() == 0)
{
cout << "该学生还没有预约!" << endl;
return;
}
cout << "\t\t\t\t待处理的预约订单如下:" << endl;
for (i = 0; i < D.M.size(); i++)
{
if (!D.M[i]["status"].compare("1"))
{
v.push_back(i);
if (!D.M[i]["week"].compare("1"))
week = "星期一";
else if (!D.M[i]["week"].compare("2"))
week = "星期二";
else if (!D.M[i]["week"].compare("3"))
week = "星期三";
else if (!D.M[i]["week"].compare("4"))
week = "星期四";
else if (!D.M[i]["week"].compare("5"))
week = "星期五";
else
week = D.M[i]["week"];
if (!D.M[i]["status"].compare("1"))
status = "审核中";
else
status = "不明确";
cout << j << ":" << "\t学生学号:" << D.M[i]["num"] << "\t"
<< "学生姓名:" << D.M[i]["name"] << "\t"
<< "机房编号:" << D.M[i]["computer"] << "\t"
<< "week:" << week << "\t"
<< "day:" << (D.M[i]["day"].compare("1") ? "下午" : "上午") << "\t"
<< "status:" << status << endl;
j++;
}
}
int ch = 0,n=0;
while (true)
{
cout << "请输入要处理预约的编号:";
cin >> ch;
rewind(stdin);
if (cin.fail() || ch > v.size()|| ch <= 0)
{
cout << "输入错误!请重新输入:" << endl;
cin.clear();
rewind(stdin);
continue;
}
else
{
cout << "1.通过" << endl;
cout << "2.不通过" << endl;
cout << "0.返回" << endl;
cout << "请输入:";
cin >> n;
if (cin.fail())
{
cout << "输入错误!请重新输入:" << endl;
cin.clear();
rewind(stdin);
continue;
}
if (n==1)
{
D.M[v[ch-1]]["status"] = "2";
}
else if (n == 2)
{
D.M[v[ch - 1]]["status"] = "3";
}
else if (n == 0)
{
return;
}
else
{
D.M[v[ch - 1]]["status"] = "3";
}
cout << "处理成功!" << endl;
break;
}
}
D.update_order();
}