//computerRoom.h
#pragma once
#include <iostream>
using namespace std;
//机房类
class ComputerRoom {
public:
int m_ComId;//机房Id号
int m_MaxNum;//最大容量
};
//globalFile.h
#pragma once
//管理员文件
#define ADMIN_FILE "admin.txt"
//学生文件
#define STUDENT_FILE "student.txt"
//教师文件
#define TEACHER_FILE "teacher.txt"
//机房信息文件
#define COMPUTER_FILE "computerRoom.txt"
//订单文件
#define ORDER_FILE "order.txt"
//Identity.h
#pragma once
#include<iostream>
using namespace std;
class Identity {
public:
//操作菜单 纯虚函数
virtual void operMenu() = 0;
//用户名
string m_Name;
//用户密码
string m_Pwd;
};
//Manager.h
#pragma once
#include<iostream>
using namespace std;
#include "Identity.h"
#include <string>
#include <fstream>
#include "globalFile.h"
#include <vector>
#include "Student.h"
#include "Teacher.h"
#include "computerRoom.h"
class Manager : public Identity {
public:
//无参构造
Manager();
//有参构造
Manager(string name, string pwd);
//显示管理员菜单的操作界面
virtual void operMenu();
//添加账号
void addPerson();
//查看账号
void showPerson();
//查看机房信息
void showComputer();
//清空预约记录
void cleanFile();
//初始化容器
void initVector();
//检测重复 参数1 检测学号/职工号 参数2 检测类型
bool checkRepeat(int id, int type);
//学生容器
vector<Student>vStu;
//教师容器
vector<Teacher>vTea;
//机房信息
vector<ComputerRoom>vCom;
};
//orderFile.h
#pragma once
#include<iostream>
using namespace std;
#include "globalFile.h"
#include <fstream>
#include <map>
#include <string>
class OrderFile {
public:
//构造函数
OrderFile();
//更新预约条数
void updateOrder();
//记录预约条数
int m_Size;
//记录所有预约信息的容器, key记录条数 value 具体记录键值对信息
map<int, map<string, string>> m_orderData;
};
//Student.h
#pragma once
#include<iostream>
using namespace std;
#include "Identity.h"
#include <vector>
#include "computerRoom.h"
#include <fstream>
#include "globalFile.h"
#include "orderFile.h"
//学生类
class Student :public Identity{
public:
//默认构造
Student();
//有参构造
Student(int id , string name, string pwd);
//菜单界面
virtual void operMenu();
//申请预约
void applyOrder();
//查看自身预约
void showMyOrder();
//查看所有预约
void showAllOrder();
//取消预约
void cancelOrder();
//学生学号
int m_Id;
//机房容器
vector<ComputerRoom> vCom;
};
//Teacher.h
#pragma once
#include<iostream>
using namespace std;
#include "Identity.h"
#include "orderFile.h"
#include <vector>
//教师类设计
class Teacher :public Identity {
public:
//默认构造
Teacher();
//有参构造
Teacher(int empId, string name, string pwd);
//菜单
virtual void operMenu();
//查看所有预约
void showAllOrder();
//审批预约
void validOrder();
//职工id
int m_EmpId;
};
//Manager.cpp
#include "Manager.h"
#include <algorithm>
//无参构造
Manager::Manager() {
}
//有参构造
Manager::Manager(string name, string pwd) {
//初始化管理员信息
this->m_Name = name;
this->m_Pwd = pwd;
//初始化容器 获取到所有文件中 学生,老师信息
this->initVector();
//初始化机房信息
ifstream ifs;
ifs.open(COMPUTER_FILE, ios::in);
ComputerRoom com;
while (ifs >> com.m_ComId && ifs >> com.m_MaxNum) {
vCom.push_back(com);
}
ifs.close();
}
//显示管理员菜单的操作界面
void Manager::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 Manager::addPerson() {
cout << "请输入添加账号类型" << endl;
cout << "1,添加学生" << endl;
cout << "2,添加老师" << endl;
string fileName;//操作文件名
string tip;//提示id号
string errorTip;//重复错误提示
ofstream ofs;//文件操作对象
int select = 0;
cin >> select;//接受用户的选项
if (select == 1) {
//添加的是学生
fileName = STUDENT_FILE;
tip = "请输入学号:";
errorTip = "学号重复,请重新输入";
}
else {
fileName = TEACHER_FILE;
tip = "请输入职工编号:";
errorTip = "职工号重复,请重新输入";
}
//利用追加的方式写文件
ofs.open(fileName, ios::out | ios::app);
int id; //学号/职工号
string name; //姓名
string pwd; //密码
cout << tip << endl;
while (true) {
cin >> id;
bool ret = this->checkRepeat(id, select);
if (ret) {//有重复
cout << errorTip << endl;
}
else {
break;
}
}
cout << "请输入姓名:" << endl;
cin >> name;