1、机房预约系统需求
1.1 系统简介
- 学校现有几个规格不同的机房,由于使用时经常出现”撞车”现象,现开发一套机房预约系统,解决这一问题。
1.2 身份简介
分别有三种身份使用该程序
-
学生代表
:申请使用机房 -
教师
:审核学生的预约申请 -
管理员
:给学生、教师创建账号
1.3 机房简介
机房总共有3间
- 1号机房 — 最大容量20人
- 2号机房 — 最多容量50人
- 3号机房 — 最多容量100人
1.4 申请简介
- 申请的订单每周由管理员负责清空。
- 学生可以预约未来一周内的机房使用,预约的日期为周一至周五,预约时需要选择预约时段(上午、下午)
- 教师来审核预约,依据实际情况审核预约通过或者不通过
1.5 系统具体需求
-
首先进入登录界面,可选登录身份有:
- 学生代表
- 老师
- 管理员
- 退出
-
每个身份都需要进行验证后,进入子菜单
- 学生需要输入 :学号、姓名、登录密码
- 老师需要输入:职工号、姓名、登录密码
- 管理员需要输入:管理员姓名、登录密码
-
学生具体功能
- 申请预约 — 预约机房
- 查看自身的预约 — 查看自己的预约状态
- 查看所有预约 — 查看全部预约信息以及预约状态
- 取消预约 — 取消自身的预约,预约成功或审核中的预约均可取消
- 注销登录 — 退出登录
-
教师具体功能
- 查看所有预约 — 查看全部预约信息以及预约状态
- 审核预约 — 对学生的预约进行审核
- 注销登录 — 退出登录
-
管理员具体功能
- 添加账号 — 添加学生或教师的账号,需要检测学生编号或教师职工号是否重复
- 查看账号 — 可以选择查看学生或教师的全部信息
- 查看机房 — 查看所有机房的信息
- 清空预约 — 清空所有预约记录
- 注销登录 — 退出登录
代码展示
1.创建身份基类
因为学生和老师都有姓名和密码,所以创建身份基类
personmanager.h
#pragma once
#include<iostream>
#include<string>
using namespace std;
//创建身份基类
class personmanager
{
public:
//输入个人信息
string p_name;//姓名
string p_code;//密码
};
2、管理员部分
manager.h
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"personmanager.h"
#include<fstream>
#include<map>
class manager:public personmanager
{
public:
manager();
manager(string name,string code);
//存放所有学号和职工号,方便查找是否有重复的
void save_id(int type,int id);
//将文件中的id号存到multiset容器中
void save_set(int type);
//添加账号
void add_account();
//查看账号
void look_account();
//查看机房
void look_comroom();
//清空预约
void delete_appoint();
//virtual void emp_appoint();
注销登录
//virtual void logout();
~manager();
};
manager.cpp
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"manager.h"
#include<fstream>
#include<set>
#include"student.h"
#include"teacher.h"
#include"globalfile.h"
#include"write_infostu.h"
//用multiset不会出现重复的,并且会自动排序
multiset<int> m1;//存放学生学号
multiset<int> m2;//存放老师职工号
manager::manager() {};
manager::manager(string name, string code)
{
this->p_name = name;
this->p_code = code;
}
void manager::save_id(int type,int id)
{
ofstream ofs;
if (type == 1)//存放学生学号
{
ofs.open("stu_id.txt", ios::out | ios::app);
ofs << id << endl;
}
if (type == 2)
{
ofs.open("teacher_id.txt", ios::out | ios::app);
ofs << id << endl;
}
}
void manager::save_set(int type)
{
ifstream ifs;
int id;
if (type == 1)//存放学生学号
{
ifs.open("stu_id.txt", ios::in);
while (ifs >> id)
{
m1.insert(id);
}
}
if (type == 2)//存放老师职工号
{
ifs.open("teacher_id.txt", ios::in);
while (ifs >> id)
{
m2.insert(id);
}
}
ifs.close();
}
void manager::add_account()
{
cout << "请选择要添加的职工身份:" << endl;
cout << "1、学生" << endl;
cout << "2、老师" << endl;
int k;
cin >> k;
if (k == 1)
{
cout << "请输入学生学号:" << endl;
int id;
cin >> id;
save_set(1);
multiset<int>::iterator pos = m1.find(id);
while(pos != m1.end())
{
cout << "该学号已存在, 请重新输入:" << endl;
cin >> id;
pos = m1.find(id);
}
save_id(1, id);
cout << "请输入学生姓名:" << endl;
string name;
cin >> name;
cout << "请输入学生登录密码:" << endl;
string code;
cin >> code;
student s1(id,name,code);
write_info(s1);
m1.clear();
}
if (k == 2)
{
cout << "请输入老师职工号:" << endl;
int id;
cin >> id;
save_set(2);
multiset<int>::iterator pos = m2.find(id);
while (pos != m2.end())
{
cout << "该职工号已存在,请重新输入:" << endl;
cin >> id;
pos = m2.find(id);
}
save_id(2, id);
cout << "请输入老师姓名:" << endl;
string name;
cin >> name;
cout << "请输入老师登录密码:" << endl;
string code ;
cin >> code;
teacher t1(id,name, code);
ofstream ofs;
ofs.open(TEACHER_FILE, ios::out | ios::app);
ofs << t1.t_id<< " " << t1.p_name<< " " << t1.p_code << endl;
ofs.close();
m2.clear();
}
system("pause");
system("cls");
}
void manager::look_account()
{
cout << "请选择要查看的职工身份:" << endl;
cout << "1、学生" << endl;
cout << "2、老师" << endl;
int k;
cin >> k;
if (k == 1)
{
ifstream ifs;
ifs.open(STUDENT_FILE, ios::in);
char buf[4048] = { 0 };
if (!ifs.is_open())
{
cout << "文件不存在或者没有学生信息!" << endl;
}
else
{
while (ifs.getline(buf, sizeof(buf)))
{
cout << buf << endl;
}
}
ifs.close();
}
if (k == 2)
{
ifstream ifs;
ifs.open(TEACHER_FILE, ios::in);
char buf[4048] = { 0 };
if (!ifs.is_open())
{
cout << "文件不存在或者没有老师信息!" << endl;
}
else
{
while (ifs.getline(buf, sizeof(buf)))
{
cout << buf << endl;
}
}
ifs.close();
}
system("pause");
system("cls");
}
void manager::look_comroom()
{
ifstream ifs;
ifs.open(COMPUTER_FILE,ios::in);
char buf[1024] = { 0 };
while (ifs.getline(buf, sizeof(buf)))
{
cout << buf << endl;
}
system("pause");
system("cls");
}
void manager::delete_appoint()
{
cout << "请确认是否清空?" << endl;
cout << "1、是" << endl;
cout << "2、否" << endl;
int k;
cin >> k;
if (k == 1)
{
fstream fs;
fs.open(ORDER_FILE,ios::out| ios::trunc);
fs.close();
fs.open("student_order.txt",ios::out|ios::trunc);
fs.close();
}
system("pause");
system("cls");
}
manager::~manager() {};
2、学生代表
student.h
#pragma once
#include<string>
#include<iostream>
#include"personmanager.h"
#include<vector>
#include"globalfile.h"
class student :public personmanager
{
public:
student();
student(int id, string name, string code);
//*申请预约-- - 预约机房
void apply_appoint();
//* 查看自身的预约-- - 查看自己的预约状态
void look_appoint();
//* 查看所有预约-- - 查看全部预约信息以及预约状态
void lookall_appoint();
//* 取消预约-- - 取消自身的预约,预约成功或审核中的预约均可取消
void cancel_appoint();
//virtual void getinfor() ;//纯虚函数
int s_id=0;
};
student.cpp
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"student.h"
#include"read_file.h"
#include<fstream>
#include"order_num.h"
#include<cstring>
#include"student_order.h"
#include<map>
#include"updatestu_date.h"
#include"updata_show.h"
map<int, student_order> m;//保存新增的预约信息
map<int, student_order> m1;//存入”student_order.text"文件中的信息
student::student() {};
student::student(int id,string name, string code)
{
this->s_id = id;
this->p_name = name;
this->p_code = code;
}
void student::apply_appoint()
{
int num=order_num();//记录文件中的预约序号
//机房选择 时间段选择
cout << "请选择要预约的机房:" << endl;
cout << "1、机房一" << endl;
cout << "2、机房二" << endl;
cout << "3、机房三" << endl;
int k;
cin >> k;
cout << "请选择预约时间:" << endl;
cout << "1、周一" << endl;
cout << "2、周二" << endl;
cout << "3、周三" << endl;
cout << "4、周四" << endl;
cout << "5、周五" << endl;
int k2;
cin >> k2;
cout << "请选择时间段:" << endl;
cout << "1、上午" << endl;
cout << "2、下午" << endl;
int k3;
cin >> k3;
int state = 0;//审核中
student_order stuor(this->s_id, this->p_name, this->p_code, k, k2, k3,state);
m.insert(pair<int, student_order>(num, stuor));
updatestu_date(m,2);
update_show(m,2);
//清空
m.erase(m.begin(), m.end());
m.clear();
}
void student::look_appoint( )
{
ifstream ifs;
student_order s1;
int num;
string name;//姓名
string code;//密码
int id;//学号
int k = 0;//机房信息
int k1 = 0;//周几信息
int k2 = 0;//上下午信息
//预约状态:0——审核中,1——预约成功,2——预约失败,3——预约已取消
int state = 0;
ifs.open("student_order.txt", ios::in);
//将文件中的信息存入m1容器中
while (ifs >> num && ifs >> id && ifs >> name && ifs >> code && ifs >> k && ifs >> k1 && ifs >> k2 && ifs>>state)
{
s1.s_id = id;
s1.p_name = name;
s1.p_code = code;
s1.s_k = k;
s1.s_k1 = k1;
s1.s_k2 = k2;
s1.s_state = state;
m1.insert(pair<int, student_order>(num, s1));
}
string str;
string str1;
//根据学号查找容器中的信息
for (map<int, student_order>::iterator it = m1.begin(); it != m1.end(); it++)
{
if (it->second.s_id == this->s_id)
{
if (it->second.s_k2 == 1)
{
str = "上午";
}
if (it->second.s_k2 == 2)
{
str = "下午";
}
if (it->second.s_state == 0)
{
str1 = "审核中";
}
if (it->second.s_state == 1)
{
str1 = "预约成功";
}
if (it->second.s_state == 2)
{
str1 = "预约失败";
}
if (it->second.s_state == 3)
{
str1 = "预约已取消";
}
cout << it->first << "、 学号:"
<< it->second.s_id << " 姓名:"
<< it->second.p_name << " 密码:"
<< it->second.p_code << " 预约机房"
<< it->second.s_k << " 周"
<< it->second.s_k1 << " "
<< str << " 预约状态:"
<< str1 << endl;
}
}
ifs.close();
//清空
m1.erase(m1.begin(), m1.end());
m1.clear();
system("pause");
system("cls");
}
void student::lookall_appoint()
{
ifstream ifs;
ifs.open(ORDER_FILE, ios::in);
char buf[4048] = { 0 };
while (ifs.getline(buf, sizeof(buf)))
{
cout << buf << endl;
}
system("pause");
system("cls");
}
void student::cancel_appoint()
{
cout << "请确定是否取消预约?" << endl;
cout << "1、是" << endl;
cout << "2、否" << endl;
int k;
cin >> k;
if (k == 1)
{
look_appoint();
cout << "请选择要取消的预约:(请输入数字)" << endl;
int choice;
cin >> choice;
student_order s1;
int num;
string name;//姓名
string code;//密码
int id;//学号
int k = 0;//机房信息
int k1 = 0;//周几信息
int k2 = 0;//上下午信息
//预约状态:0——审核中,1——预约成功,2——预约失败,3——预约已取消
int state = 0;
ifstream ifs;
ifs.open("student_order.txt", ios::in);
//将文件中的信息存入m1容器中
while (ifs >> num && ifs >> id && ifs >> name && ifs >> code && ifs >> k && ifs >> k1 && ifs >> k2&&ifs>>state)
{
s1.s_id = id;
s1.p_name = name;
s1.p_code = code;
s1.s_k = k;
s1.s_k1 = k1;
s1.s_k2 = k2;
s1.s_state = state;
m1.insert(pair<int, student_order>(num, s1));
}
map<int, student_order>::iterator pos=m1.find(choice);
pos->second.s_state = 3;
updatestu_date(m1,1);
update_show(m1,1);
cout << "取消预约成功!" << endl;
ifs.close();
//清空
m1.erase(m1.begin(), m1.end());
m1.clear();
}
system("pause");
system("cls");
}
4、老师
teacher.h
#pragma once
#include<string>
#include<iostream>
#include"personmanager.h"
class teacher :public personmanager
{
public:
teacher();
teacher(int id,string name, string code);
//*查看所有预约-- - 查看全部预约信息以及预约状态
void look_allappoint();
//* 审核预约-- - 对学生的预约进行审核
void audit_appoint();
//* 注销登录-- - 退出登录
int t_id;
};
teacher.cpp
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"teacher.h"
#include<fstream>
#include"globalfile.h"
#include "student_order.h"
#include<map>
#include"updatestu_date.h"
#include"updata_show.h"
teacher::teacher() {};
teacher::teacher(int id,string name, string code)
{
this->t_id = id;
this->p_name = name;
this->p_code = code;
}
void teacher::look_allappoint()
{
ifstream ifs;
ifs.open(ORDER_FILE, ios::in);
char buf[4048] = { 0 };
while (ifs.getline(buf, sizeof(buf)))
{
cout << buf << endl;
}
system("pause");
system("cls");
}
void teacher::audit_appoint()
{
cout << "所有的预约信息如下:" << endl;
look_allappoint();
cout << "请选择要审核的序号:" << endl;
int k3;
cin >> k3;
student_order s1;
map<int, student_order> m1;//存入”student_order.text"文件中的信息
int num;
string name;//姓名
string code;//密码
int id;//学号
int k = 0;//机房信息
int k1 = 0;//周几信息
int k2 = 0;//上下午信息
//预约状态:0——审核中,1——预约成功,2——预约失败,3——预约已取消
int state = 0;
ifstream ifs;
ifs.open("student_order.txt", ios::in);
//将文件中的信息存入m1容器中
while (ifs >> num && ifs >> id && ifs >> name && ifs >> code && ifs >> k && ifs >> k1 && ifs >> k2 && ifs >> state)
{
s1.s_id = id;
s1.p_name = name;
s1.p_code = code;
s1.s_k = k;
s1.s_k1 = k1;
s1.s_k2 = k2;
s1.s_state = state;
m1.insert(pair<int, student_order>(num, s1));
}
map<int, student_order>::iterator pos = m1.find(k3);
cout << "请选择是否审核通过:" << endl;
cout << "1、是" << endl;
cout << "2、否" << endl;
int key;
cin >> key;
if (key == 1)
{
pos->second.s_state = 1;
}
if (key == 2)
{
pos->second.s_state = 2;
}
updatestu_date(m1, 1);
update_show(m1, 1);
cout << "修改成功!" << endl;
ifs.close();
m1.clear();
system("pause");
system("cls");
}
5、全局文件
globalfile.h
#pragma once
//管理员文件
#define ADMIN_FILE "manager.txt"
//学生文件
#define STUDENT_FILE "student.txt"
//教师文件
#define TEACHER_FILE "teacher.txt"
//机房信息文件
#define COMPUTER_FILE "computerRoom.txt"
//订单文件
#define ORDER_FILE "order.txt"
6、计算订单文件有多少订单
order_num.h
#pragma once
#include<string>
#include<iostream>
#include"globalfile.h"
#include<fstream>
int order_num();
order_num.cpp
#include"order_num.h"
#include<fstream>
#include<string>
using namespace std;
int order_num()
{
ifstream ifs;
ifs.open(ORDER_FILE, ios::in);
char buf[1024] = { 0 };
int num = 0;
while (ifs.getline(buf, sizeof(buf)))
{
num++;
}
return num;
}
7、读取文件中的老师/学生信息
read_file.h
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"globalfile.h"
#include<fstream>
void read_file(string FILENAME, int type);
read_file.cpp
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"read_file.h"
#include<fstream>
//type为1读取学生文件,2读取老师文件
void read_file(string FILENAME, int type)
{
ifstream ifs;
int id;
string name;
string code;
string state;//预约状态
if (type == 1)//学生文件
{
FILENAME =STUDENT_FILE;
ifs.open(FILENAME, ios::in);
if (!ifs.is_open())
{
cout << "文件不存在或文件读取失败" << endl;
}
else {
cout << "学生信息读取成功" << endl;
while (ifs >> id && ifs >> name && ifs >> code && ifs >> state)
{
cout << id << " " << name << " " << code << " " << state << endl;
}
}
}
if (type == 2)//老师文件
{
FILENAME = TEACHER_FILE;
ifs.open(FILENAME, ios::in);
if (!ifs.is_open())
{
cout << "文件不存在或文件读取失败" << endl;
}
else {
cout << "老师信息读取成功" << endl;
while (ifs >> id && ifs >> name && ifs >> code)
{
cout << id << " " << name << " " << code << endl;
}
}
}
}
8、创建学生订单管理类
student_order.h
#pragma once
#include<string>
#include<iostream>
#include"personmanager.h"
#include<vector>
#include"globalfile.h"
class student_order :public personmanager
{
public:
student_order();
student_order(int id, string name, string code, int k, int k1, int k2,int state);
int s_id;//学号
int s_k=0;//机房信息
int s_k1 = 0;//周几信息
int s_k2 = 0;//上下午信息
//预约状态:0——审核中,1——预约成功,2——预约失败,3——预约已取消
int s_state = 0;
};
student_order.cpp
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"student_order.h"
#include<fstream>
#include<map>
student_order::student_order() {};
student_order::student_order(int id, string name, string code, int k, int k1, int k2,int state)
{
this->s_id = id;
this->p_name = name;
this->p_code = code;
this->s_k = k;
this->s_k1 = k1;
this->s_k2 = k2;
this->s_state = state;
}
9、创建学生信息写入函数并封装
write_infostu.h
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"globalfile.h"
#include"student.h"
void write_info(student &s);
write_infostu.cpp
#include"write_infostu.h"
#pragma once
#include<string>
#include<iostream>
#include<fstream>
using namespace std;
#include"student.h"
void write_info(student &s)
{
ofstream ofs;
ofs.open(STUDENT_FILE, ios::out|ios::app);
ofs << s.s_id << " " << s.p_name << " " << s.p_code << endl;
ofs.close();
}
10、创建学生信息以及订单信息记录函数并封装
这个主要是将数字信息写入文件中,方便后续处理
updatestu_date.h
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include<map>
#include"student_order.h"
//在student_order.text更新学生预定机房的信息
void updatestu_date(map<int,student_order> &m,int type);
updatestu_date.cpp
这一部分分两种情况,当学生订单信息改变时,使用第一种代码,将容器中存放的所有数据全部写入文件中(从头开始写),刚开始我尝试过从文件的某一指定位置更改文件中存放的信息,但是失败了,有兴趣的可以自己百度试下,文件操作有提供seekp函数之类的;当新增订单时,使用第二种代码,从文件的末尾开始写入容器中的信息。
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include"updatestu_date.h"
#include<fstream>
void updatestu_date(map<int, student_order>& m,int type)
{
//将容器中的所有数据都写入文件中
if (type == 1)
{
ofstream ofs;
ofs.open("student_order.txt", ios::out );
for (map<int, student_order>::iterator it = m.begin(); it != m.end(); it++)
{
ofs << it->first << " "
<< it->second.s_id << " "
<< it->second.p_name << " "
<< it->second.p_code << " "
<< it->second.s_k << " "
<< it->second.s_k1 << " "
<< it->second.s_k2 << " "
<<it->second.s_state<< endl;
}
ofs.close();
}
//只写入新增的预约
if (type == 2)
{
ofstream ofs;
ofs.open("student_order.txt", ios::out|ios::app);
map<int, student_order>::iterator it = m.begin();
ofs << it->first << " "
<< it->second.s_id << " "
<< it->second.p_name << " "
<< it->second.p_code << " "
<< it->second.s_k << " "
<< it->second.s_k1 << " "
<< it->second.s_k2 << " "
<< it->second.s_state << endl;
ofs.close();
}
}
11、将学生的个人信息和订单信息写入文件中
这个主要是写入文字性的信息,方便人们查看,第十个函数是方便计算机操作
updata_show.h
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include<fstream>
#include<map>
#include"student_order.h"
void update_show(map<int, student_order>& m,int type);
updata_show.cpp
#pragma once
#include<string>
#include<iostream>
using namespace std;
#include<fstream>
#include<map>
#include"updata_show.h"
#include"globalfile.h"
void update_show(map<int, student_order>& m,int type)
{
ofstream ofs;
if (type == 1)
{
ofs.open(ORDER_FILE, ios::out);//覆盖性全部写入
}
if (type == 2)
{
ofs.open(ORDER_FILE, ios::out |ios::app);//从文件尾部开始写
}
string str;
string str1;
for (map<int, student_order>::iterator it = m.begin(); it != m.end(); it++)
{
if (it->second.s_k2 == 1)
{
str = "上午";
}
if (it->second.s_k2 == 2)
{
str = "下午";
}
if(it->second.s_state==0)
{
str1 = "审核中";
}
if (it->second.s_state == 1)
{
str1 = "预约成功";
}
if (it->second.s_state == 2)
{
str1 = "预约失败";
}
if (it->second.s_state == 3)
{
str1 = "预约已取消";
}
ofs << it->first << "、 学号:"
<< it->second.s_id << " 姓名:"
<< it->second.p_name << " 密码:"
<< it->second.p_code << " 预约机房"
<< it->second.s_k << " 周"
<< it->second.s_k1 << " "
<< str << " 预约状态:"
<< str1 << endl;
}
ofs.close();
}
12、机房预约系统
提供各种接口整理成机房预约系统,完成!
机房预约系统.cpp
#include<string>
#pragma once
#include<iostream>
#include"personmanager.h"
#include"student.h"
using namespace std;
#include<fstream>
#include<algorithm>
#include<vector>
#include"manager.h"
#include"teacher.h"
#include"globalfile.h"
#include"read_file.h"
manager man;
//创建三个机房的容器
//最大容量20人
vector<student> v1;
//2号机房-- - 最多容量50人
vector<student>v2;
//3号机房 --- 最多容量100人
vector<student>v3;
//创建主菜单
void mainmenu()
{
cout << "请选择你的登录身份:" << endl;
cout << "1、学生代表" << endl;
cout << "2、老师" << endl;
cout << "3、管理员" << endl;
cout << "4、退出" << endl;
}
//创建学生系统
void sys_student(student &stu)
{
while (1)
{
cout << "请选择要使用的功能" << endl;
cout << "1、申请预约" << endl;
cout << "2、查看自身的预约" << endl;
cout << "3、查看所有预约" << endl;
cout << "4、取消预约" << endl;
cout << "5、注销登录" << endl;
int k;
cin>>k;
switch (k)
{
case 1:stu.apply_appoint();
break;
case 2:stu.look_appoint();
break;
case 3:stu.lookall_appoint();
break;
case 4:stu.cancel_appoint();
break;
case 5:
cout<<"欢迎下次使用!" << endl;
system("pause");
return ;
break;
default:
break;
}
}
}
//创建老师系统
void sys_teacher(teacher& t)
{
while (1)
{
cout << "请选择要使用的功能" << endl;
cout << "1、查看所有预约" << endl;
cout << "2、审核预约" << endl;
cout << "3、注销登录" << endl;
int k;
cin >> k;
switch (k)
{
case 1:t.look_allappoint();
break;
case 2:t.audit_appoint();
break;
case 3:
cout << "欢迎下次使用!" << endl;
system("pause");
return;
break;
default:
break;
}
}
}
//创建管理员系统
void sys_manager(manager &man)
{
while (1)
{
cout << "请选择要使用的功能" << endl;
cout << "1、添加账号" << endl;
cout << "2、查看账号" << endl;
cout << "3、查看机房" << endl;
cout << "4、清空预约" << endl;
cout << "5、注销登录" << endl;
int k;
cin >> k;
switch (k)
{
case 1:man.add_account();
break;
case 2:man.look_account();
break;
case 3:man.look_comroom();
break;
case 4:man.delete_appoint();
break;
case 5:
cout << "欢迎下次使用!" << endl;
return;
break;
default:
break;
}
}
}
//创建子菜单
void partmenu(int k,student &stu,teacher &t,manager &man)
{
string name;
string code;
int id;
ifstream ifs;
if (k == 1)
{
cout << "请输入学号:" << endl;
cin >>stu.s_id;
cout << "请输入姓名:" << endl;
cin >> stu.p_name;
cout << "请输入登录密码:" << endl;
cin >> stu.p_code;
string state;
//登录验证
ifs.open(STUDENT_FILE, ios::in);
if (!ifs.is_open())
{
cout << "文件不存在!" << endl;
}
else
{
while (ifs >> id && ifs >> name && ifs >> code)
{
if (stu.s_id == id&&stu.p_name == name &&stu.p_code==code)
{
cout << "验证成功!" << endl;
sys_student(stu);
}
}
}
ifs.close();
}
if (k == 2)
{
cout << "请输入职工号:" << endl;
cin >> t.t_id;
cout << "请输入姓名:" << endl;
cin >>t.p_name;
cout << "请输入登录密码:" << endl;
cin >> t.p_code;
//登录验证
ifs.open(TEACHER_FILE, ios::in);
if (!ifs.is_open())
{
cout << "文件不存在!" << endl;
}
else
{
while (ifs >> id && ifs >> name && ifs >> code)
{
if (t.t_id == id && t.p_name == name && t.p_code == code)
{
cout << "验证成功!" << endl;
sys_teacher(t);
}
}
}
ifs.close();
}
if (k == 3)
{
cout << "请输入管理员姓名:" << endl;
cin >> name;
cout << "请输入登录密码:" << endl;
cin >> code;
if (name == man.p_name && code == man.p_code)
{
sys_manager(man);
}
else {
cout << "姓名或密码输入错误!" << endl;
}
}
}
int main()
{
man.p_name="管理员";
man.p_code = "123";
student stu;
teacher t;
while (1)
{
mainmenu();
int choice;
cin >>choice;
partmenu(choice,stu,t,man);
if (choice == 4)
{
cout << "欢迎下次使用!" << endl;
return 0;
}
}
system("pause");
return 0;
}
版权声明:本文为qq_43050258原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。