从C向C++19——机房预约系统

一.系统需求

1.信息准备

身份信息:分别有三种身份使用该程序

  • 学生代表:申请使用机房
  • 教师:审核学生的预约申请
  • 管理员:给学生、教师创建账号

机房信息:机房总共有3间

  • 1号机房 — 最大容量20人
  • 2号机房 — 最多容量50人
  • 3号机房 — 最多容量100人

申请信息:

  • 申请的订单每周由管理员负责清空。
  • 学生可以预约未来一周内的机房使用,预约的日期为周一至周五,预约时需要选择预约时段(上午、下午)
  • 教师来审核预约,依据实际情况审核预约通过或者不通过

2.系统需求

  • 首先进入登录界面,可选登录身份有:
    • 学生代表
    • 老师
    • 管理员
    • 退出
  • 每个身份都需要进行验证后,进入子菜单
    • 学生需要输入 :学号、姓名、登录密码
    • 老师需要输入:职工号、姓名、登录密码
    • 管理员需要输入:管理员姓名、登录密码
  • 学生具体功能
    • 申请预约 — 预约机房
    • 查看自身的预约 — 查看自己的预约状态
    • 查看所有预约 — 查看全部预约信息以及预约状态
    • 取消预约 — 取消自身的预约,预约成功或审核中的预约均可取消
    • 注销登录 — 退出登录
  • 教师具体功能
    • 查看所有预约 — 查看全部预约信息以及预约状态
    • 审核预约 — 对学生的预约进行审核
    • 注销登录 — 退出登录
  • 管理员具体功能
    • 添加账号 — 添加学生或教师的账号,需要检测学生编号或教师职工号是否重复
    • 查看账号 — 可以选择查看学生或教师的全部信息
    • 查看机房 — 查看所有机房的信息
    • 清空预约 — 清空所有预约记录
    • 注销登录 — 退出登录

在这里插入图片描述

二.程序入口

main.cpp程序:

#include <iostream>
#include <string>
#include <fstream>
#include "globalfile.h"
#include "identy.h"
#include "student.h"
#include "teacher.h"
#include "manger.h"
using namespace std;

//进入学生界面
void studentmenu(Identy*& student)
{
	while (true)
	{
		student->opermenu();
		Student* stu = (Student*)student;
		
		int select = 0;
		cin >> select;

		if (select == 1) //申请预约
		{
			stu->applyorder();
		}
		else if (select == 2) //查看自身预约
		{
			stu->showmyorder();
		}
		else if (select == 3) //查看所有预约
		{
			stu->showallorder();
		}
		else if (select == 4) //取消预约
		{
			stu->cancerorder();
		}
		else
		{
			delete student;
			cout << "注销成功" << endl;
			system("pause");
			system("cls");
			return;
		}
	}
}

//进入教师菜单界面
void teachermenu(Identy *& teacher)
{
	while (true)
	{
		teacher->opermenu();
		Teacher* tea = (Teacher*)teacher;
		int select = 0;
		cin >> select;
		if (select == 1)
		{
			tea->showallmenu();
		}
		else if (select == 2)
		{
			tea->validorder();
		}
		else
		{
			delete teacher;
			cout << "注销成功" << endl;
			system("pause");
			system("cls");
			return;
		}
	}
}

//进入管理员菜单界面
void mangermenu(Identy*& manger)
{
	while (true)
	{
		manger->opermenu();              //父类指针只能调用重写的纯虚函数
		Manger* man = (Manger*)manger;

		int select = 0;
		cin >> select;
		if (select == 1)
		{
			//添加账号
			cout << "添加账号" << endl;
			man->addperson();
		}
		else if (select == 2)
		{
			//查看账号
			cout << "查看账号" << endl;
			man->showperson();
		}
		else if (select == 3)
		{
			//查看机房
			cout << "查看机房" << endl;
			man->showcomputer();
		}
		else if (select == 4)
		{
			//清空预约
			cout << "清空预约" << endl;
			man->cleanfile();
		}
		else
		{
			delete manger;
			cout << "注销成功" << endl;
			system("pause");
			system("cls");
			return;
		}
	}
}

