<C++>13 项目:机房预约系统
本文最后更新于:2023年6月27日 上午
13 项目:机房预约系统
13.1 项目需求
有数个规格不同的机房,现开发一套预约系统,以解决使用冲突
三种身份代表:学生(申请使用)、教师(审核预约)、管理员(创建学生、教师账号)
机房共有三间:1号机房(20人)、2号机房(50人)、3号机房(100人)
管理员:申请的订单每周由管理员手动清空
学生:可以预约未来一周内的机房使用,日期为周一至周五,可选时段为上午或下午
教师:审核预约,选择通过或不通过
菜单:
- 学生(学号、姓名、登陆密码)
- 申请预约
- 查看自身预约
- 查看所有预约
- 取消预约(成功的预约或审核中的预约)
- 注销登录(二次确认)
- 老师(职工号、姓名、登陆密码)
- 查看所有预约
- 审核预约
- 注销登录(二次确认)
- 管理员(管理员编号、登陆密码)
- 添加账号
- 查看账号
- 修改账号
- 查看机房
- 清空预约记录
- 注销登录(二次确认)
- 退出
账号:
- 账号类(ID、姓名、密码、标识符)
- 管理员(ID 为 000000,标识符)
- 教师(ID 为 1000XX,标识符)
- 学生(ID 为 3000XX,标识符)
机房:
- 机房类(容量,预约记录)
附录
机房预约系统
执行以下代码
#include "menu.h" int main() { menu0(); }
#1 2头文件:
room.h
包含机房类。还声明了一个预定信息类。
这两个类的实现都在:room.cpp
#pragma once
#include"person.h"
class List; // 预定信息类
class Room { // 机房类
public:
Room(int seats); // 构造器,初始指定那个座位数
bool add_request(List* list); // 添加预定
bool confirm_request(vector<List*>::const_iterator r, bool passed, Teacher* t, bool link = false);
// 完成预定
void clear(); // 清空信息
void showAllTBD(); // 显示全部 待审核预定 的信息
void showAllD(); // 显示全部 已审核预定 的信息
int getSeat(); // 返回那个座位数
string getName(); // 返回机房名称
bool cancel(vector<List*>::const_iterator tar);
// 取消一个 待审核预定
static vector<Room*>* rooms; // 机房集。静态容器,包含全部机房
vector<List*> tbd; // 待审核集。该容器包含全部 待审核预定
vector<List*> confirmed; // 已审核集。该容器包含全部 已审核预定
private:
int seats; // 座位数
string name; // 机房名
static int m_name_count; // 静态变量。初始化时自动分配机房名称
};
person.h
包含所有账号类,以及预定信息类
账号类:Person(信息账号类)、Student(学生账号类)、Teacher(教师账号类)、Manager(管理员账号类)
账号类的实现在:person.cpp
预定信息类的实现在:room.cpp
#pragma once
#include<iostream>
using namespace std;
#include<string>
#include<vector>
class List;
class Room;
class Person { // 信息账号类。该类是所有账号类的父类
public:
int getID(); // 获取账号 ID
char getSign(); // 获取账号标记(教师为 T,学生为 S,管理员为 M,信息为 W)
string getName();
void setName(string name);
void setID(int id);
void setPW(string ne);
bool checkPW(string pw); // 检查密码是否正确
string print(); // 返回该账号的信息构成的字符串
static Person* reject_has_existed; // 一个静态的实例。当提交的预定与当前已审核的预定冲突时,用该实例进行标记
protected:
Person(); // 构造器。不允许实例化该类对象
Person(string name, int id);
string name; // 姓名
int id = -1; // ID
char sign = 'P'; // 账号标记(教师为 T,学生为 S,管理员为 M,信息为 W)
string password; // 密码
};
class Manager: public Person { // 管理员类
public:
Manager(string name, string pw);
static Manager* getManager(); // 静态方法。返回唯一的管理员账号实例。
Person* createAccount(char identity, string name, string pw);
// 创建账号
private:
static Manager* ss; // 静态实例。管理员账号是唯一的,就是这个实例
static int m_id_count;
};
class Student : public Person { // 学生类
public:
Student(string name, string pw);
static vector<Student*>* all(); // 静态方法。返回包含全部学生实例的容器
List* order(int date, bool time); // 返回一个新的预约
static Student* find(int id); // 静态方法。按 ID 查找学生
static Student* find(string name); // 静态方法。按姓名查找学生
private:
static vector<Student*>* ss; // 学生集。静态容器。是包含全部学生实例的容器
static int m_id_count; // 实例化学生类时自动分配 ID
};
class Teacher : public Person { // 教师类
public:
Teacher(string name, string pw);
static vector<Teacher*>* all(); // 静态方法。返回包含全部教师实例的容器
List* confirm(List* l, bool b); // 返回一个经过审核的预约
static Teacher* find(int id);
static Teacher* find(string name);
private:
static vector<Teacher*>* ss; // 教师集。静态容器。是包含全部教师实例的容器
static int m_id_count;
};
class List { // 预约信息类
public:
Person* requester; // 此处一般是一个 Student*,表示预约人的信息
Person* confirmer; // 此处可能是一个 Teacher*,也可能是一个 Person*
// Teacher* 的场合,表示审核人的信息
// Person* 的场合,表示那个错误的原因
int state; // 审核状态:0待审核、1通过、-1拒绝
int date; // 日期,范围是 1 - 7(周一 ~ 周日)
bool time; // 时段:true 上午、false 下午
Room* room; // 机房
List(int date, bool time, Student* s);
void confirm(bool pass, Person* t); // 更新审核状态
string print(); // 返回预约信息构成的字符串
};
menu.h
菜单。程序的主干。
执行
menu0()
以进入机房预约系统
#pragma once
#include"room.h"
void testing_initial(); // 测试初始化。这个方法初始化了数个账号及机房,以供测试之用
void menu0(); // 程序的主入口
void show_menu0(); // 显示 一级菜单
Person* log_in(int n); // 尝试登录。返回将要登录的账号信息
void menu_stu(); // 学生菜单入口
void show_menu_stu(); // 显示 学生菜单
void menu_tea(); // 教师菜单入口
void show_menu_tea(); // 显示 教师菜单
void menu_man(); // 管理员菜单入口
void show_menu_man(); // 显示 管理员菜单
bool log_out(); // 登出的二次确认
void stu_order(Student* student); // 预约机房
void check_order(Student* student); // 查看该账号的所有预约
int check_all(); // 查看所有预约
int check_all_tbd(); // 查看所有 未审核的预约
int check_all_confirmed(); // 查看所有 审核通过的预约(不包含被拒绝的预约)
void cancel(Student* student); // 取消一条 未审核的预约
void confirm(Teacher* t); // 审核预约
bool confirm_it(int num, bool passed, Teacher* t);
// 审核预约的执行程序
void add_account(Manager* m); // 添加账号
void show_accounts(); // 展示全部账号
void change_account(); // 修改一个账号的信息
void show_rooms(); // 展示全部机房
void clear_history(); // 清空预约记录
#2 源文件:
room.cpp
#include"room.h"
Room::Room(int seats) {
this->seats = seats;
this->name = "机房" + to_string(++m_name_count);
/* 实例化时,自动将自身放入 Room::rooms 房间集 */
rooms->push_back(this);
};
bool Room::add_request(List* list) {
list->room = this;
/* 同一账号不能重复添加内容完全相同的请求 */
for (vector<List*>::const_iterator i = this->tbd.begin(); i != this->tbd.end(); i++) {
List* temp = *i;
if (temp->requester == list->requester && temp->date == list->date && temp->time == list->time) {
return false;
}
}
/* 如果指定机房在指定时段已被占用,直接拒绝该请求 */
for (vector<List*>::const_iterator i = this->confirmed.begin(); i != this->confirmed.end(); i++) {
List* temp = *i;
if (temp->state > 0 && temp->date == list->date && temp->time == list->time) {
/* 向该请求添加错误信息 */
list->confirm(false, Person::reject_has_existed);
confirmed.push_back(list);
return false;
}
}
/* 检查通过后,将该请求放入 待审核集 */
this->tbd.push_back(list);
return true;
};
bool Room::confirm_request(vector<List*>::const_iterator r, bool passed, Teacher* t,bool link){
/* 这是正在审核的预约对象 */
List* list = *r;
/* 如果审核结果是通过,那么有必要同时拒绝所有其他相同时间的未审核预定 */
if (passed) link = true;
/* 从 未审核集 中移除该预约 */
tbd.erase(r);
/* 在 已审核集 中进行搜索。时间安排如有冲突则直接拒绝 */
for (vector<List*>::const_iterator i = confirmed.begin(); i != confirmed.end(); i++) {
List* temp = *i;
if (temp->state > 0 && temp->date == list->date && temp->time == list->time) {
/* 向该请求添加错误信息 */
list->confirm(false, Person::reject_has_existed);
confirmed.push_back(list);
return false;
}
}
/* 更新该预约的审核状态 */
list->confirm(passed, t);
/* 认为需要拒绝其他请求时,递归调用此方法,直至拒绝了全部请求 */
if (link) {
for (vector<List*>::const_iterator i = tbd.begin(); i != tbd.end(); i++) {
List* temp = *i;
if (temp->date == list->date && temp->time == list->time) {
confirm_request(i, false, t, true);
break;
}
}
}
/* 不需要拒绝其他请求时,将该预约添加到 已审核集。 */
this->confirmed.push_back(list);
return true;
};
/* 清空该机房所有预定记录 */
void Room::clear(){
for (vector<List*>::const_iterator i = confirmed.begin(); i != confirmed.end(); i++) {
delete* i;
}
confirmed.clear();
for (vector<List*>::const_iterator i = tbd.begin(); i != tbd.end(); i++) {
delete* i;
}
tbd.clear();
tbd.swap(confirm);
};
void Room::showAllTBD(){
cout << "机房:" << name << "待确认申请如下:" << endl;
cout << "申请人ID\t姓名\t日期\t时段\t申请状态\t审核ID\t审核姓名" << endl;
for (vector<List*>::const_iterator i = tbd.begin(); i != tbd.end(); i++) {
List* temp = *i;
cout << temp->print() << endl;
}
};
void Room::showAllD(){
cout << "机房:" << name << "已完成申请如下:" << endl;
cout << "申请人ID\t姓名\t日期\t时段\t申请状态\t审核ID\t审核姓名" << endl;
for (vector<List*>::const_iterator i = confirmed.begin(); i != confirmed.end(); i++) {
List* temp = *i;
cout << temp->print() << endl;
}
};
int Room::getSeat() {
return this->seats;
};
string Room::getName() {
return this->name;
};
bool Room::cancel(vector<List*>::const_iterator tar) {
this->tbd.erase(tar);
return true;
};
List::List(int date, bool time, Student* s) {
this->date = date;
this->time = time;
this->requester = s;
this->state = 0;
this->confirmer = NULL;
this->room = NULL;
};
void List::confirm(bool pass, Person* t) {
this->confirmer = t;
if (pass) this->state = 1;
else this->state = -1;
};
string List::print() {
string ret = requester->print() + "\t周" + to_string(date) + "\t" + (time ? "上午" : "下午") + "\t";
if (state == 0) {
ret += "审核中";
}
else {
ret += (state > 0 ? "通过" : "拒绝");
ret += "\t" + confirmer->print();
}
return ret;
};
int Room::m_name_count = 0;
vector<Room*>* Room::rooms = new vector<Room*>;
person.cpp
#include"person.h"
int Person::getID() {
return id;
}
char Person::getSign() {
return sign;
}
string Person::getName() {
return name;
}
void Person::setName(string name) {
this->name = name;
}
void Person::setID(int id) {
this->id = id;
}
void Person::setPW(string ne) {
password = ne;
}
bool Person::checkPW(string pw) {
return pw == password;
}
string Person::print() {
return to_string(id) + "\t" + name;
};
Person::Person(){};
Person::Person(string name, int id) {
this->name = name;
this->id = id;
this->sign = 'W';
};
Manager::Manager(string name, string pw) {
this->name = name;
this->id = m_id_count;
this->password = pw;
this->sign = 'M';
};
Student::Student(string name, string pw) {
this->name = name;
this->id = ++m_id_count;
this->password = pw;
this->sign = 'S';
/* 实例化学生对象时,该对象会被自动添加到 学生集 */
Student::ss->push_back(this);
};
Teacher::Teacher(string name, string pw) {
this->name = name;
this->id = ++m_id_count;
this->password = pw;
this->sign = 'T';
/* 实例化教师对象时,该对象会被自动添加到 教师集 */
Teacher::ss->push_back(this);
};
List* Student::order(int date, bool time) {
List* order = new List(date, time, this);
return order;
}
List* Teacher::confirm(List* l, bool b) {
l->confirm(b, this);
return l;
};
vector<Student*>* Student::all() {
return ss;
};
Manager* Manager::getManager() {
return ss;
};
vector<Teacher*>* Teacher::all() {
return ss;
};
Student* Student::find(int id) {
for (vector<Student*>::const_iterator i = ss->begin(); i != ss->end(); i++) {
Student* temp = *i;
if (temp->id == id) {
return temp;
}
}
return NULL;
};
Student* Student::find(string name) {
for (vector<Student*>::const_iterator i = ss->begin(); i != ss->end(); i++) {
Student* temp = *i;
if (temp->name == name) {
return temp;
}
}
return NULL;
};
Teacher* Teacher::find(int id) {
for (vector<Teacher*>::const_iterator i = ss->begin(); i != ss->end(); i++) {
Teacher* temp = *i;
if (temp->id == id) {
return temp;
}
}
return NULL;
};
Teacher* Teacher::find(string name) {
for (vector<Teacher*>::const_iterator i = ss->begin(); i != ss->end(); i++) {
Teacher* temp = *i;
if (temp->name == name) {
return temp;
}
}
return NULL;
};
Person* Manager::createAccount(char identity, string name, string pw) {
Person* get;
switch (identity) {
case 'S':
get = Student::find(name);
if (get != NULL) return NULL;
else {
return new Student(name, pw);
}
case 'T':
get = Teacher::find(name);
if (get != NULL) return NULL;
else {
return new Teacher(name, pw);
}
case 'M':
return NULL;
default:
return NULL;
}
};
/* 以下是一些静态变量的初始化 */
Person* Person::reject_has_existed = new Person("机房已被占用", -9001); // 错误信息
vector<Student*>* Student::ss = new vector<Student*>; // 学生集
Manager* Manager::ss = new Manager("Heruin", "000000"); // 管理员初始化
vector<Teacher*>* Teacher::ss = new vector<Teacher*>; // 教师集
int Manager::m_id_count = 0;
int Student::m_id_count = 300000;
int Teacher::m_id_count = 100000;
menu.cpp
#include "menu.h"
Person* user = NULL;
void testing_initial() { // 初始化了一些账号和机房,以便测试之用
new Student("胡桃", "000000");
new Student("香菱", "000000");
new Student("行秋", "000000");
new Student("重云", "000000");
new Teacher("甘雨", "000000");
new Teacher("凝光", "000000");
new Room(15);
new Room(20);
new Room(40);
};
void menu0() {
testing_initial(); /* initial for test only */
bool running = true;
while (running) {
show_menu0();
cout << "请选择:";
int choice = 0;
cin >> choice;
if (choice > 0 && choice < 4) {
user = log_in(choice);
if (user == NULL) {
cout << "登录失败" << endl;
system("pause");
system("cls");
continue;
}
}
switch (choice) {
case 1:
system("cls");
menu_stu();
break;
case 2:
system("cls");
menu_tea();
break;
case 3:
system("cls");
menu_man();
break;
case 9:
if (log_out()) {
running = false;
}
break;
default:
cout << "输入有误,请重新输入" << endl;
break;
}
user = NULL;
if (running) system("pause");
system("cls");
}
};
void show_menu0() {
cout << "—————机房预约系统(登陆页面)—————" << endl;
cout << "\t\t1 学 生 登 录" << endl;
cout << "\t\t2 教 师 登 录" << endl;
cout << "\t\t3 管 理 员 登 录" << endl;
cout << "\t\t9 退 出 系 统" << endl;
};
Person* log_in(int n) {
cout << endl << "——————————" << endl;
cout << "请输入 ID:";
int id;
cin >> id;
cout << endl << "请输入密码:";
string pw;
cin >> pw;
if (n == 1) {
Student* ts = Student::find(id);
if (ts == NULL || !ts->checkPW(pw)) {
return NULL;
}
else return ts;
}
else if (n == 2) {
Teacher* ts = Teacher::find(id);
if (ts == NULL || !ts->checkPW(pw)) {
return NULL;
}
else return ts;
}
else if (n == 3) {
Manager* manager = Manager::getManager();
if (id == manager->getID() && manager->checkPW(pw)) {
return manager;
}
else return NULL;
}
else {
return NULL;
}
};
void menu_stu() {
bool running = true;
Student* student = (Student*)user;
while (running) {
show_menu_stu();
cout << "请选择:";
int choice;
cin >> choice;
switch (choice) {
case 1:
stu_order(student);
break;
case 2:
check_order(student);
break;
case 3:
check_all();
break;
case 4:
cancel(student);
break;
case 9:
if (log_out()) {
running = false;
}
break;
default:
cout << "输入有误" << endl;
break;
}
if (running) system("pause");
system("cls");
}
};
void show_menu_stu() {
cout << "————机房预约系统(学生端:" << user->getID() << " " << user->getName() << ")————" << endl;
cout << "\t\t1 预 约 机 房" << endl;
cout << "\t\t2 预 约 查 询" << endl;
cout << "\t\t3 机 房 状 态 查 询" << endl;
cout << "\t\t4 取 消 预 约" << endl;
cout << "\t\t9 注 销 登 录" << endl;
};
void menu_tea() {
bool running = true;
Teacher* teacher = (Teacher*)user;
while (running) {
show_menu_tea();
cout << "请选择:";
int choice = 0;
cin >> choice;
switch (choice) {
case 1:
check_all();
break;
case 2:
confirm(teacher);
break;
case 9:
if (log_out()) {
running = false;
}
break;
default:
cout << "输入有误" << endl;
break;
}
if (running) system("pause");
system("cls");
}
};
void show_menu_tea() {
cout << "————机房预约系统(教师端:" << user->getID() << " " << user->getName() << ")————" << endl;
cout << "\t\t1 查 看 预 约" << endl;
cout << "\t\t2 审 核 查 询" << endl;
cout << "\t\t9 注 销 登 录" << endl;
};
void menu_man() {
Manager* manager = (Manager*)user;
bool running = true;
while (running) {
show_menu_man();
cout << "请选择:";
int choice = 0;
cin >> choice;
switch (choice) {
case 1:
add_account(manager);
break;
case 2:
show_accounts();
break;
case 3:
change_account();
break;
case 4:
show_rooms();
break;
case 5:
clear_history();
break;
case 9:
if (log_out()) {
running = false;
}
break;
default:
cout << "输入有误" << endl;
break;
}
if (running) system("pause");
system("cls");
}
};
void show_menu_man() {
cout << "————机房预约系统(管理员:" << user->getID() << " " << user->getName() << ")————" << endl;
cout << "\t\t1 添 加 账 号" << endl;
cout << "\t\t2 查 看 账 号" << endl;
cout << "\t\t3 修 改 账 号" << endl;
cout << "\t\t4 查 看 机 房" << endl;
cout << "\t\t5 清 空 记 录" << endl;
cout << "\t\t9 注 销 登 录" << endl;
};
bool log_out() {
char confirm = 'N';
cout << endl << "确定要退出吗?(Y / N):";
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
return true;
}
else {
return false;
}
};
void stu_order(Student* student) {
cout << endl << "============预 定 机 房============" << endl;
show_rooms();
cout << "请输入要预定的机房序号:";
int room = 0;
cin >> room;
room--;
if (room >= Room::rooms->size() || room < 0) {
cout << "输入错误:不存在的机房" << endl;
}
cout << endl << "请输入要预定的日期(周一 到 周末)" << endl;
cout << "输入 1 - 7 的数字:";
int date = 0;
cin >> date;
if (date < 1 || date > 7) {
cout << "输入错误:日期需是 1 - 7 的整数" << endl;
return;
}
char time = 'P';
cout << endl << "请输入要预定的时间段(N 上午/ A 下午):";
cin >> time;
bool t = true;
if (time == 'N' || time == 'n') {
t = true;
}
else if (time == 'A' || time == 'a') {
t = false;
}
else {
cout << "输入错误:只能是上午(N)或下午(A)" << endl;
return;
}
Room* temp = Room::rooms->at(room);
if (temp->add_request(student->order(date, t))) {
cout << "预定提交成功" << endl;
}
else {
cout << "预定提交失败" << endl;
}
};
void check_order(Student* student) {
cout << endl << "============预 定 查 询============" << endl;
int count = 1;
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp_room = *i;
cout << "☆·" << temp_room->getName() << endl;
for (vector<List*>::const_iterator il = temp_room->tbd.begin(); il != temp_room->tbd.end(); il++) {
List* temp = *il;
if (temp->requester == student) {
cout << "\t<" << count++ << "> " << temp->print() << endl;
}
}
for (vector<List*>::const_iterator il = temp_room->confirmed.begin(); il != temp_room->confirmed.end(); il++) {
List* temp = *il;
if (temp->requester == student) {
cout << "\t<" << count++ << "> " << temp->print() << (temp -> state > 0 ? "\t★" : "\t☆") << endl;
}
}
}
};
int check_all() {
cout << endl << "============查 看 全 部 预 约============" << endl;
int ret = 0;
ret += check_all_tbd();
cout << endl;
ret += check_all_confirmed();
return ret;
};
int check_all_tbd() {
cout << "==============待 审 核 预 约=============" << endl;
int count = 1;
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp_room = *i;
cout << "☆·" << temp_room->getName() << endl;
for (vector<List*>::const_iterator il = temp_room->tbd.begin(); il != temp_room->tbd.end(); il++) {
List* temp = *il;
cout << "\t<" << count++ << "> " << temp->print() << endl;
}
}
return count - 1;
};
int check_all_confirmed() {
cout << "==============已 通 过 预 约=============" << endl;
int count = 1;
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp_room = *i;
cout << "★·" << temp_room->getName() << endl;
for (vector<List*>::const_iterator il = temp_room->confirmed.begin(); il != temp_room->confirmed.end(); il++) {
List* temp = *il;
if (temp->state < 0) continue;
cout << "\t<" << count++ << "> " << temp->print() << endl;
}
}
return count - 1;
};
void cancel(Student* student) {
cout << endl << "============取 消 预 定===========" << endl;
int n = 1;
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp_room = *i;
cout << "☆·" << temp_room->getName() << endl;
for (vector<List*>::const_iterator il = temp_room->tbd.begin(); il != temp_room->tbd.end(); il++) {
List* temp = *il;
if (temp->requester == student) {
cout << "\t<" << n++ << "> " << temp->print() << endl;
}
}
}
cout << "请输入要取消的订单号:";
int num = 0;
cin >> num;
if (num < 1 || num > n) {
cout << "输入有误:(输入值 " << num << ",订单号范围 " << 1 << " - " << n << ")" << endl;
return;
}
n = 1;
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp_room = *i;
for (vector<List*>::const_iterator il = temp_room->tbd.begin(); il != temp_room->tbd.end(); il++) {
List* temp = *il;
if (temp->requester == student) {
if (n == num) {
if (temp_room->cancel(il)) {
cout << "取消成功" << endl;
}
else {
cout << "取消失败!" << endl;
}
return;
}
else {
n++;
}
}
}
}
};
void confirm(Teacher* t) {
cout << endl << "★============·审 核 预 约·===========★" << endl;
int count = check_all_tbd();
if (count == 0) {
cout << "当前没有要审核的预约" << endl;
return;
}
cout << "输入要批复的预约编号:";
int num = 0;
cin >> num;
cout << endl << "是否批准?(Y / N):";
char con = 'P';
cin >> con;
bool done = false;
switch (con) {
case'Y':
case'y':
done = confirm_it(num, true, t);
break;
case'n':
case'N':
done = confirm_it(num, false, t);
break;
default:
cout << "输入错误!" << endl;
break;
}
if (done) {
cout << "审核成功" << endl;
}
else {
cout << "审核失败!" << endl;
}
cout << "是否继续?(Y / N):";
cin >> con;
if (con == 'Y' || con == 'y' || con == '1') confirm(t);
};
bool confirm_it(int num, bool passed, Teacher* t) {
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp_room = *i;
for (vector<List*>::const_iterator il = temp_room->tbd.begin(); il != temp_room->tbd.end(); il++) {
num--;
if (num == 0) {
temp_room->confirm_request(il, passed, t);
return true;
}
}
}
return false;
}
void add_account(Manager* m) {
cout << "★=============·创 建 账 号·=============★" << endl;
cout << "请输入姓名:";
string name = "";
cin >> name;
cout << "请输入初始密码:";
string pw = "";
cin >> pw;
cout << "要创建何种账号?(S 学生账号/ T 教师账号):";
char acc = 'M';
cin >> acc;
Person* p = NULL;
switch (acc) {
case's':
case'S':
p = m->createAccount('S', name, pw);
break;
case'T':
case't':
p = m->createAccount('T', name, pw);
break;
case'm':
case'M':
p = m->createAccount('M', name, pw);
break;
default:
cout << "输入错误!" << endl;
return;
}
if (p == NULL) {
cout << "创建失败!" << endl;
}
else {
cout << "创建成功:" << endl;
cout << "\t" << p->print() << endl;
}
cout << "继续吗?(Y / N):";
cin >> acc;
if (acc == 'y' || acc == 'Y' || acc == '1') add_account(m);
};
void show_accounts() {
cout << "=================显示全部账号=================" << endl;
cout << "———————学 生 账 号———————" << endl;
if (Student::all()->empty()) {
cout << "\t\t 尚无学生账号" << endl;
}
else {
for (vector<Student*>::const_iterator i = Student::all()->begin(); i != Student::all()->end(); i++) {
Student* temp = *i;
cout << temp->print() << endl;
}
}
cout << "———————教 师 账 号———————" << endl;
if (Teacher::all()->empty()) {
cout << "\t\t 尚无教师账号" << endl;
}
else {
for (vector<Teacher*>::const_iterator i = Teacher::all()->begin(); i != Teacher::all()->end(); i++) {
Teacher* temp = *i;
cout << temp->print() << endl;
}
}
};
void change_account() {
show_accounts();
cout << "★=============·修改账号信息·=============★" << endl;
cout << "请输入更改账号的类别(S 学生账号/ T 教师账号):";
char acc = 'M';
cin >> acc;
cout << "请输入账号 ID:";
int id = 0;
cin >> id;
Person* account = NULL;
switch (acc) {
case 's':
case 'S':
account = Student::find(id);
break;
case 't':
case 'T':
account = Teacher::find(id);
break;
case 'm':
case 'M':
return;
default:
cout << "错误的账号类别!" << endl;
return;
}
if (account == NULL) {
cout << "未找到该账号" << endl;
return;
}
else {
cout << account->print() << endl;
}
cout << "请输入姓名:";
string name;
cin >> name;
account->setName(name);
cout << "请输入密码:";
cin >> name;
account->setPW(name);
cout << "修改完毕:";
cout << account->print() << endl;
cout << endl << "继续吗?(Y / N):";
cin >> acc;
if (acc == 'y' || acc == 'Y') {
system("cls");
change_account();
}
};
void show_rooms() {
cout << "可用机房如下:" << endl;
int n = 1;
for (vector<Room*>::const_iterator i = Room::rooms->begin(); i != Room::rooms->end(); i++) {
Room* temp = *i;
cout << n++ << " " << temp->getName() << "\t座位数:" << temp->getSeat() << endl;
}
};
void clear_history() {
cout << "★★★=========·清空预定记录·=========★★★" << endl;
cout << "现有记录会被全部清空!确定吗?(Y / N):";
char confirm = 'N';
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
for (vector<Room*>::const_iterator ri = Room::rooms->begin(); ri != Room::rooms->end(); ri++) {
Room* room = *ri;
for (vector<List*>::const_iterator i = room->tbd.begin(); i != room->tbd.end(); i++) {
List* temp = *i;
delete temp;
}
room->tbd.clear();
for (vector<List*>::const_iterator i = room->confirmed.begin(); i != room->confirmed.end(); i++) {
List* temp = *i;
delete temp;
}
room->confirmed.clear();
room->tbd.swap(room->confirmed);
}
}
cout << endl << "清空完成" << endl;
};
<C++>13 项目:机房预约系统
https://i-melody.github.io/2022/05/24/C++/入门阶段/13 项目:机房预约系统/