0
点赞
收藏
分享

微信扫一扫

《C++》机房预约系统案例

IT程序员 2023-08-04 阅读 61

机房预约系统文件

可运行存在bug,断断续续手搓10多天

《C++》机房预约系统案例_ios

《C++》机房预约系统案例_#include_02

  • Administrator.h

#pragma once
#include "LoginIdentity.h"
#include "CompRoom.h"

class MapId
{
public:
	string M_name;
	string M_pwd;
};

class LoginAdmin : public Login
{
public:
	LoginAdmin();
	LoginAdmin(string id, string pwd);
	map<string,MapId> Lm1;
	map<string, MapId> Lm2;
	map<int, ComRoom> Cm;

	virtual void operMenu();

	void MenuEncap();

	void AddAccount();//添加账号

	void ShowAccount();//查看账号

	void ShowComputerRoom();//查看机房

	void DropOrder();//清空预约信息
};

  • CompRoom.h

#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include "LoginIdentity.h"

class ComRoom
{
public:
	int M_maxSize;
	int M_size;
};

  • FilePath.h

#pragma once
#define ADMIN_FILE "Admin.dat"
#define STUDENT_FILE "Student.dat"
#define TEACHER_FILE "Teacher.dat"
#define COMPROOM_FILE "CompRoom.dat"
#define ORDER_FILE "Order.dat"
//#define DEBUG_FILE "debug.log"

  • LoginIdentity.h

#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <map>
#include "FilePath.h"
using namespace std;

class Login
{
public:
	virtual void operMenu() = 0;
	string M_Id;
	string M_Pwd;

};


void showmainMenu();
void LoginIn(string fileName,int type);
void LoginIdType(Login *Parent, int type,string name);
void AddId(string fileName,string name,string id,string pwd);

  • Order.h

#pragma once
#include "LoginIdentity.h"

class Order
{
public:
	string M_name;
	string M_id;
	int M_date;
	int M_period;
	int M_comproom;
	int M_state;
};
class Orderfile
{
public:
	map<int,Order> om;

	void initOrder();

	void showOrder(const map<int,Order> m);

	void updataOrder();
};

  • Student.h

#pragma once
#include "LoginIdentity.h"
#include "CompRoom.h"
#include "Order.h"

class LoginStudent : public Login
{
public:
	LoginStudent();
	LoginStudent(string name, string id, string pwd);
	string M_name;
	map<int, ComRoom> m;

	virtual void operMenu();

	void MenuEncap();

	void ApplicationOder();//申请预约

	void ShowMyOder();//查看我的预约

	void CancelOder();//取消预约

	void ShowAllOder();//查看所有预约
};

  • Teacher.h

#pragma once
#include "LoginIdentity.h"

class LoginTeacher : public Login
{
public:
	string M_name;

	virtual void operMenu();

	void MenuEncap();

	void ShowAllOder();//查看所有预约

	void ReviewOder();//审核预约

};

  • Administrator.cpp

#include "Administrator.h"
LoginAdmin::LoginAdmin()
{

}
LoginAdmin::LoginAdmin(string id,string pwd)
{
	this->M_Id = id;
	this->M_Pwd = pwd;
}

bool isRepeat(string fileName,string id)
{
	bool flag = false;
	ifstream ifs(fileName, ios::in);
	string ftmp;
	string fid;
	if (ifs.is_open())
	{
		while (ifs>>ftmp&&ifs>>fid&&ifs>>ftmp)
		{
			if (fid == id)
			{
				cout << "该账号已存在!" << endl;
				flag = true;
				break;
			}
		}
	}
	ifs.close();
	return flag;
}