//登录功能
void login(string filename,int type)
{
	Identy * person = NULL;                //父类指针,用于指向子类对象

	ifstream ifs;
	ifs.open(filename, ios::in);

	if (!ifs.is_open())
	{
		cout << "文件不存在" << endl;
		ifs.close();
		return;
	}

	int id=0;
	string name;
	string code;

	if (type == 1)
	{
		cout << "请输入你的学号:" << endl;
		cin >> id;
	}
	else if (type == 2)
	{
		cout << "请输入你的职工号:" << endl;
		cin >> id;
	}
	cout << "请输入用户名:" << endl;
	cin >> name;
	cout << "请输入密码:" << endl;
	cin >> code;

	if (type == 1)
	{
		//学生身份验证
		int fid;
		string fname;
		string fcode;
		while (ifs >> fid && ifs >> fname && ifs >> fcode)
		{
			if (id == fid && name == fname && code == fcode)
			{
				cout << "学生验证登录成功!" << endl;
				system("pause");
				system("cls");
				person = new Student(id, name, code);
				//进入学生身份菜单
				studentmenu(person);
				return;
			}
		}
	}
	else if (type == 2)
	{
		//教师身份验证
		int fid;
		string fname;
		string fcode;
		while (ifs >> fid && ifs >> fname && ifs >> fcode)
		{
			if (fid == id && fname == name && fcode == code)
			{
				cout << "老师验证登录成功!" << endl;
				system("pause");
				system("cls");
				person = new Teacher(id, name, code);
				//进入教师身份菜单
				teachermenu(person);
				return;
			}
		}
	}
	else if(type==3)
	{
		//管理员身份验证
		string fname;
		string fcode;
		while (ifs >> fname && ifs >> fcode)
		{
			if (fname == name && fcode == code)
			{
				cout << "管理员验证登录成功!" << endl;
				system("pause");
				system("cls");
				person = new Manger(name, code);
				//进入管理员身份菜单
				mangermenu(person);
				return;
			}
		}
	}

	cout << "验证登录失败!" << endl;
	system("pause");
	system("cls");
}



int main()
{
	int select = 0;        
	while (true)
	{
		cout << "======================  欢迎来到红太阳客机房预约系统  =====================" << endl;
		cout << endl << "请输入您的身份" << endl;
		cout << "\t\t -------------------------------\n";
		cout << "\t\t|                               |\n";
		cout << "\t\t|          1.学生代表           |\n";
		cout << "\t\t|                               |\n";
		cout << "\t\t|          2.老    师           |\n";
		cout << "\t\t|                               |\n";
		cout << "\t\t|          3.管 理 员           |\n";
		cout << "\t\t|                               |\n";
		cout << "\t\t|          0.退    出           |\n";
		cout << "\t\t|                               |\n";
		cout << "\t\t -------------------------------\n";
		cout << "输入您的选择: ";

		cin >> select;
		switch (select)
		{
		case 1://学生身份
			login(SF, 1);
			break;
		case 2://老师身份
			login(TF, 2);
			break;
		case 3://管理员身份
			login(AF, 3);
			break;
		case 0://退出系统
			cout << "欢迎下一次使用红太阳!" << endl;
			return 0;
			break;
		default:
			cout << "输入有误,请重新选择" << endl;
			system("pause");
			system("cls");
			break;
		}
    }

	system("pause");
	return 0;
}

三.头文件

1.基类

identy.h头文件:

#pragma once
#include <iostream>
#include <string>
using namespace std;

//身份抽象基类
class Identy
{
public:
	//操作餐单,纯虚函数
	virtual void opermenu() = 0;

	string m_name;
	string m_code;
};

