实现一个学生请假系统,主要用来帮助学生请假具体要求如下
(1)登录界面有三种身份,每种身份有不同的功能。
(2)管理员能:添加账号,查看账号,删除账号, 注销登录。
(3)学生能:申请请假,查看我的请假,取消我的申请,注销登录。
(4)老师能:审核申请,查看申请,查看历史请假记录,注销登录。
本系统涉及的主要知识点
抽象类、封装、继承、多态、类、文件输入输出、STL容器等
系统功能模块图
主要模块流程图
(1)系统整体流程图
(2)学生模块流程图
(3)老师模块流程图
(4)管理员模块流程图
源程序
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
//身份抽象类
class Identity
{
public:
//操作菜单
virtual void operMenu() = 0;
//不同身份的菜单
virtual void IdentityMenu() = 0;
//姓名
string m_Name;
//密码
string m_Password;
};
//申请记录类
class Apply {
public:
Apply() {}
Apply(string a, string b, string c, string d)
{
this->a_name = a;
this->a_time = b;
this->a_cause = c;
this->a_condition = d;
}
//姓名
string a_name;
//时间
string a_time;
//原因
string a_cause;
//审核状态
string a_condition;
};
//教师类
class Teacher :public Identity
{
public:
//默认构造
Teacher();
//有参构造
Teacher(int id, string name, string pass);
//操作菜单
virtual void operMenu();
//不同身份的菜单
virtual void IdentityMenu();
//职工号
int Emp_Id;
//查看申请
void LookApply();
//审核申请
void RevApply();
//待审核记录容器
vector<Apply> va;
//已审核记录容器
vector<Apply> vaed;
//查看请假记录
void LookApplyed();
//查看记录容器
vector<Apply> vadl;
};
//申请记录类 ( 头文件重复包含问题无法解决,新添一类 )
class Apply1 {
public:
Apply1() {}
Apply1(string a, string b, string c, string d)
{
this->a_name = a;
this->a_time = b;
this->a_cause = c;
this->a_condition = d;
}
//姓名
string a_name;
//时间
string a_time;
//原因
string a_cause;
//审核状态
string a_condition;
};
//学生类
class Student :public Identity
{
public:
//默认构造
Student();
//有参构造
Student(int id,string name, string pass);
//进行功能操作的菜单
virtual void operMenu();
//不同身份的菜单
virtual void IdentityMenu();
//学号
int m_Id;
//申请请假
void Apply();
//查看我的申请
void LookMyApply();
//请假记录容器
vector<Apply1> vas;
//待审核时容器
vector<Apply1> vad;
//取消申请
void CancelApply();
//取消申请容器
vector<Apply1> vac;
};
//管理员类
class Administrator :public Identity
{
public:
//默认构造
Administrator();
//有参构造
Administrator(string name, string pass);
//进行功能操作的菜单
virtual void operMenu();
//不同身份的菜单
virtual void IdentityMenu();
//添加账号
void AddPerson();
//查看账号
void LookPerson();
//删除账号
void DeletePerson();
//存放老师的容器
vector<Teacher> vt;
//存放学生的容器
vector<Student> vs;
//判断是否删除成功标志,防止重复添加信息
bool IsFlag;
//将老师数据放入容器
void Set_T_vector();
//将学生数据放入容器
void Set_S_vector();
};
//学生请假系统
class StudentAFLManager
{
public:
//菜单
void Show_Menu();
//退出
void Quit();
};
//默认构造
Administrator::Administrator()
{
}
//有参构造
Administrator::Administrator(string name, string pass)
{
this->m_Name = name;
this->m_Password = pass;
}
//操作菜单
void Administrator::operMenu()
{
cout << "请输入姓名:" << endl;
string name;//存放用户输入的姓名
cin >> name;
cout << "请输入密码:" << endl;
string password;//存放用户输入的密码
cin >> password;
ifstream ifs; //创建流对象,对文件进行操作
ifs.open("administrator.txt", ios::in);//以只读的方式打开文件
string fname;//从文件中获取的姓名
string fpassword;//从文件中获取的密码
while (ifs >> fname && ifs >> fpassword)//读取文件中的内容
{
if (fname == name && fpassword == password)
{
cout << "身份验证成功!" << endl;
system("pause");
system("cls");
Identity *p = new Administrator(name, password);
//进入管理员子菜单
Administrator a;
while (true)
{
p->IdentityMenu();
cout << "请输入数字选择功能:";
int select;
cin >> select;
if (select == 1)
{
//添加账号
a.AddPerson();
}
else if (select == 2)
{
//查看账号
a.LookPerson();
}
else if (select == 3)
{
//删除账号
a.DeletePerson();
}
else if (select == 0)
{
//注销登录
cout << "注销成功!" << endl;
system("pause");
system("cls");
return;
}
}
}
}
cout << "身份验证失败!" << endl;
ifs.close();
system("pause");
system("cls");
}
//不同身份的菜单
void Administrator::IdentityMenu()
{
cout << "欢迎管理员: " << this->m_Name << endl;
cout << endl;
cout << "\t\t--------------------------------------------------------" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 1. 添加账号 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 2. 查看账号 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 3. 删除账号 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 0. 注销登录 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t--------------------------------------------------------" << endl;
}
void Administrator::AddPerson()
{
this->Set_T_vector();
this->Set_S_vector();
cout << "请选择添加的账号类型:" << endl;
cout << "1.老师" << endl;
cout << "2.学生" << endl;
int select;
cin >> select;
if (select == 1)
{
//添加老师账号
ofstream ofs;
ofs.open("teacher.txt", ios::out | ios::app);//写文件,追加方式 不用判断,不存在则创建文件
int id = 0;
string name;
string password;
cout << "请输入职工号:";
cin >> id;
//----------------
for (vector<Teacher>::iterator it = vt.begin(); it != vt.end(); it++)
{
if (it->Emp_Id == id)
{
cout << "错误!该职工号已存在,添加失败!" << endl;
system("pause");
system("cls");
return;
}
}
//---------------
cout << "请输入姓名:";
cin >> name;
cout << "请输入密码:";
cin >> password;
ofs << id << " " << name << " " << password << " " << endl;
cout << "添加成功" << endl;
system("pause");
system("cls");
ofs.close();
}
else if (select == 2)
{
//添加学生账号
ofstream ofs;
ofs.open("student.txt", ios::out | ios::app);//写文件,追加方式
int id = 0;
string name;
string password;
cout << "请输入学号:";
cin >> id;
for (vector<Student>::iterator it = vs.begin(); it != vs.end(); it++)
{
if (it->m_Id == id)
{
cout << "错误!该学号已存在,添加失败!" << endl;
system("pause");
system("cls");
return;
}
}
cout << "请输入姓名:";
cin >> name;
cout << "请输入密码:";
cin >> password;
ofs << id << " " << name << " " << password << " " << endl;
cout << "添加成功" << endl;
system("pause");
system("cls");
ofs.close();
}
else
{
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
}
}
void Administrator::LookPerson()
{
cout << "请选择查看的账号类型:" << endl;
cout << "1.老师" << endl;
cout << "2.学生" << endl;
int select;
cin >> select;
if (select == 1)
{
//查看老师账号
ifstream ifs;
ifs.open("teacher.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
int id;
string name;
string password;
cout << "----------------------------------------------" << endl;
cout << "职工号 " << " 姓名 " << " 密码" << endl;
while (ifs >> id && ifs >> name && ifs >> password)
{
cout << id << "\t" << name << "\t" << password << endl;
}
system("pause");
system("cls");
ifs.close();
}
else if (select == 2)
{
//查看学生账号
ifstream ifs;
ifs.open("student.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
int id;
string name;
string password;
cout << "----------------------------------------------" << endl;
cout << "学号 " << " 姓名 " << " 密码" << endl;
while (ifs >> id && ifs >> name && ifs >> password)
{
cout << id << "\t" << name << "\t" << password << endl;
}
system("pause");
system("cls");
ifs.close();
}
else
{
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
}
}
void Administrator::DeletePerson()
{
//清空,防止重复操作导致的数据重复添加
vt.clear();
vs.clear();
cout << "请选择删除账号的类型:" << endl;
cout << "1.老师" << endl;
cout << "2.学生" << endl;
int select;
cin >> select;
IsFlag = false;
if (select == 1)
{
ifstream ifs;
ifs.open("teacher.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Teacher t;
while (ifs >> t.Emp_Id && ifs >> t.m_Name && ifs >> t.m_Password)
{
vt.push_back(t);
}
cout << "----------------------------------------------" << endl;
for (vector<Teacher>::iterator it = vt.begin(); it != vt.end(); it++)
{
cout << it->Emp_Id << " " << it->m_Name << " " << it->m_Password << endl;
}
cout << "----------------------------------------------" << endl;
//删除老师账号
int s = 0;
cout << "请输入想要删除的老师职工编号:" << endl;
int id = 0;
cin >> id;
for (vector<Teacher>::iterator it = vt.begin(); it != vt.end(); it++)
{
if ((*it).Emp_Id == id )
{
IsFlag = true;
s++;
vt.erase(it);
cout << "删除成功" << endl;
break;
}
}
if(s==0)
cout << "删除失败,未找到该老师!" << endl;
if (true == IsFlag)
{
ofstream ofs;
ofs.open("teacher.txt", ios::trunc);
for (vector<Teacher>::iterator it = vt.begin(); it != vt.end(); it++)
{
ofs << it->Emp_Id << " " << it->m_Name << " " << it->m_Password << " " << endl;
}
ofs.close();
}
ifs.close();
//按任意键清屏
system("pause");
system("cls");
}
else if (select == 2)
{
ifstream ifs;
ifs.open("student.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Student t;
while (ifs >> t.m_Id && ifs >> t.m_Name && ifs >> t.m_Password)
{
vs.push_back(t);
}
cout << "----------------------------------------------" << endl;
for (vector<Student>::iterator it = vs.begin(); it != vs.end(); it++)
{
cout << it->m_Id << " " << it->m_Name << " " << it->m_Password << endl;
}
cout << "----------------------------------------------" << endl;
//删除学生账号
int s = 0;
cout << "请输入想要删除的学生学号:" << endl;
int id = 0;
cin >> id;
for (vector<Student>::iterator it = vs.begin(); it != vs.end(); it++)
{
if ((*it).m_Id == id)
{
IsFlag = true;
s++;
vs.erase(it);
cout << "删除成功" << endl;
break;
}
}
if(s==0)
cout << "删除失败,未找到该学生!" << endl;
if (true == IsFlag)
{
ofstream ofs;
ofs.open("student.txt", ios::trunc);
if (!ofs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
for (vector<Student>::iterator it = vs.begin(); it != vs.end(); it++)
{
ofs << it->m_Id << " " << it->m_Name << " " << it->m_Password << " " << endl;
}
ofs.close();
}
ifs.close();
//按任意键清屏
system("pause");
system("cls");
}
else
{
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
}
}
void Administrator::Set_T_vector()
{
vt.clear();
ifstream ifs;
ifs.open("teacher.txt", ios::in);
Teacher t;
while (ifs >> t.Emp_Id && ifs >> t.m_Name && ifs >> t.m_Password)
{
vt.push_back(t);
}
ifs.close();
}
void Administrator::Set_S_vector()
{
vs.clear();
ifstream ifs;
ifs.open("student.txt", ios::in);
Student t;
while (ifs >> t.m_Id && ifs >> t.m_Name && ifs >> t.m_Password)
{
vs.push_back(t);
}
ifs.close();
}
//默认构造
Student::Student()
{
}
//有参构造
Student::Student(int id,string name, string pass)
{
this->m_Id = id;
this->m_Name = name;
this->m_Password = pass;
}
//操作菜单
void Student::operMenu()
{
cout << "请输入学号:" << endl;
int Id = 0;
cin >> Id;
cout << "请输入姓名:" << endl;
string name;
cin >> name;
cout << "请输入密码:" << endl;
string password;
cin >> password;
ifstream ifs;
ifs.open("student.txt", ios::in);
int fid;//从文件中获取的学号
string fname;//从文件中获取的姓名
string fpassword;//从文件中获取的密码
while (ifs >> fid && ifs >> fname && ifs >> fpassword)//碰到空格就会结束,所以会读到学号,姓名,密码
{
if (fid == Id && fname == name && fpassword == password)
{
cout << "身份验证成功!" << endl;
system("pause");
system("cls");
Identity *p = new Student(Id, name, password);
Student s(Id, name, password);
//进入学生子菜单
while (true)
{
p->IdentityMenu();
cout << "请输入数字选择功能:";
int select;
cin >> select;
if (select == 1)
{
//申请请假
s.Apply();
}
else if (select == 2)
{
//查看我的申请
s.LookMyApply();
}
else if (select == 3)
{
//取消申请
s.CancelApply();
}
else if (select == 0)
{
//注销登录
cout << "注销成功!" << endl;
system("pause");
system("cls");
return;
}
else
{
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
}
}
}
}
cout << "身份验证失败!" << endl;
ifs.close();
system("pause");
system("cls");
}
//不同身份的菜单
void Student::IdentityMenu()
{
cout << "欢迎学生: " << this->m_Name << endl;
cout << endl;
cout << "\t\t--------------------------------------------------------" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 1. 申请请假 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 2. 查看我的申请 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 3. 取消申请 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 0. 注销登录 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t--------------------------------------------------------" << endl;
}
void Student::Apply()
{
cout << "请输入你请假的时间(xx月xx日):" << endl;
string time;
cin >> time;
cout << "请输入你请假的原因:" << endl;
string cause;
cin >> cause;
ofstream ofs;
ofs.open("apply.txt", ios::out|ios::app);
ofs <<this->m_Name<<" "<<time << " " << cause << " " << "审核中" << endl;
cout << "申请成功,审核中!" << endl;
ofs.close();
system("pause");
system("cls");
}
void Student::LookMyApply()
{
vas.clear();
vad.clear();
ifstream ifs;
ifs.open("applyed.txt",ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Apply1 a;
while (ifs >> a.a_name && ifs >> a.a_time && ifs >> a.a_cause && ifs >> a.a_condition)
{
vas.push_back(a);
}
int s = 0;
for (vector<Apply1>::iterator it = vas.begin(); it != vas.end(); it++)
{
if (it->a_name == this->m_Name)
{
++s;
cout << it->a_name << " " << it->a_time << " " << it->a_cause << " " << it->a_condition << endl;
/*vas.erase(it);
break;*/
}
}
ifs.close(); //用完关闭,不然第二次打不开
ifs.open("apply.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Apply1 a1;
while (ifs >> a1.a_name && ifs >> a1.a_time && ifs >> a1.a_cause && ifs >> a1.a_condition)
{
vad.push_back(a1);
}
for (vector<Apply1>::iterator it1 = vad.begin(); it1 != vad.end(); it1++)
{
if (it1->a_name == this->m_Name)
{
++s;
cout << it1->a_name << " " << it1->a_time << " " << it1->a_cause << " " << it1->a_condition << endl;
}
}
if (s == 0)
{
cout << "未查到您的相关申请记录!" << endl;
}
ifs.close();
system("pause");
system("cls");
}
void Student::CancelApply()
{
ifstream ifs;
ifs.open("apply.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Apply1 a;
while (ifs >> a.a_name && ifs >> a.a_time && ifs >> a.a_cause && ifs >> a.a_condition)
{
vac.push_back(a);
}
if (vac.empty())
{
cout << "错误!你没有相关申请记录!" << endl;
system("pause");
system("cls");
return;
}
cout << "确认要取消你的申请吗?" << endl;
cout << "1.确认" << endl;
cout << "2.返回" << endl;
int select;
while (true)
{
cin >> select;
if (select == 1)
{
//取消申请
for (vector<Apply1>::iterator it1 = vac.begin(); it1 != vac.end(); it1++)
{
if (it1->a_name == this->m_Name)
{
vac.erase(it1);
break;
}
}
ifs.close();
ofstream ofs;
ofs.open("apply.txt", ios::trunc);
for (vector<Apply1>::iterator it2 = vac.begin(); it2 != vac.end(); it2++)
{
ofs << it2->a_name << " " << it2->a_time << " " << it2->a_cause << " " << it2->a_condition << endl;
}
ofs.close();
cout << "取消成功!" << endl;
system("pause");
system("cls");
break;
}
else if (select == 2)
{
//返回
system("cls");
break;
}
else
{
cout << "输入无效,请重新输入!" << endl;
system("pause");
}
}
}
void StudentAFLManager::Show_Menu()
{
cout << endl;
cout << "===============================欢迎使用学生请假系统===============================" << endl;
cout << endl;
cout << "请输入您的身份:" << endl;
cout << "\t\t--------------------------------------------------------" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 1. 学 生 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 2. 老 师 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 3. 管 理 员 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 0. 退 出 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t--------------------------------------------------------" << endl;
}
void StudentAFLManager::Quit()
{
cout << "欢迎您下次使用!" << endl;
system("pause");
system("cls");
}
//默认构造
Teacher::Teacher()
{
}
//有参构造
Teacher::Teacher(int id, string name, string pass)
{
this->Emp_Id = id;
this->m_Name = name;
this->m_Password = pass;
}
//操作菜单
void Teacher::operMenu()
{
cout << "请输入职工号:" << endl;
int Id = 0;
cin >> Id;
cout << "请输入姓名:" << endl;
string name;
cin >> name;
cout << "请输入密码:" << endl;
string password;
cin >> password;
ifstream ifs;
ifs.open("teacher.txt", ios::in);
int fid;//从文件中获取的职工号
string fname;//从文件中获取的姓名
string fpassword;//从文件中获取的密码
while (ifs >> fid && ifs >> fname && ifs >> fpassword)//碰到空格就会结束,所以会读到学号,姓名,密码
{
if (fid == Id && fname == name && fpassword == password)
{
cout << "身份验证成功!" << endl;
system("pause");
system("cls");
//进入老师子菜单
Identity *p = new Teacher(Id, name, password);
Teacher t;
while (true)
{
p->IdentityMenu();
cout << "请输入数字选择功能:";
int select;
cin >> select;
if (select == 1)
{
//审核申请
t.RevApply();
}
else if (select == 2)
{
//查看申请
t.LookApply();
}
else if (select == 3)
{
//查看请假记录
t.LookApplyed();
}
else if (select == 0)
{
//注销登录
cout << "注销成功!" << endl;
system("pause");
system("cls");
return;
}
else
{
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
}
}
}
}
cout << "身份验证失败!" << endl;
ifs.close();
system("pause");
system("cls");
}
//不同身份的菜单
void Teacher::IdentityMenu()
{
cout << "欢迎教师: " << this->m_Name << endl;
cout << endl;
cout << "\t\t--------------------------------------------------------" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 1. 审核申请 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 2. 查看申请 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 3. 查看历史请假记录 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t| 0. 注销登录 |" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t--------------------------------------------------------" << endl;
}
void Teacher::LookApply()
{
vadl.clear();
ifstream ifs;
ifs.open("apply.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Apply a;
while (ifs >> a.a_name && ifs >> a.a_time && ifs >> a.a_cause && ifs >> a.a_condition)
{
vadl.push_back(a);
}
//判断文件是否为空
if (vadl.empty())
cout << "当前没有申请记录!" << endl;
for (vector<Apply>::iterator it = vadl.begin(); it != vadl.end(); it++)
{
cout << it->a_name << " " << it->a_time << " " << it->a_cause << " " << it->a_condition << endl;
}
ifs.close();
system("pause");
system("cls");
}
void Teacher::RevApply()
{
va.clear();
ifstream ifs;
ifs.open("apply.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
string buf;
cout << "姓名" << " " << "时间" << " " << "原因" << endl;
while (getline(ifs, buf))//逐行读取
{
cout << buf << endl;
}
ifs.close();
cout << "请输入你想审核哪位学生的申请?(输入学生姓名)" << endl;
string name;
cin >> name;
ifs.close();//关闭文件
ifs.open("apply.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Apply a;
int s = 0;
while (ifs >> a.a_name && ifs >> a.a_time && ifs >> a.a_cause && ifs>>a.a_condition)
{
va.push_back(a);
}
cout << "-------------------------------------" << endl;
cout << name << "的申请如下:" << endl;
for (vector<Apply>::iterator it = va.begin(); it != va.end(); it++)
{
if (it->a_name == name)
{
s++;
cout << it->a_name << " " << it->a_time << " " << it->a_cause << " " << it->a_condition << endl;
Apply m((*it).a_name, (*it).a_time, (*it).a_cause, (*it).a_condition);
va.erase(it);
vaed.push_back(m);
break;
}
}
cout << "-------------------------------------" << endl;
ifs.close();
ofstream ofs;
ofs.open("apply.txt", ios::out);
for (vector<Apply>::iterator it = va.begin(); it != va.end(); it++)
{
ofs << it->a_name << " " << it->a_time << " " << it->a_cause << " " << it->a_condition << endl;
}
ofs.close();
if (s == 0)
cout << "错误!该学生没有申请记录!" << endl;
cout << "请选择是否同意该申请?" << endl;
cout << "1.同意" << endl;
cout << "2.拒绝" << endl;
int select;
while (true)
{
cin >> select;
if (select == 1)
{
//同意
ofstream ofs;
ofs.open("applyed.txt", ios::out|ios::app);
for (vector<Apply>::iterator it = vaed.begin(); it != vaed.end(); it++)
{
ofs << it->a_name << " " << it->a_time << " " << it->a_cause << " " << "同意" << endl;
}
cout << "审核成功!已同意该申请!" << endl;
system("pause");
system("cls");
break;
}
else if (select == 2)
{
//拒绝
ofstream ofs;
ofs.open("applyed.txt", ios::out|ios::app);
for (vector<Apply>::iterator it = vaed.begin(); it != vaed.end(); it++)
{
ofs << it->a_name << " " << it->a_time << " " << it->a_cause << " " << "拒绝" << endl;
}
cout << "审核成功!已拒绝该申请!" << endl;
ofs.close();
system("pause");
system("cls");
break;
}
else
{
cout << "输入无效,请重新输入!" << endl;
system("pause");
}
ifs.close();
}
}
void Teacher::LookApplyed()
{
vadl.clear();
ifstream ifs;
ifs.open("applyed.txt", ios::in);
if (!ifs)//判断文件是否打开成功
{
cout << "打开文件失败,请检查文件名是否正确!" << endl;
system("pause");
system("cls");
return;
}
Apply a;
while (ifs >> a.a_name && ifs >> a.a_time && ifs >> a.a_cause && ifs >> a.a_condition)
{
vadl.push_back(a);
}
//判断文件是否为空
if (vadl.empty())
{
cout << "当前没有请假记录!" << endl;
system("pause");
system("cls");
return;
}
//-------------
for (vector<Apply>::iterator it = vadl.begin(); it != vadl.end(); it++)
{
cout << it->a_name << " " << it->a_time << " " << it->a_cause << " " << it->a_condition << endl;
}
ifs.close();
system("pause");
system("cls");
}
int main()
{
StudentAFLManager s;
Identity *p;
int select = 0;
while (true)
{
s.Show_Menu();
cin >> select;
switch (select)
{
case 1:
//学生
p = new Student;
p->operMenu();
break;
case 2:
//老师
p = new Teacher;
p->operMenu();
break;
case 3:
//管理员
p = new Administrator;
p->operMenu();
break;
case 0:
//退出
s.Quit();
exit(1);
break;
default:
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
}
}
return 0;
}
以上就是C++实现的学生请假系统了
如果这篇文章对你有帮助的话,就点个赞吧~
点赞收藏关注就是对我最大的支持~