void LoginAdmin::operMenu()
{
	cout << endl;
	cout << "\t               欢迎回来            " << endl;
	cout << "\t       当前账号:[管理员]" << this->M_Id << endl;
	cout << "\t --------------------------------- " << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        1   添加新的账号         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        2   查看所有账号         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        3   查看机房信息         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        4   清空预约记录         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        0   退出登录              |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t --------------------------------- " << endl;
}
void LoginAdmin::MenuEncap()
{
	int choose = -1;
	while (choose)
	{
		operMenu();
		if (-1 == choose)
			cout << "请选择:>";
		cin >> choose;
		while (getchar() != '\n');

		switch (choose)
		{
		case 1://添加账号
			AddAccount();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 2://查看账号
			ShowAccount();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 3://查看机房编号
			ShowComputerRoom();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 4://清空预约记录
			DropOrder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 0://退出登录
			cout << "退出登录成功!" << endl;
			break;
		default:
			cout << "选项无效,请重新输入:>";
			break;
		}
	}
}
void LoginAdmin::AddAccount()
{
	int choose = -1;
	string name;
	string id;
	string pwd;
	MapId mid;
	while (true)
	{
		int choose = -1;
		cout << "开始添加账号,输入其他添加结束" << endl;
		cout << "\t1、添加学生账号" << endl;
		cout << "\t2、添加老师账号" << endl;
		cout << "\t请选择添加账号type :>";
		cin >> choose;
		while (getchar() != '\n');
		/*cin.clear(); cin.ignore();*/
		if (1 == choose)
		{
			//添加学生账号
			cout << "\t请输入学生姓名:>";
			cin >> name;
			cout << "\t请输入学生学号:>";
			cin >> id;
			if (isRepeat(STUDENT_FILE, id))
				return;
			cout << "\t请设置账号密码:>";
			cin >> pwd;
			AddId(STUDENT_FILE, name, id, pwd);
			mid.M_name = name; mid.M_pwd = pwd;
			Lm1.insert(make_pair(id, mid));
		}
		else if (2 == choose)
		{
			//添加老师账号
			cout << "\t请输入老师姓名:>";
			cin >> name;
			cout << "\t请输入老师工号:>";
			cin >> id;
			cout << "\t请设置账号密码:>";
			cin >> pwd;
			AddId(TEACHER_FILE, name, id, pwd);
		}
		else
		{
			return;
			//退出添加
		}
	}
}

void LoginAdmin::ShowAccount()
{
	//读所有账号
	ifstream ifs1(STUDENT_FILE, ios::in);
	MapId mid;
	string id;
	if (ifs1.is_open())
	{
		while (ifs1 >> mid.M_name&&ifs1 >> id&&ifs1 >> mid.M_pwd)
		{
			Lm1.insert(make_pair(id, mid));
		}
		ifs1.close();
	}
	ifstream ifs2(TEACHER_FILE, ios::in);
	if (ifs2.is_open())
	{
		while (ifs2 >> mid.M_name&&ifs2 >> id&&ifs2 >> mid.M_pwd)
		{
			Lm2.insert(make_pair(id, mid));
		}
		ifs2.close();
	}
	//
	cout << "所有学生账号:"<<endl;
	if (!Lm1.empty())
	{
		cout << "\t姓名" << "\t学号" << "\t密码" << endl;
		cout << "\t--------------------------------" << endl;
		for (map<string, MapId>::iterator it = Lm1.begin(); it != Lm1.end(); it++)
			cout << "\t" << (*it).second.M_name << "\t" << (*it).first << "\t" << (*it).second.M_pwd << endl;
		cout << endl;
	}
	else
	{
		cout << "\t无学生账号!" << endl;
	}
	cout << "所有老师账号:" << endl;
	if (!Lm2.empty())
	{
		cout << "\t姓名" << "\t工号" << "\t密码" << endl;
		for (map<string, MapId>::iterator it = Lm2.begin(); it != Lm2.end(); it++)
			cout << "\t" << (*it).second.M_name << "\t" << (*it).first << "\t" << (*it).second.M_pwd << endl;
		cout << endl;
	}
	else
	{
		cout << "\t无老师账号!" << endl;
	}
}

void LoginAdmin::ShowComputerRoom()
{
	//初始化机房信息
	ifstream ifs(COMPROOM_FILE, ios::in);
	if (ifs.is_open())
	{
		ComRoom cr;
		int cr_id;
		while (ifs >> cr_id&&ifs >> cr.M_maxSize&&ifs >> cr.M_size)
		{
			Cm.insert(make_pair(cr_id, cr));
		}
		ifs.close();
	}
	cout << "所有机房信息如下:" << endl;
	for (auto it = Cm.begin(); it != Cm.end(); it++)
	{
		cout << "\t机房号:" << (*it).first << "  机子总数:" << (*it).second.M_maxSize
			<< "  剩余机子:" << (*it).second.M_size << endl;
	}
}