2.学生类

student.h头文件:

#pragma once
#include <iostream>
#include "identy.h"
#include "computerroom.h"
#include <vector>
#include <fstream>
#include "globalfile.h"
#include "orderfile.h"
using namespace std;

//学生类
class Student :public Identy
{
public:
	Student();                                      //默认构造
	Student(int id,string name,string code);        //有参构造
	~Student();                                     //析构函数

	//成员方法
	void opermenu();                                //菜单界面                  
	void applyorder();                              //申请预约
	void showmyorder();                             //查看自身预约
	void showallorder();                            //查看所有预约
	void cancerorder();                             //取消预约

	//成员属性
	int m_id;                                       //学号
	vector<Computerroom> vcom;                      //机房容器
};

3.教师类

teacher.h头文件:

#pragma once
#include <iostream>
#include "identy.h"
#include "orderfile.h"
#include <vector>
using namespace std;

//教师类
class Teacher:public Identy
{
public:
	Teacher();                                         //默认构造
	Teacher(int empid,string name,string code);        //有参构造                                      
	~Teacher();                                        //析构函数

	//成员方法
	virtual void opermenu();                           //显示菜单
	void showallmenu();                                //查看所有预约
	void validorder();                                 //审核预约

	//成员属性
	int m_id;                                          //教师编号
};

4.管理员类

manger.h头文件:

#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include "globalfile.h"
#include "identy.h"
#include "student.h"
#include "teacher.h"
#include <algorithm>
#include "computerroom.h"
using namespace std;

//管理员类
class Manger :public Identy
{
public:
	Manger();                                                //默认构造
	Manger(string name,string code);                         //有参构造
	~Manger();                                               //析构函数

	//成员方法
	void opermenu();                                         //菜单界面
	void addperson();                                        //添加账号
	void showperson();                                       //查看账号
	void showcomputer();                                     //查看机房信息
	void cleanfile();                                        //清空预约信息
	void initvector();                                       //初始化容器
	bool checkrepeat(int id,int type);                       //查重函数

	//成员属性
	vector<Student> vstu;                                    //学生容器
	vector<Teacher> vtea;                                    //教师容器
	vector<Computerroom> vcom;                               //机房容器
};

5.机房类

computerroom.h头文件:

#pragma once
#include <iostream>
using namespace std;

//机房类
class Computerroom
{
public:
	int m_id;               //机房编号
	int m_cap;              //机房容量
};

6.文件名宏

globalfile.h头文件:

#pragma once

#define AF "admin.txt"
#define SF "student.txt"
#define TF "teacher.txt"
#define CF "computerroom.txt"
#define OF "order.txt"

7.预约类

orderfile.h头文件:

#pragma once
#include <iostream>
#include <string>
#include "computerroom.h"
#include <fstream>
#include "globalfile.h"
#include <map>

//预约类
class Orderfile
{
public:
	Orderfile();
	void updateorder();

	int m_size;                                   //记录预约条数
	map<int, map<string, string>> m_orderdata;    //记录容器
};

四.源文件

1.学生

student.cpp源文件:

#include "student.h"

//默认构造
Student::Student()
{

}

//有参构造
Student::Student(int id, string name, string code)
{
	this->m_id = id;
	this->m_name = name;
	this->m_code = code;

	//初始化机房信息
	ifstream ifs;
	ifs.open(CF, ios::in);
	Computerroom c;
	while (ifs >> c.m_id && ifs >> c.m_cap)
	{
		vcom.push_back(c);
	}
	ifs.close();
}

//析构函数
Student::~Student()
{

}

//实现菜单界面  
void Student::opermenu()
{
	cout << "欢迎学生代表:" << this->m_name << "登录!" << endl;
	cout << "\t\t ----------------------------------\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          1.申请预约              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          2.查看我的预约          |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          3.查看所有预约          |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          4.取消预约              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          0.注销登录              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t ----------------------------------\n";
	cout << "请选择您的操作: " << endl;
}

