首页 > 编程语言 >《C++》机房预约系统案例

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

时间:2023-08-04 23:34:21浏览次数:38  
标签:string 预约 void C++ name 机房 choose id cout

机房预约系统文件

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

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

《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;
}

标签:string,预约,void,C++,name,机房,choose,id,cout
From: https://blog.51cto.com/u_16071993/6970079

相关文章

  • C++ 核心指南之 C++ 哲学/基本理念(下)
    C++核心指南(C++CoreGuidelines)是由BjarneStroustrup、HerbSutter等顶尖C+专家创建的一份C++指南、规则及最佳实践。旨在帮助大家正确、高效地使用“现代C++”。这份指南侧重于接口、资源管理、内存管理、并发等High-level主题。遵循这些规则可以最大程度地保证静......
  • c++算法之离散化例题
    离散化基础2题目描述给定 n 个元素的数列,将相同的数据离散化为一个数据(去重),即把 {4000,201,11,45,11}{4000,201,11,45,11} 离散化为 {4,3,1,2,1}{4,3,1,2,1}。输入格式第一行一个整数 (1≤m≤105)n(1≤n≤105),为元素的个数。第二行 n 个用空格隔天的整数a[i](−109......
  • 《Modern C++ Design》之上篇
    如下内容是在看侯捷老师翻译的《ModernC++Design》书籍时,整理的code和摘要,用于不断地温故知新。第一章1.运用TemplateTemplate参数实作PolicyClassestemplate<template<classCreated>classCreationPolicy>//template<template<class>classCreationPolicy......
  • 一些有趣的C++代码
    本文混合搅碎剁烂转载。。。 1:绘制曲线 #include<bits/stdc++.h>usingnamespacestd;intmain(){intx,m;for(doublei=1;i>=-1;i-=0.1){m=acos(i)*10;for(x=1;x<m;x++)cout<<"";cout<&l......
  • C++多线程中互斥量的使用
    多线程中互斥信号量(Mutex)的使用1.0互斥量的基本概念1.1Example\(\quad\)首先我们要明白,为什么会有互斥信号量的出现,在多线程编程中,不同的线程之间往往要对同一个数据进行操作,如果该数据是只读的,当然不会出现什么问题,但是如果两个线程同时对某个数据进行写操作,则可能出现难以......
  • 使用Vue+Vite搭建在线 C++ 源代码混淆工具,带在线实例
    就酱紫github开源地址:https://github.com/dffxd-suntra/cppdgithub在线实例:https://dffxd-suntra.github.io/cppd/预览图片:长截屏背景图重复了,抱歉......
  • 第三阶段C++提高编程(黑马程序员)——Day10
    4STL-函数对象4.1函数对象4.1.1函数对象概念概念:重载函数调用操作符的类,其对象常称为函数对象函数对象使用重载的()时,行为类似函数调用,也叫仿函数本质:函数对象(仿函数)是一个类,不是一个函数4.1.2函数对象使用特点:函数对象在使用时,可以像普通函数那样调用,可以有参数,可以有返回值函数......
  • C++11 同步与互斥
    C++11同步与互斥1.std中的锁1.1锁是实现互斥的方法,在std中实现了多种基本锁如下:std::mutex:最基本的互斥锁,只能在同一线程中进行加锁和解锁操作。std::recursive_mutex:递归互斥锁,允许同一线程多次加锁,但必须在同一线程中解锁相同次数。std::timed_mutex:定时互斥锁,允......
  • C++ Toolkit zz
    所谓“工欲善其事,必先利其器”,从程序员的角度来讲,好工具的使用总会给人带来事半功倍的效果。面对众多工具/软件,我们应该如何取舍呢。前不久,笔者在csdn的c++论坛发了一篇贴文,以期能征求大家的广泛意见,得到了不错的反响。本文在对该贴进行整理的基础上,又做了一些补充。在这里要特别......
  • c++算法之离散化
    什么是离散化?离散化,故离散数学,其中的“离散”就是不连续的意思。离散化可以保持原数值之间相对大小关系不变的情况下将其映射成正整数。也就是给可能用到的数值按大小关系分配一个编号,来代替原数值进行各种操作。离散化步骤:1.排序2.去重3.归位举一个例子:将{4000,201,11......