void LoginAdmin::DropOrder()
{
	ofstream ofs1(ORDER_FILE, ios::out|ios::trunc);
	if (ofs1.is_open())
	{
		ofs1.close();
	}
	ofstream ofs2(COMPROOM_FILE, ios::out | ios::trunc);
	if (ofs2.is_open())
	{
		ofs2 << "1 20 20" << endl;
		ofs2 << "1 30 30" << endl;
		ofs2 << "1 45 45" << endl;
		ofs2.close();
	}
	cout << "清空预约记录成功!" << endl;
}

  • LoginIdentity.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include "LoginIdentity.h"
#include"Administrator.h"
#include "Student.h"
#include "Teacher.h"
void showmainMenu()
{
	cout << "============= 欢迎使用孤沐机房预约系统 =============" << endl;
	cout << endl;
	cout << "\t --------------------------------- " << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        1   学生账号登录         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        2   老师账号登录         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        3   管理账号登录         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        0   退出预约系统         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t -------------------------------- " << endl;
}

void LoginIn(string fileName,int type)
{
	Login *Parent = NULL;
	ifstream ifs(fileName, ios::in);
	if (!ifs.is_open())
		return;

	string name;
	string id;
	string pwd;
	if (1 == type)
	{
		bool flag=false;
		//学生号登录
		cout << "请输入姓名:>";
		cin >> name;
		cout << "请输入学号:>";
		cin >> id;
		cout << "请输入密码:>";
		cin >> pwd;
		string fname;
		string fid;
		string fpwd;
		while (ifs >> fname&&ifs >> fid&&ifs >> fpwd)
		{
			if (fname == name&&fid == id&&fpwd == pwd)
			{
				cout << "登录成功" << endl;
				ifs.close();
				system("pause");
				system("cls");
				flag = true;

				Parent = new(LoginStudent);
				Parent->M_Id = id;
				Parent->M_Pwd = pwd;
				LoginIdType(Parent, type,name);

				delete Parent;
			}
		}
		if (!flag)
		{
			cout << "账户不存在或密码错误!" << endl;
		}
	}
	else if (2 == type)
	{
		//老师号登录
		bool flag = false;
		cout << "请输入姓名:>";
		cin >> name;
		cout << "请输入工号:>";
		cin >> id;
		cout << "请输入密码:>";
		cin >> pwd;
		string fname;
		string fid;
		string fpwd;
		while (ifs >> fname&&ifs >> fid&&ifs >> fpwd)
		{
			if (fname == name&&fid == id&&fpwd == pwd)
			{
				cout << "登录成功" << endl;
				ifs.close();
				system("pause");
				system("cls");
				flag = true;

				Parent = new(LoginTeacher);
				Parent->M_Id = id;
				Parent->M_Pwd = pwd;
				LoginIdType(Parent, type, name);

				delete Parent;
			}
		}
		if (!flag)
		{
			cout << "账户不存在或密码错误!" << endl;
		}
	}
	else if (3 == type)
	{
		//管理员登录
		bool flag = false;
		cout << "请输入管理员账号:>";
		cin >> id;
		cout << "请输入密码:>";
		cin >> pwd;
		string fid;
		string fpwd;
		while (ifs >> fid&&ifs >> fpwd)
		{
			if (fid == id&&fpwd == pwd)
			{
				cout << "登录成功" << endl;
				ifs.close();
				system("pause");
				system("cls");
				flag = true;
				
				Parent = new(LoginAdmin);
				Parent->M_Id = id;
				Parent->M_Pwd = pwd;
				LoginIdType(Parent, type, "");

				delete Parent;
			}
		}
		if (!flag)
		{
			cout << "账号不存在或密码错误!" << endl;
		}
	}
	else
	{
		cout << "type不存在!" << endl;
		system("pause");
		system("cls");
		return;
	}
	ifs.close();
	system("pause");
	system("cls");
}
void LoginIdType(Login *Parent,int type,string name)
{
	if (1 == type)
	{
		LoginStudent* login = (LoginStudent*)Parent;
		login->M_name = name;
		login->MenuEncap();
	}
	else if (2 == type)
	{
		LoginTeacher* login = (LoginTeacher*)Parent;
		login->M_name = name;
		login->MenuEncap();
	}
	else if (3 == type)
	{
		LoginAdmin* login = (LoginAdmin*)Parent;
		login->MenuEncap();
	}
}

void AddId(string fileName,string name, string id, string pwd)
{
	ofstream ofs(fileName, ios::out|ios::app);
	if (!ofs.is_open())
		return;
	ofs << name << " " << id << " " << pwd;
	ofs << endl;
	cout << id << " 添加成功!" << endl;
	ofs.close();
}

  • Order.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include "Order.h"