//申请预约
void Student::applyorder()
{
	cout << "机房开放时间为周一至周五!" << endl;
	cout << "请输入申请预约的时间:" << endl;
	cout << "1、周一" << endl;
	cout << "2、周二" << endl;
	cout << "3、周三" << endl;
	cout << "4、周四" << endl;
	cout << "5、周五" << endl;

	int data = 0;                 //日期
	int interval = 0;             //时间段
	int room = 0;                 //机房编号

	while (true)
	{
		cin >> data;
		if (data >= 1 && data <= 5)
		{
			break;
		}
		cout << "输入有误,请重新输入" << endl;
	}

	cout << "请输入申请预约的时间段:" << endl;
	cout << "1、上午" << endl;
	cout << "2、下午" << endl;

	while (true)
	{
		cin >> interval;
		if (interval >= 1 && interval <= 2)
		{
			break;
		}
		cout << "输入有误,请重新输入" << endl;
	}

	cout << "请选择机房:" << endl;
	cout << "1号机房容量:" << vcom[0].m_cap << endl;
	cout << "2号机房容量:" << vcom[1].m_cap << endl;
	cout << "3号机房容量:" << vcom[2].m_cap << endl;

	while (true)
	{
		cin >> room;
		if (room >= 1 && room <= 3)
		{
			break;
		}
		cout << "输入有误,请重新输入" << endl;
	}

	cout << "预约成功!审核中" << endl;

	ofstream ofs(OF, ios::app);
	ofs << "data:" << data << " ";
	ofs << "interval:" << interval << " ";
	ofs << "stuId:" << this->m_id << " ";
	ofs << "stuName:" << this->m_name << " ";
	ofs << "roomId:" << room << " ";
	ofs << "status:" << 1 << endl;

	ofs.close();

	system("pause");
	system("cls");
}

