提示:本文不是老师上课的讲义,是自己做该项目的记录
1 机房预约系统需求
1.1 系统简介
学校有几个规格不同的机房, 由于使用时经常出现“撞车”现象,现开发一套机房预约系统,解决这一问题
1.2 身份简介
分别有三种身份使用该程序
- 学生代表: 申请使用机房
- 教师: 审核学生的预约申请
- 管理员: 给学生、教师创建账号
1.3 机房简介
机房总共有三件
- 1号机房 — 最大容量20人
- 2号机房 — 最大容量50人
- 3号机房 — 最大容量100人
1.4 申请简介
- 申请的订单每周由管理员负责清空
- 学生可以预约未来一周内的机房使用,预约的日期为周一至周五,预约时需要选择预约时段(上午、下午)
- 教师来审核预约,依赖实际情况审核预约通过或者不通过
1.5 系统具体需求
- 首先进入登录界面,可选登录身份有:
- 每个身份都需要进行验证后,进入子菜单
- 学生需要输入:学号、姓名、登录密码
- 老师需要输入:职工号、姓名、登陆密码
- 管理员需要输入:管理员姓名、登录密码
- 学生具体功能
- 申请预约 — 预约机房
- 查看自身的预约 — 查看自己的预约状态
- 查看所有预约 — 查看全部预约信息以及预约状态
- 取消预约 — 取消自身的预约,预约成功或审核中的预约均可以取消
- 注销登录 — 退出登录
- 教师具体功能
- 查看所有预约 — 查看全部预约信息以及预约状态
- 审核预约 — 对学生的预约进行审核
- 注销登录 — 退出登录
- 管理员具体功能
- 添加账号 — 添加学生或教师的账号,需要检测学生编号或教师职工号是否重复
- 查看账号 — 可以选择查看学生或教师的全部信息
- 查看机房 — 查看所有机房的信息
2 分析
分析上文的需求,我们至少需要创建一个身份父类,由学生、教师、管理员三个子类继承。 需要一个预约系统.cpp,来实现各个菜单 机房信息需要一个容器来存储
参照老师上次教的职工管理系统,先把菜单和退出功能弄出来,再弄身份类,再加功能
目前还是个未成品,有时间再接着做吧
3 代码
3.1 机房预约系统.cpp
#include <iostream>
using namespace std;
#include "menu.h"
#include <string>
#include "person.h"
#include "student.h"
#include <vector>
#include "computerRoom.h"
#include "teacher.h"
#include <map>
#include "manager.h"
void creatCr(vector< ComputerRoom>& v) {
ComputerRoom cr = ComputerRoom("1号机房", 20,20);
v.push_back(cr);
cr = ComputerRoom("2号机房", 50,50);
v.push_back(cr);
cr = ComputerRoom("3号机房", 100,100);
v.push_back(cr);
}
void doCheck(vector< ComputerRoom> v) {
for (vector< ComputerRoom>::iterator it = v.begin(); it != v.end(); it++) {
(*it).check();
}
}
void showUnverify(multimap<int, Student> map) {
cout << "待审核的预约如下:" << endl;
for (multimap<int, Student>::iterator it = map.begin(); it != map.end(); it++) {
cout << "学号为" << it->first << "的学生预约了" << (it->second).bookname << endl;
}
}
int main() {
vector< ComputerRoom> v;
creatCr(v);
multimap<int, Student> map;
Menu m;
int choice = 0;
m.mainMenu();
while (true) {
cout << "请输入您的选择:" << endl;
cin >> choice;
string name;
int id;
string password;
switch (choice) {
case 1:
cout << "请输入学号:" << endl;
cin >> id;
if (true) {
cout << "请输入密码:" << endl;
cin >> password;
if (true) {
Student s = Student(id);
system("cls");
m.sMenu();
int schoice;
while (true) {
cout << "请输入您的选择:" << endl;
cin >> schoice;
switch (schoice) {
case 1:
s.book(v,map);
break;
case 2:
s.checkBook();
break;
case 3:
doCheck(v);
break;
case 4:
s.cancelBook(v,map);
break;
case 5:
m.exitSystem();
break;
default:
system("cls");
break;
}
}
}
else {
cout << "您输入的密码有误,请重新输入" << endl;
}
}
else{
cout << "您输入的学号有误,请重新输入" << endl;
}
break;
case 2:
cout << "请输入职工号:" << endl;
cin >> id;
if (true) {
cout << "请输入密码:" << endl;
cin >> password;
if (true) {
Teacher t = Teacher(id);
system("cls");
m.tMenu();
int tchoice;
while (true)
{
cout << "请输入您的选择:" << endl;
cin >> tchoice;
switch (tchoice) {
case 1:
showUnverify(map);
break;
case 2:
t.verify(v,map);
break;
case 3:
m.exitSystem();
break;
default:
system("cls");
break;
}
}
}
else {
cout << "您输入的密码有误,请重新输入" << endl;
}
}
else {
cout << "您输入的职工号有误,请重新输入" << endl;
}
break;
case 3:
cout << "请输入管理工号:" << endl;
cin >> id;
if (true) {
cout << "请输入密码:" << endl;
cin >> password;
if (true) {
Manager mg= Manager(id);
system("cls");
m.mMenu();
int mchoice;
while (true)
{
cout << "请输入您的选择:" << endl;
cin >> mchoice;
switch (mchoice) {
case 1:
break;
case 2:
break;
case 3:
doCheck(v);
break;
case 4:
m.exitSystem();
break;
default:
system("cls");
break;
}
}
}
else {
cout << "您输入的密码有误,请重新输入" << endl;
}
}
else {
cout << "您输入的管理工号有误,请重新输入" << endl;
}
break;
case 4:
m.exitSystem();
break;
default:
system("cls");
break;
}
}
return 0;
}
3.2 身份类
3.2.1 person.h
#pragma once
#include <iostream>
using namespace std;
#include <string>
class Person {
public:
int m_id;
string m_name;
string m_password;
};
3.2.2 person.cpp
#include "person.h"
3.3 学生类
3.3.1 student.h
#pragma once
#include <iostream>
using namespace std;
#include "person.h"
#include <string>
#include <vector>
#include"computerRoom.h"
#include <map>
class Student :public Person {
public:
int m_id;
string m_name;
string m_password;
bool isbook=false;
bool isok=false;
string bookname;
Student(int id);
void book(vector< ComputerRoom>& v, multimap<int, Student> &map);
void checkBook();
void cancelBook(vector< ComputerRoom>& v, multimap<int, Student>& map);
~Student();
};
3.3.2 student.cpp
#include "student.h"
Student::Student(int id) {
m_id = id;
}
void Student::book(vector< ComputerRoom>& v, multimap<int, Student>& map) {
string name;
cout << "请输入要预约的机房名称:(1号机房、2号机房、3号机房)" << endl;
cin >> name;
vector< ComputerRoom>::iterator it = v.begin();
for (; it != v.end(); it++) {
if (it->m_name == name)
break;
}
it->book();
map.insert(make_pair(m_id, *this));
isbook = true;
bookname = name;
}
void Student::checkBook() {
if (!isbook) {
cout << "您没有预约机房" << endl;
}
else {
cout << "您预约的机房名称为" << bookname << endl;
if (isok) {
cout << "您的预约已通过" << endl;
}
else {
cout << "您的预约正在审核中" << endl;
}
}
}
void Student::cancelBook(vector< ComputerRoom>& v, multimap<int, Student>& map) {
if (!isbook) {
cout << "您没有预约机房" << endl;
}
else {
isbook = false;
vector< ComputerRoom>::iterator it = v.begin();
for (; it != v.end(); it++) {
if (it->m_name == bookname)
break;
}
it->cancel();
cout << "您的预约已取消" << endl;
multimap<int, Student>::iterator pos = map.find(m_id);
map.erase(pos);
}
}
Student::~Student() {
}
3.4 老师类
3.4.1 teacher.h
#pragma once
#include <iostream>
using namespace std;
#include<map>
#include "student.h"
class Teacher {
public:
int id;
Teacher(int id);
void verify(vector< ComputerRoom>& v,multimap<int, Student>& map);
};
3.4.2 teacher.cpp
#include "teacher.h"
Teacher::Teacher(int id) {
this->id = id;
}
void Teacher::verify(vector< ComputerRoom>& v,multimap<int, Student>& map) {
int id;
int choice;
cout << "请输入要审核的预约信息的学号:" << endl;
cin >> id;
cout << "是否同意该预约?同意输入1,不同意输入0" << endl;
cin >> choice;
multimap<int, Student>::iterator pos = map.find(id);
(pos->second).isok = choice;
if (!choice) {
vector< ComputerRoom>::iterator it = v.begin();
for (; it != v.end(); it++) {
if (it->m_name == (pos->second).bookname)
break;
}
it->cancel();
}
map.erase(pos);
}
3.5 管理员类
3.5.1 manager.h
#pragma once
#include <iostream>
using namespace std;
class Manager {
public:
int id;
Manager(int id);
};
3.5.2 manager.cpp
#include "manager.h"
Manager::Manager(int id) {
this->id = id;
}
3.6 菜单类
3.6.1 menu.h
#pragma once
#include <iostream>
using namespace std;
class Menu {
public:
void mainMenu();
void sMenu();
void tMenu();
void mMenu();
void exitSystem();
};
3.6.2 menu.cpp
#include <iostream>
using namespace std;
#include "menu.h"
void Menu::mainMenu() {
cout << "*******************************************" << endl;
cout << "********** 欢迎使用机房预约系统!**********" << endl;
cout << "************* 请选择登陆身份 **************" << endl;
cout << "************* 1、学生 *********************" << endl;
cout << "************* 2、教师 *********************" << endl;
cout << "************* 3、管理员 *******************" << endl;
cout << "************* 4、退出 *********************" << endl;
cout << "*******************************************" << endl;
cout << endl;
}
void Menu::sMenu() {
cout << "*******************************************" << endl;
cout << "********** 欢迎使用机房预约系统!**********" << endl;
cout << "**************** 请选择操作 ***************" << endl;
cout << "************* 1、申请预约 *****************" << endl;
cout << "************* 2、查看自身的预约 ***********" << endl;
cout << "************* 3、查看所有预约 *************" << endl;
cout << "************* 4、取消预约 *****************" << endl;
cout << "************* 5、退出登陆 *****************" << endl;
cout << "*******************************************" << endl;
cout << endl;
}
void Menu::tMenu() {
cout << "*******************************************" << endl;
cout << "********** 欢迎使用机房预约系统!**********" << endl;
cout << "**************** 请选择操作 ***************" << endl;
cout << "************* 1、查看所有预约 *************" << endl;
cout << "************* 2、审核预约 *****************" << endl;
cout << "************* 3、退出登陆 *****************" << endl;
cout << "*******************************************" << endl;
cout << endl;
}
void Menu::mMenu() {
cout << "*******************************************" << endl;
cout << "********** 欢迎使用机房预约系统!**********" << endl;
cout << "**************** 请选择操作 ***************" << endl;
cout << "************* 1、添加账号 *****************" << endl;
cout << "************* 2、查看账号 *****************" << endl;
cout << "************* 3、查看机房 *****************" << endl;
cout << "************* 4、退出登陆 *****************" << endl;
cout << "*******************************************" << endl;
cout << endl;
}
void Menu::exitSystem() {
cout << "欢迎下次使用!" << endl;
exit(0);
}
3.7 机房类
3.7.1 computerRoom.h
#pragma once
#include <iostream>
using namespace std;
#include<string>
class ComputerRoom {
public:
string m_name;
int m_amount;
int m_unwanted;
int m_wanted=0;
ComputerRoom(string name,int amount,int unwanted);
void check();
void book();
void cancel();
};
3.7.2 computerRoom.cpp
#include "computerRoom.h"
ComputerRoom::ComputerRoom(string name, int amount,int unwanted) {
m_name = name;
m_amount = amount;
m_unwanted = unwanted;
}
void ComputerRoom::check() {
cout << m_name << "最大容量为:" << m_amount << ",其中已预约:" << m_wanted << ",未预约:" << m_unwanted << endl;
}
void ComputerRoom::book() {
if (m_unwanted > 0) {
m_unwanted--;
m_wanted++;
cout << "预约已提交!" << endl;
}
else {
cout << "该机房已满!" << endl;
}
}
void ComputerRoom::cancel() {
if (m_wanted) {
m_wanted--;
m_unwanted++;
}
else {
cout << "取消失败" << endl;
}
}
|