void Orderfile::initOrder()
{
	om.clear();
	ifstream ifs(ORDER_FILE, ios::in);
	if (ifs.is_open())
	{
		Order o;
		string date;
		string period;
		string comproom;
		string name;
		string id;
		string state;
		while (ifs >> date&&ifs >> period&&ifs >> comproom
			&&ifs >> name&&ifs >> id&&ifs >> state)
		{
			int pos = date.find(":");
			o.M_date = stoi(date.substr(pos + 1, date.size() - pos - 1));

			pos = period.find(":");
			o.M_period = stoi(period.substr(pos + 1, period.size() - pos - 1));

			pos = comproom.find(":");
			o.M_comproom = stoi(comproom.substr(pos + 1, comproom.size() - pos - 1));

			pos = name.find(":");
			o.M_name = name.substr(pos + 1, name.size() - pos - 1);

			pos = id.find(":");
			o.M_id = id.substr(pos + 1, id.size() - pos - 1);

			pos = state.find(":");
			o.M_state = stoi(state.substr(pos + 1, state.size() - pos - 1));

			om.insert(make_pair(om.size()+1, o));
		}
		ifs.close();
	}
}

void Orderfile::showOrder(const map<int, Order> m)
{
	if (!m.size())
		return;
	cout << "\t序号\t" << "日期\t" << "时间段\t" << "机房\t\t" << "姓名\t" << "学号\t" << "状态\t" << endl;
	for (auto it = m.begin(); it != m.end(); it++)
	{
		cout << "\t" << (*it).first << "\t";
		switch ((*it).second.M_date)
		{
		case 1:cout << "星期一\t"; break;
		case 2:cout << "星期二\t"; break;
		case 3:cout << "星期三\t"; break;
		case 4:cout << "星期四\t"; break;
		case 5:cout << "星期五\t"; break;
		default:
			return;
		}
		if (1 == (*it).second.M_period)
			cout << "上午\t";
		else if (2 == (*it).second.M_period)
			cout << "下午\t";
		else
			return;
		cout << (*it).second.M_comproom << "号机房\t\t";
		cout << (*it).second.M_name << "\t";
		cout << (*it).second.M_id << "\t";
		switch ((*it).second.M_state)
		{
		case 1:cout << "审核中" << endl; break;
		case 2:cout << "预约成功" << endl; break;
		case 3:cout << "预约失败" << endl; break;
		case 4:cout << "预约取消" << endl; break;
		default:
			return;
		}
	}
}

void Orderfile::updataOrder()
{
	ofstream ofs(ORDER_FILE, ios::out | ios::trunc);
	if (ofs.is_open())
	{
		for (auto it = om.begin(); it != om.end();it++)
		{
			ofs << "data:" << (*it).second.M_date << " ";
			ofs << "Peroid:" << (*it).second.M_period << " ";
			ofs << "Comprom:" << (*it).second.M_comproom << " ";
			ofs << "Name:" << (*it).second.M_name << " ";
			ofs << "Stuid:" << (*it).second.M_id << " ";
			ofs << "State:" << (*it).second.M_state << endl;
		}
		ofs.close();
	}
}

  • Student.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include "Student.h"
#include <vector>
LoginStudent::LoginStudent()
{

}
LoginStudent::LoginStudent(string name, string id, string pwd)
{

}
void InitCompRoom(map<int, ComRoom> &m)
{
	//初始化机房信息
	ifstream ifs(COMPROOM_FILE, ios::in);
	if (ifs.is_open())
	{
		ComRoom cr;
		int cr_id;
		while (ifs >> cr_id&&ifs >> cr.M_maxSize&&ifs >> cr.M_size)
		{
			m.insert(make_pair(cr_id, cr));
		}
		ifs.close();
	}
	cout << "所有机房信息如下:" << endl;
	for (auto it = m.begin(); it != m.end(); it++)
	{
		cout << "\t机房号:" << (*it).first << "  机子总数:" << (*it).second.M_maxSize
			<< "  剩余机子:" << (*it).second.M_size << endl;
	}
}
void LoginStudent::operMenu()
{
	cout << endl;
	cout << "\t               欢迎回来            " << endl;
	cout << "\t       当前账号:[学生]  " << this->M_Id << endl;
	cout << "\t --------------------------------- " << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        1   申请新的预约         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        2   查看我的预约         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        3   查看所有预约         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        4   取消我的预约         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        0   退出登录             |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t --------------------------------- " << endl;
}