//查看自身预约
void Student::showmyorder()
{
	Orderfile of;
	if (of.m_size == 0)
	{
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	for (int i = 0; i < of.m_size; i++)
	{
		if (atoi(of.m_orderdata[i]["stuId"].c_str()) == this->m_id)       //将C++中strIng转化为int类型
		{
			cout << "预约日期: 周" << of.m_orderdata[i]["data"];
			cout << " 时段:" << (of.m_orderdata[i]["interval"] == "1" ? "上午" : "下午");
			cout << " 机房:" << of.m_orderdata[i]["roomId"];
			// 0 取消的预约   1 审核中   2 已预约 -1 预约失败
			string status = " 状态: ";  
			if (of.m_orderdata[i]["status"] == "1")
			{
				status += "审核中";
			}
			else if (of.m_orderdata[i]["status"] == "2")
			{
				status += "预约成功";
			}
			else if (of.m_orderdata[i]["status"] == "-1")
			{
				status += "审核未通过,预约失败";
			}
			else
			{
				status += "预约已取消";
			}
			cout << status << endl;

		}
	}

	system("pause");
	system("cls");
}

//查看所有预约
void Student::showallorder()
{
	Orderfile of;
	if (of.m_size == 0)
	{
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}

	for (int i = 0; i < of.m_size; i++)
	{
		cout << i + 1 << "、 ";
		cout << "预约日期: 周" << of.m_orderdata[i]["data"];
		cout << " 时段:" << (of.m_orderdata[i]["interval"] == "1" ? "上午" : "下午");
		cout << " 学号:" << of.m_orderdata[i]["stuId"];
		cout << " 姓名:" << of.m_orderdata[i]["stuName"];
		cout << " 机房:" << of.m_orderdata[i]["roomId"];
		// 0 取消的预约   1 审核中   2 已预约 -1 预约失败
		string status = " 状态: ";  
		if (of.m_orderdata[i]["status"] == "1")
		{
			status += "审核中";
		}
		else if (of.m_orderdata[i]["status"] == "2")
		{
			status += "预约成功";
		}
		else if (of.m_orderdata[i]["status"] == "-1")
		{
			status += "审核未通过,预约失败";
		}
		else
		{
			status += "预约已取消";
		}
		cout << status << endl;
	}

	system("pause");
	system("cls");
}

//取消预约
void Student::cancerorder()
{
	Orderfile of;
	if (of.m_size == 0)
	{
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	cout << "审核中或预约成功的记录可以取消,请输入取消的记录" << endl;
	vector<int>v;
	int index = 1;
	for (int i = 0; i < of.m_size; i++)
	{
		if (atoi(of.m_orderdata[i]["stuId"].c_str()) == this->m_id)
		{
			if (of.m_orderdata[i]["status"] == "1" || of.m_orderdata[i]["status"] == "2")
			{
				v.push_back(i);
				cout << index++ << "、 ";
				cout << "预约日期: 周" << of.m_orderdata[i]["date"];
				cout << " 时段:" << (of.m_orderdata[i]["interval"] == "1" ? "上午" : "下午");
				cout << " 机房:" << of.m_orderdata[i]["roomId"];
				// 0 取消的预约   1 审核中   2 已预约  -1 预约失败
				string status = " 状态: ";  
				if (of.m_orderdata[i]["status"] == "1")
				{
					status += "审核中";
				}
				else if (of.m_orderdata[i]["status"] == "2")
				{
					status += "预约成功";
				}
				cout << status << endl;
			}
		}
	}

	cout << "请输入取消的记录,0代表返回" << endl;
	int select = 0;
	while (true)
	{
		cin >> select;
		if (select >= 0 && select <= v.size())
		{
			if (select == 0)
			{
				break;
			}
			else
			{
				of.m_orderdata[v[select - 1]]["status"] = "0";
				of.updateorder();
				cout << "已取消预约" << endl;
				break;
			}
		}
		cout << "输入有误,请重新输入" << endl;
	}
}

2.老师

teacher.cpp源文件:

#include "teacher.h"

//默认构造
Teacher::Teacher()
{

}

//有参构造 
Teacher::Teacher(int empid, string name, string code)
{
	this->m_id = empid;
	this->m_name = name;
	this->m_code = code;
}

//析构函数
Teacher::~Teacher()
{

}

//显示菜单
void Teacher::opermenu()
{
	cout << "欢迎教师:" << this->m_name << "登录!" << endl;
	cout << "\t\t ----------------------------------\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          1.查看所有预约          |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          2.审核预约              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t|          0.注销登录              |\n";
	cout << "\t\t|                                  |\n";
	cout << "\t\t ----------------------------------\n";
	cout << "请选择您的操作: " << endl;
}

//查看所有预约
void Teacher::showallmenu()
{
	Orderfile of;
	if (of.m_size == 0)
	{
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	for (int i = 0; i < of.m_size; i++)
	{
		cout << i + 1 << "、 ";

		cout << "预约日期: 周" << of.m_orderdata[i]["data"];
		cout << " 时段:" << (of.m_orderdata[i]["interval"] == "1" ? "上午" : "下午");
		cout << " 学号:" << of.m_orderdata[i]["stuId"];
		cout << " 姓名:" << of.m_orderdata[i]["stuName"];
		cout << " 机房:" << of.m_orderdata[i]["roomId"];
		// 0 取消的预约   1 审核中   2 已预约 -1 预约失败
		string status = " 状态: ";  
		if (of.m_orderdata[i]["status"] == "1")
		{
			status += "审核中";
		}
		else if (of.m_orderdata[i]["status"] == "2")
		{
			status += "预约成功";
		}
		else if (of.m_orderdata[i]["status"] == "-1")
		{
			status += "审核未通过,预约失败";
		}
		else
		{
			status += "预约已取消";
		}
		cout << status << endl;
	}

	system("pause");
	system("cls");
}

//审核预约
void Teacher::validorder()
{
	Orderfile of;
	if (of.m_size == 0)
	{
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	cout << "待审核的预约记录如下:" << endl;

	vector<int> v;
	int index = 0;
	for (int i = 0; i < of.m_size; i++)
	{
		if (of.m_orderdata[i]["status"] == "1")
		{
			v.push_back(i);
			cout << ++index << "、 ";
			cout << "预约日期: 周" << of.m_orderdata[i]["data"];
			cout << " 时段:" << (of.m_orderdata[i]["interval"] == "1" ? "上午" : "下午");
			cout << " 机房:" << of.m_orderdata[i]["roomId"];
			string status = " 状态: ";  // 0取消的预约   1 审核中   2 已预约  -1 预约失败
			if (of.m_orderdata[i]["status"] == "1")
			{
				status += "审核中";
			}
			cout << status << endl;
		}
	}

	cout << "请输入审核的预约记录,0代表返回" << endl;
	int select = 0;
	int ret = 0;
	while (true)
	{
		cin >> select;
		if (select >= 0 && select <= v.size())
		{
			if (select == 0)
				break;
			else
			{
				cout << "请输入审核结果" << endl;
				cout << "1、通过" << endl;
				cout << "2、不通过" << endl;
				cin >> ret;
				if (ret == 1)
				{
					of.m_orderdata[v[select - 1]]["status"] = "2";
				}
				else if (ret == 2)
				{
					of.m_orderdata[v[select - 1]]["status"] = "-1";
				}
				of.updateorder();
				cout << "审核完毕!" << endl;
				break;
			}
		}
		else
			cout << "无效输入,请重新输入!" << endl;
	}
	system("pause");
	system("cls");
}

3.管理员

manger.cpp源文件:

#include "manger.h"

//默认构造
Manger::Manger()
{

}

//有参构造
Manger::Manger(string name, string code)
{
	this->m_name = name;
	this->m_code = code;

	this->initvector();

	//获取机房信息
	ifstream ifs;
	ifs.open(CF, ios::in);
	Computerroom c;
	while (ifs >> c.m_id && ifs >> c.m_cap)
	{
		vcom.push_back(c);
	}
	cout << "当前机房数量为: " << vcom.size() << endl;
	ifs.close();
}

//析构函数
Manger::~Manger()
{

}

//菜单界面
void Manger::opermenu()
{
	cout << "欢迎管理员:" << this->m_name << "登录!" << endl;
	cout << "\t\t ---------------------------------\n";
	cout << "\t\t|                                |\n";
	cout << "\t\t|          1.添加账号            |\n";
	cout << "\t\t|                                |\n";
	cout << "\t\t|          2.查看账号            |\n";
	cout << "\t\t|                                |\n";
	cout << "\t\t|          3.查看机房            |\n";
	cout << "\t\t|                                |\n";
	cout << "\t\t|          4.清空预约            |\n";
	cout << "\t\t|                                |\n";
	cout << "\t\t|          0.注销登录            |\n";
	cout << "\t\t|                                |\n";
	cout << "\t\t ---------------------------------\n";
	cout << "请选择您的操作: " << endl;
}

//添加账号
void Manger::addperson()
{
	cout << "请输入添加账号的类型" << endl;
	cout << "1、添加学生" << endl;
	cout << "2、添加老师" << endl;

	string filename;
	string tip;
	string errortip;
	ofstream ofs;

	int select = 0;
	cin >> select;

	if (select == 1)
	{
		filename = SF;
		tip = "请输入学号:";
		errortip = "学号重复,请重新输入!";
	}
	else if (select == 2)
	{
		filename = TF;
		tip = "请输入职工号:";
		errortip = "职工号重复,请重新输入!";
	}

	ofs.open(filename, ios::out | ios::app);

	int id;
	string name;
	string code;
	cout << tip << endl;
	while (true)
	{
		cin >> id;
		bool ret = checkrepeat(id, select);
		if (ret)
			cout << errortip << endl;
		else
			break;
	}
	cout << "请输入姓名:" << endl;
	cin >> name;
	cout << "请输入密码:" << endl;
	cin >> code;

	ofs << id << " " << name << " " << code<<endl;
	cout << "添加成功!" << endl;

	ofs.close();
	system("pause");
	system("cls");
	this->initvector();
}

//输出学生
void printStudent(Student&s)
{
	cout << "学号: " << s.m_id << " 姓名: " << s.m_name << " 密码:" << s.m_code << endl;
}
//输出老师
void printTeacher(Teacher& t)
{
	cout << "职工号: " << t.m_id << " 姓名: " << t.m_name << " 密码:" << t.m_code << endl;
}

//查看账号
void Manger::showperson()
{
	cout << "请选择查看内容:" << endl;
	cout << "1、查看所有学生" << endl;
	cout << "2、查看所有老师" << endl;

	int select = 0;
	cin >> select;
	if (select == 1)
	{
		cout << "所有学生信息如下: " << endl;
		for_each(vstu.begin(), vstu.end(), printStudent);
	}
	else if( select == 2)
	{
		cout << "所有老师信息如下: " << endl;
		for_each(vtea.begin(), vtea.end(), printTeacher);
	}

	system("pause");
	system("cls");
}

//查看机房信息
void Manger::showcomputer()
{
	cout << "机房信息如下: " << endl;
	for (vector<Computerroom>::iterator it = vcom.begin(); it != vcom.end(); it++)
	{
		cout << "机房编号: " << it->m_id << " 机房最大容量: " << it->m_cap << endl;
	}
	system("pause");
	system("cls");
}

//清空预约信息
void Manger::cleanfile()
{
	ofstream ofs(OF, ios::trunc);
	ofs.close();

	cout << "清空成功!" << endl;
	system("pause");
	system("cls");
}

//初始化容器
void Manger::initvector()
{
	//清空容器
	vstu.clear();
	vtea.clear();

	//读取信息(学生)
	ifstream ifs;
	ifs.open(SF, ios::in);
	if (!ifs.is_open())
	{
		cout << "文件读取失败" << endl;
		return;
	}
	Student s;
	while (ifs >> s.m_id && ifs >> s.m_name && ifs >> s.m_code)
	{
		vstu.push_back(s);
	}
	cout << "当前学生数量为:" << vstu.size() << endl;
	ifs.close();

	//读取信息(老师)
	ifs.open(TF, ios::in);
	if (!ifs.is_open())
	{
		cout << "文件读取失败" << endl;
		return;
	}
	Teacher t;
	while (ifs >> t.m_id && ifs >> t.m_name && ifs >> t.m_code)
	{
		vtea.push_back(t);
	}
	cout << "当前教师数量为:" << vtea.size() << endl;
	ifs.close();
}

//查重函数
bool Manger::checkrepeat(int id,int type)
{
	if (type == 1)
	{
		for (vector<Student>::iterator it = vstu.begin(); it != vstu.end(); it++)
		{
			if (id == it->m_id)
			{
				return true;
			}
		}
	}
	else if (type == 2)
	{
		for (vector<Teacher>::iterator it = vtea.begin(); it != vtea.end(); it++)
		{
			if (id == it->m_id)
			{
				return true;
			}
		}
	}
	return false;
}

4.预约信息

orderfile.cpp源文件:

#include "orderfile.h"

Orderfile::Orderfile()
{
	ifstream ifs;
	ifs.open(OF, ios::in);

	string data;      //日期
	string interval;  //时间段
	string stuId;     //学生编号
	string stuName;   //学生姓名
	string roomId;    //机房编号
	string status;    //预约状态
	this->m_size = 0;

	while (ifs >> data && ifs >> interval && ifs >> stuId && ifs >> stuName && ifs >> roomId && ifs >> status)
	{
		string key;
		string value;
		map<string, string> m;

		int pos = data.find(":");
		if (pos != -1)
		{
			key = data.substr(0, pos);
			value = data.substr(pos + 1, data.size() - pos - 1);
			m.insert(make_pair(key, value));
		}

		pos = interval.find(":");
		if (pos != -1)
		{
			key = interval.substr(0, pos);
			value = interval.substr(pos + 1, interval.size() - pos - 1);
			m.insert(make_pair(key, value));
		}

		pos = stuId.find(":");
		if (pos != -1)
		{
			key = stuId.substr(0, pos);
			value = stuId.substr(pos + 1, stuId.size() - pos - 1);
			m.insert(make_pair(key, value));
		}

		pos = stuName.find(":");
		if (pos != -1)
		{
			key = stuName.substr(0, pos);
			value = stuName.substr(pos + 1, stuName.size() - pos - 1);
			m.insert(make_pair(key, value));
		}

		pos = roomId.find(":");
		if (pos != -1)
		{
			key = roomId.substr(0, pos);
			value = roomId.substr(pos + 1, roomId.size() - pos - 1);
			m.insert(make_pair(key, value));
		}

		pos = status.find(":");
		if (pos != -1)
		{
			key = status.substr(0, pos);
			value = status.substr(pos + 1, status.size() - pos - 1);
			m.insert(make_pair(key, value));
		}
		this->m_orderdata.insert(make_pair(this->m_size, m));
		this->m_size++;
	}

	ifs.close();
}

void Orderfile::updateorder()
{
	if (this->m_size == 0)
	{
		return;
	}

	ofstream ofs(OF, ios::out | ios::trunc);
	for (int i = 0; i < m_size; i++)
	{
		ofs << "datea:" << this->m_orderdata[i]["data"] << " ";
		ofs << "interval:" << this->m_orderdata[i]["interval"] << " ";
		ofs << "stuId:" << this->m_orderdata[i]["stuId"] << " ";
		ofs << "stuName:" << this->m_orderdata[i]["stuName"] << " ";
		ofs << "roomId:" << this->m_orderdata[i]["roomId"] << " ";
		ofs << "status:" << this->m_orderdata[i]["status"] << endl;
	}
	ofs.close();
}

d.size() - pos - 1);
m.insert(make_pair(key, value));
}

	pos = stuName.find(":");
	if (pos != -1)
	{
		key = stuName.substr(0, pos);
		value = stuName.substr(pos + 1, stuName.size() - pos - 1);
		m.insert(make_pair(key, value));
	}

	pos = roomId.find(":");
	if (pos != -1)
	{
		key = roomId.substr(0, pos);
		value = roomId.substr(pos + 1, roomId.size() - pos - 1);
		m.insert(make_pair(key, value));
	}

	pos = status.find(":");
	if (pos != -1)
	{
		key = status.substr(0, pos);
		value = status.substr(pos + 1, status.size() - pos - 1);
		m.insert(make_pair(key, value));
	}
	this->m_orderdata.insert(make_pair(this->m_size, m));
	this->m_size++;
}

ifs.close();

}

void Orderfile::updateorder()
{
if (this->m_size == 0)
{
return;
}

ofstream ofs(OF, ios::out | ios::trunc);
for (int i = 0; i < m_size; i++)
{
	ofs << "datea:" << this->m_orderdata[i]["data"] << " ";
	ofs << "interval:" << this->m_orderdata[i]["interval"] << " ";
	ofs << "stuId:" << this->m_orderdata[i]["stuId"] << " ";
	ofs << "stuName:" << this->m_orderdata[i]["stuName"] << " ";
	ofs << "roomId:" << this->m_orderdata[i]["roomId"] << " ";
	ofs << "status:" << this->m_orderdata[i]["status"] << endl;
}
ofs.close();

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨城烟柳ベ旧人殇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值