void LoginStudent::MenuEncap()
{
	int choose = -1;
	while (choose)
	{
		operMenu();
		if (-1 == choose)
			cout << "请选择:>";
		cin >> choose;
		while (getchar() != '\n');

		switch (choose)
		{
		case 1://申请预约
			ApplicationOder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 2://查看我的预约
			ShowMyOder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 3://查看所有预约
			ShowAllOder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 4://取消预约
			CancelOder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 0://退出登录
			cout << "退出登录成功!" << endl;
			break;
		default:
			cout << "选项无效,请重新输入:>";
			choose = 0;
			break;
		}
	}
}
bool OrderInfor(map<int, ComRoom> &m, string &order)
{
	int input = 0;
	cout << "请选择日期:" << endl;
	cout << "\t1、周一" << endl;
	cout << "\t2、周二" << endl;
	cout << "\t3、周三" << endl;
	cout << "\t4、周四" << endl;
	cout << "\t5、周五" << endl;
	while (true)
	{
		cout << "\t";
		cin >> input;
		while (getchar() != '\n');
		if (input <= 5 && input >= 1)
			break;
		cout << "\t选项无效,请重新输入:>";
	}
	order = "date:" + to_string(input);
	cout << "请选择时间段:" << endl;
	cout << "\t1、上午" << endl;
	cout << "\t2、下午" << endl;
	while (true)
	{
		cout << "\t";
		cin >> input;
		while (getchar() != '\n');
		if (input <= 2 && input >= 1)
			break;
		cout << "\t选项无效,请重新输入:>";
	}
	order += " Period:";
	order += to_string(input);
	cout << "请选择机房:" << endl;
	cout << "\t1、1号机房" << endl;
	cout << "\t2、2号机房" << endl;
	cout << "\t3、3号机房" << endl;
	while (true)
	{
		cout << "\t";
		cin >> input;
		while (getchar() != '\n');
		if (input <= 3 && input >= 1)
			break;
		cout << "\t选项无效,请重新输入:>";
	}
	if (m.find(input)->second.M_size == 0)
	{
		cout << input << "号机房预约满了,看看其他机房吧!" << endl;
		return false;
	}
	order += " CompRoom:";
	order += to_string(input);
	m.find(input)->second.M_size--;
	ofstream ofs(COMPROOM_FILE, ios::out | ios::trunc);
	if (ofs.is_open())
	{
		for (auto it = m.begin(); it != m.end(); it++)
		{
			ofs << (*it).first << " " << (*it).second.M_maxSize << " " << (*it).second.M_size;
			ofs << endl;
		}
	}
	return true;
}
void LoginStudent::ApplicationOder()
{
	string order;
	InitCompRoom(m);
	if (OrderInfor(m, order))
	{
		string my = " Name:" + M_name + " Stuid:" + M_Id + " State:1";
		order += my;
		//cout << order;
		ofstream ofs(ORDER_FILE, ios::out | ios::app);
		if (ofs.is_open())
		{
			ofs << order << endl;
			ofs.close();
			cout << "申请预约成功!" << endl;
		}
	}
}

void LoginStudent::CancelOder()
{
	Orderfile of;
	map<int, Order> m1;
	vector<int> v1;
	of.initOrder();
	int no = 1;
	for (auto it = of.om.begin(); it != of.om.end(); it++)
	{
		if ((*it).second.M_name == this->M_name && (*it).second.M_id == this->M_Id)
		{
			if ((*it).second.M_state == 1 || (*it).second.M_state==2)
			{
				v1.push_back((*it).first);
				m1.insert(make_pair(no, (*it).second));
				no++;
			}
		}
	}
	of.showOrder(m1);
	cout << "只有审核中和审核通过的预约可以取消" << endl;
	cout << "\t请输入要取消的预约信息序号:>";
	int input=0;
	cin >> input;
	if (m1.size() >= input || !input)
	{
		char con;
		cout << "\t确认( y ) / 取消(任意字符) :>";
		cin >> con;
		while (getchar() != '\n');
		if (con != 'y')
		{
			cout << "\t操作已取消!" << endl;
			return;
		}
		of.om.erase(v1.at(input-1));
		of.updataOrder();
		cout << "\t序号 " << input << " 的预约取消成功" << endl;
	}
	else
	{
		cout << "\t序号不存在或你没有预约!" << endl;
		return;
	}
}

void LoginStudent::ShowAllOder()
{
	Orderfile of;
	of.initOrder();
	of.showOrder(of.om);
}

void LoginStudent::ShowMyOder()
{
	Orderfile of;
	map<int, Order> m1;
	of.initOrder();
	int no = 1;
	for (auto it = of.om.begin(); it != of.om.end(); it++)
	{
		if ((*it).second.M_name == this->M_name && (*it).second.M_id == this->M_Id)
		{
			m1.insert(make_pair(no, (*it).second));
			no++;
		}
	}
	of.showOrder(m1);
}

  • Teacher.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include "Teacher.h"
#include "Order.h"

void LoginTeacher::operMenu()
{
	cout << endl;
	cout << "\t               欢迎回来            " << endl;
	cout << "\t       当前账号:[老师]  " << this->M_Id << endl;
	cout << "\t --------------------------------- " << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        1   查看所有预约         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        2   开始审核预约         |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t|        0   退出登录             |" << endl;
	cout << "\t|                                 |" << endl;
	cout << "\t --------------------------------- " << endl;
}

void LoginTeacher::MenuEncap()
{
	int choose = -1;
	while (choose)
	{
		operMenu();
		if (-1 == choose)
			cout << "请选择:>";
		cin >> choose;
		while (getchar() != '\n');

		switch (choose)
		{
		case 1://查看所有预约
			ShowAllOder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 2://审核预约
			ReviewOder();
			system("pause");
			system("cls");
			choose = -1;
			break;
		case 0://退出登录
			cout << "退出登录成功!" << endl;
			break;
		default:
			cout << "选项无效,请重新输入:>";
			choose = 0;
			break;
		}
	}
}

void LoginTeacher::ShowAllOder()
{
	Orderfile of;
	of.initOrder();
	of.showOrder(of.om);
}

void LoginTeacher::ReviewOder()
{
	Orderfile of;
	vector<int> v1;
	of.initOrder();
	int no = 1;
	for (auto it1 = of.om.begin(); it1 != of.om.end(); it1++)
	{
		if ((*it1).second.M_state == 1)
		{
			v1.push_back((*it1).first);
		}
	}
	if (v1.empty())
	{
		cout << "没有新的预约,无需审核!" << endl;
		return;
	}
	system("cls");
	for (auto it2 = v1.begin(); it2 != v1.end();)
	{
		map<int, Order> m1; m1.clear();
		m1.insert(*(of.om.find(*it2)));
		cout << "你还有 " << v1.size() << " 条预约待审核" << endl;
		cout << "开始审核,输入0返回菜单" << endl;
		of.showOrder(m1);
		int con;
		cout << "\t1、通过" << endl;
		cout << "\t2、不通过" << endl;
		cout << "\t请选择:>";
		cin >> con;
		while (getchar() != '\n');
		if (1 == con)
		{
			cout << "\t序号 " << *it2 << " 审核为:通过!" << endl;
			of.om.at(*it2).M_state = 2;
			it2=v1.erase(it2);
			of.updataOrder();
			system("cls");
		}
		else if (2 == con)
		{
			cout << "\t序号 " << *it2 << " 审核为:通过!" << endl;
			of.om.at(*it2).M_state = 3;
			it2=v1.erase(it2);
			of.updataOrder();
			system("cls");
		}
		else if (0 == con)
		{
			return;
		}
		else
		{
			cout << "\t选项无效,请重新选择!" << endl;
		}
	}
}

  • 机房预约系统.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include "LoginIdentity.h"	

int main()
{
	int choose=-1;
	showmainMenu();
	while (choose)
	{
		if (-1==choose)
			cout << "请选择:> ";
		cin >> choose;
		while (getchar() != '\n');
		
		switch (choose)
		{
		case 1://学生账号登录
			LoginIn(STUDENT_FILE, choose);
			showmainMenu(); choose = -1;
			break;
		case 2://老师账号登录
			LoginIn(TEACHER_FILE, choose);
			showmainMenu(); choose = -1;
			break;
		case 3://管理账号登录
			LoginIn(ADMIN_FILE, choose);
			showmainMenu(); choose = -1;
			break;
		case 0://退出
			cout << "程序结束,欢迎下次使用!" << endl;
			break;
		default:
			system("cls");
			showmainMenu();
			cout << "输入有误,重新输入:>";
			break;
		}
	}
	system("pause");
	return 0;
}

举报

相关推荐

0 条评论