diff --git a/src/Administrator.h b/src/Administrator.h deleted file mode 100644 index d27446d..0000000 --- a/src/Administrator.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once -#include -#include -#include -#include - -using namespace std; - -struct Administrator { - string ID; - string passWord; - int number;//管理楼栋号,系统管理员为0 -}; -void saveAdministrator(vector& a) { - ofstream ofs; - ofs.open("Administrator.txt", ios::out); - for (vector::iterator it = a.begin(); it != a.end(); it++) { - ofs << (*it).number << " " << (*it).ID << " " << (*it).passWord << endl; - }//依次存入管理员信息 - ofs.close(); -}//文件存储管理员信息 -void readAdministrator(vector& a) { - a.clear();//清空容器中信息,避免读入时导致信息重复 - Administrator a1;//临时变量 - ifstream ifs; - ifs.open("Administrator.txt", ios::in); - while (ifs >> a1.number && ifs >> a1.ID && ifs >> a1.passWord) { - a.push_back(a1); - }//循环读入管理员信息 - ifs.close(); -}//读入管理员信息 -int login(vector& a, string id, string pw) { - for (int i = 0; i < a.size(); i++) { - if (a[i].ID == id && a[i].passWord == pw) { - return a[i].number; - } - }//依次查询,返回管理楼栋号,总管理员楼栋号为零 - return -1; -}//管理员登录函数,返回0时表示总管理员登录,-1表示密码或工号错误,返回其他数字表示该管理员所管理的楼栋号 -void addAdministrator(vector& a, string id, string pw, int nu) { - Administrator ad;//临时变量 - ad.ID = id; - ad.number = nu; - ad.passWord = pw; - a.push_back(ad);//压入容器 - saveAdministrator(a); - readAdministrator(a);//更新文件存储 -}//添加新管理员 -int judgeNumber(vector& a, int nu) { - for (int i = 0; i < a.size(); i++) { - if (a[i].number == nu) { - return 1;//该楼栋号已存在 - } - } - return 0; -}//判断输入楼栋号是否存在 -int judgeId(vector& a, string id) { - for (int i = 0; i < a.size(); i++) { - if (a[i].ID == id) { - return 1;//该管理员工号已存在 - } - } - return 0; -}//判断工号是否存在 -void changePassWordOfAdministrator(vector& a, string pW, string id) { - for (int i = 0; i < a.size(); i++) { - if (a[i].ID == id) { - a[i].passWord = pW; - } - }//已经登录成功表明该管理员必定存在 - saveAdministrator(a); - readAdministrator(a);//更新文件信息 -}//修改管理员密码 diff --git a/src/Dormitory.h b/src/Dormitory.h deleted file mode 100644 index 848bf74..0000000 --- a/src/Dormitory.h +++ /dev/null @@ -1,419 +0,0 @@ -#pragma once -#include"room.h" - -using namespace std; -struct Dormitory { - - int floors;//楼层总数 - int rooms;//每层房间数 - int number;//楼栋号 - vectorroom;//本宿舍的寝室房间容器 - Dormitory() {};//默认构造函数 - Dormitory(int fl, int ro, int nu) { - floors = fl; - rooms = ro; - number = nu; - int weishu = 2;//总房间号位数,与当前房间号位数同理 - for (int f = 1; f <= fl; f++) { - for (int r = 1; r <= ro; r++) { - int weishu1=0;//当前房间号位数,本房间号位数没有计算表示楼层的那一位,如寝室号417,不会计算4这一位,仅计算17两位 - for (int i = r; i != 0; i = i / 10) { - weishu1++; - } - string rn;//临时变量 - rn = to_string(r); - for (int i = 0; i < weishu-weishu1; i++) { - string temp; - temp = rn; - rn ="0"+temp; - }//生成本房间的本层房间号 - rn =to_string(f)+rn;//在本层房间号前面加上楼层号构成寝室号,如17前加上楼层4,构成寝室号417 - Room Ro(rn);//生成本寝室 - room.push_back(Ro);//将本寝室压入本宿舍楼栋寝室房间容器中 - } - } - }//构造函数,添加宿舍楼与读入宿舍信息时使用 - void saveinfo(ofstream &o) { - o << number << " " << floors << " " << rooms << endl; - }//写出本宿舍楼楼栋号、楼层数及每层房间数信息,由savaDormitory函数调用 - void saveRoom(ofstream& o) { - for (vector::iterator it = room.begin(); it != room.end(); it++) { - (*it).saveRoom(o); - } - }//循环写出本宿舍楼各个寝室的信息,由saveDormitory函数调用 - string searchStudent(vector& d, string id) { - for (int i = 0; i < room.size(); i++) { - for (int j = 0; j < 4; j++) { - if (room[i].stu[j].studentID == id) { - string s = "学号:" + room[i].stu[j].studentID + " 姓名:" + room[i].stu[j].name + " 性别:" + room[i].stu[j].sex + " 寝室号:" + room[i].roomNumber+"\n"; - return s; - } - } - } - string o; - return o;//未查找到该信息,返回空字符串 - }//查询学生信息 - string searchRoom(string rn) { - for (int i = 0; i < room.size(); i++) { - if (room[i].roomNumber == rn) { - string s = room[i].sendinfo(); - return s; - } - } - string o; - return o;//未查找到该信息,返回空字符串 - }//查询寝室信息 - int judgeFull(string rn) { - for (int i = 0; i < room.size(); i++) { - if (room[i].roomNumber == rn) { - for (int j = 0; j < 4; j++) { - if (room[i].stu[i].name == "未入住") { - return 1; - } - } - return 0; - } - } - }//判断宿舍是否已满,用于对进行宿舍调整时对目标寝室是否人满的判断 - int judgeExitS(string na, string id) { - for (int i = 0; i < room.size(); i++) { - for (int j = 0; j < 4; j++) { - if (room[i].stu[j].name == na && room[i].stu[j].studentID == id) { - return 1; - } - } - } - return 0; - }//判断学生是否存在,进行宿舍调整前判断学生信息是否输入正确 - int judgeExitR(string rn) { - for (int i = 0; i < room.size(); i++) { - if (room[i].roomNumber == rn) { - return 1; - } - } - return 0; - }//判断寝室是否存在,用于查询寝室时判断本宿舍楼是否存在该寝室 - string searchRepair() { - string o; - for (int i = 0; i < room.size(); i++) { - if (room[i].repairReport == true) { - o = o + "寝室号:" + room[i].roomNumber + " 报修内容:"; - o = o + room[i].breakdown; - o = o + "\n"; - } - } - return o; - }//查询宿舍报修情况 - void clearRoom(vector& s,string rn) { - string id[4]; - for (int i = 0; i < room.size(); i++) { - if (room[i].roomNumber == rn) { - for (int j = 0; j < 4; j++) { - id[j] = room[i].stu[j].studentID; - room[i].stu[j].name = "未入住"; - room[i].stu[j].sex = "不详"; - room[i].stu[j].studentID = "不详"; - } - - } - } - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id[0] || s[i].studentID == id[1] || s[i].studentID == id[2] || s[i].studentID == id[3]) { - s.erase(s.begin() + i); - } - } - saveStudent(s); - readStudent(s); - }//清空毕业生宿舍,集中体现在清楚学生信息,报修及寝室号信息无需修改,本函数尚未更新文件 - string showEmpty() { - string o; - for (int i = 0; i < room.size(); i++) { - if (room[i].judgeEmpty() == 1) { - o = o + "寝室号:" + room[i].roomNumber + " 状态:" + "有空床"; - o = o + "\n"; - } - } - return o; - }//显示尚有空床的宿舍 - int addStudent(vector&s,string na, string id, string se) { - for (int i = 0; i < room.size(); i++) { - for (int j = 0; j < 4; j++) { - if (room[i].stu[j].name == "未入住") { - room[i].stu[j].name = na; - room[i].stu[j].studentID = id; - room[i].stu[j].sex = se; - for (int k = 0; k < s.size(); k++) { - if (s[k].studentID == id) { - s[k].dormitoryNumber = number; - s[k].roomNumber = stoi(room[i].roomNumber.c_str()); - } - } - return 1; - } - } - } - return 0;//整栋宿舍楼已无空床可以安排 - }//依次向本楼栋的空床中添加学生 -}; -void saveDormitory(vector& d) { - ofstream ofs; - ofs.open("Dormitory.txt", ios::out); - for (vector::iterator it = d.begin(); it != d.end(); it++) { - (*it).saveinfo(ofs); - (*it).saveRoom(ofs); - } - ofs.close(); -}//写出寝室信息的函数 -void readDormitory(vector& d) { - d.clear(); - ifstream ifs; - ifs.open("Dormitory.txt", ios::in); - int f = 0;//楼层总数临时变量 - int r = 0;//每层房间数临时变量 - int n = 0;//楼栋号临时变量 - while (ifs >> n && ifs >> f && ifs >> r) { - Dormitory d1(f, r, n);//首先读入寝室楼的楼层数、每层房间数、楼栋号信息用以初始化一个寝室楼对象 - string sn; //寝室号临时变量 - string s1n; string s1i; string s1s;//第一个学生的姓名、学号、性别信息 - string s2n; string s2i; string s2s;//第二个学 - string s3n; string s3i; string s3s;//第三个学生 - string s4n; string s4i; string s4s;//第四个学生 - bool r;//是否报修 - string bd;//报修内容临时变量 - vector::iterator it = d1.room.begin(); - while (ifs >> sn && ifs >> s1n && ifs >> s1s && ifs >> s1i && ifs >> s2n && ifs >> s2s && ifs >> s2i && ifs >> s3n && ifs >> s3s && ifs >> s3i && ifs >> s4n && ifs >> s4s && ifs >> s4i && ifs >> r&&ifs>>bd&& it != d1.room.end()) { - (*it).setRoom(sn, s1n, s1i, s1s, s2n, s2i, s2s, s3n, s3i, s3s, s4n, s4i, s4s, r,bd); - if (it != d1.room.end()-1) { - it++; - }//容器指针向后移动一位 - else { - break; - }//到达本容器最后一个存储位置,寝室信息读入停止 - } - d.push_back(d1);//降本寝室楼压入容器 - } - ifs.close(); -} -void addDormitory(vector& d,int fl,int ro,int nu) { - Dormitory d1(fl, ro, nu); - d.push_back(d1); - saveDormitory(d); - readDormitory(d); -}//添加寝室楼函数 -int judgeExitD(vector& d, int nu) { - for (int i = 0; i < d.size(); i++) { - if (d[i].number == nu) { - return 1; - } - } - return 0; -}//判断宿舍楼是否存在 -string arrange(vector& d,vector&s ,string na, string id, string se, int nu) { - string o; - for (int k = 0; k < s.size(); k++) { - if (s[k].name == na && s[k].studentID == id && s[k].sex == se) { - for (int i = 0; i < d.size(); i++) { - if (d[i].number == nu) { - int j = d[i].addStudent(s, na, id, se); - if (j == 1) { - o = o + na + "已排床成功!\n"; - return o; - } - else { - o = o + na + "排床失败,本栋已无空余床位!\n"; - return o; - } - } - } - } - } - o = "该同学不存在,排床失败!\n"; - return o; -}//安排单个同学床位,本函数尚未更新保存文件 -string searchRoom(vector& d, vector& s, string id) { - string o; - int k; - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id) { - k = i; - break; - } - }//判断该学生在学生容器中的位置 - for (int i = 0; i < d.size(); i++) { - if (s[k].dormitoryNumber == d[i].number) { - for (int j = 0; j < d[i].room.size(); j++) { - if (d[i].room[j].stu[0].studentID == id || d[i].room[j].stu[1].studentID == id || d[i].room[j].stu[2].studentID == id || d[i].room[j].stu[3].studentID == id) { - string s = d[i].room[j].sendinfo(); - return s; - } - } - }//查询该学生寝室号信息,返回该楼栋中该学生的寝室信息 - } - return o;//未查找到该信息,返回空字符串 -}//查询单个寝室信息 -int requestRepair(vector& d, vector& s, string bd,string id) { - int k; - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id) { - k = i; - break; - } - }//判断该学生在学生容器中的位置 - for (int i = 0; i < d.size(); i++) { - if (s[k].dormitoryNumber == d[i].number) { - for (int j = 0; j < d[i].room.size(); j++) { - if (d[i].room[j].stu[0].studentID == id || d[i].room[j].stu[1].studentID == id || d[i].room[j].stu[2].studentID == id || d[i].room[j].stu[3].studentID == id) { - d[i].room[j].repairReport = true; - d[i].room[j].breakdown = bd; - saveDormitory(d); - readDormitory(d); - return 1; - } - } - } - }//读取学生容器中该学生的寝室信息,在宿舍容器d中对该寝室的报修情况进行修改 - return 0; -}//申请报修 -string handleRepair(vector& d, string num,int nu){ - string o; - for (int i = 0; i < d[nu].room.size(); i++) { - if (d[nu].room[i].repairReport == true && d[nu].room[i].roomNumber == num) { - d[nu].room[i].repairReport = false; - d[nu].room[i].breakdown = "无"; - o = num + "寝室报修情况已更新!\n"; - saveDormitory(d); - readDormitory(d); - return o; - } - } - o = "该寝室不存在或该寝室尚未报修!\n"; - return o; -}//处理报修 -int changeRoom1(vector& d, vector& s, string na, string id, string rn,int nu) { - if (d[nu].judgeExitS(na, id) == 1) { - int k = -1; - for (int i = 0; i < d[nu].room.size(); i++) { - if (d[nu].room[i].roomNumber == rn) { - k = i; - break; - } - }//确定该寝室在容器中的位置 - if (k == -1) { - return 3; - }//该寝室不存在 - if (d[nu].room[k].judgeEmpty() != 1) { - return 2; - }//目标寝室已满 - string se; - int flag = 0; - for (int i = 0; i < d[nu].room.size(); i++) { - for (int j = 0; j < 4; j++) { - if (d[nu].room[i].stu[j].name == na && d[nu].room[i].stu[j].studentID == id) { - se = d[nu].room[i].stu[j].sex; - d[nu].room[i].stu[j].name = "未入住"; - d[nu].room[i].stu[j].studentID = "不详"; - d[nu].room[i].stu[j].sex = "不详"; - flag = 1; - break; - }//提取性别信息,将原寝室中该学生信息清空 - } - if (flag == 1) { - break; - } - } - for (int i = 0; i < d[nu].room.size(); i++) { - if (d[nu].room[i].roomNumber == rn) { - int j; - for (j = 0; j < 4; j++) { - if (d[nu].room[i].stu[j].name == "未入住") { - break; - } - } - d[nu].room[i].stu[j].name = na; - d[nu].room[i].stu[j].studentID = id; - d[nu].room[i].stu[j].sex = se; - } - }//在目标寝室中选中未入住的床位将信息填入 - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id) { - s[i].roomNumber = stoi(rn.c_str()); - } - } - saveDormitory(d); - saveStudent(s); - readDormitory(d); - readStudent(s); - return 1;//调整成功 - } - return 0;//该该学生不存在 -}//将学生调至有空床的宿舍时 -int changeRoom2(vector& d, vector& s, string na1, string id1, string na2, string id2, int nu) { - if (d[nu].judgeExitS(na1, id1) == 1 && d[nu].judgeExitS(na2, id2) == 1) { - int flag = 0; - int ro1, ro2;//房间容器位置临时变量 - int st1, st2;//床位号临时变量 - string rn1, rn2;//寝室号临时变量 - for (int i = 0; i < d[nu].room.size(); i++) { - for (int j = 0; j < 4; j++) { - if (d[nu].room[i].stu[j].name == na1 && d[nu].room[i].stu[j].studentID == id1) { - ro1 = i; - st1 = j; - rn1 = d[nu].room[i].roomNumber; - flag = 1; - } - if (flag == 1) { - break; - } - } - }//确定学生1在寝室容器中的位置 - flag = 0; - for (int i = 0; i < d[nu].room.size(); i++) { - for (int j = 0; j < 4; j++) { - if (d[nu].room[i].stu[j].name == na2 && d[nu].room[i].stu[j].studentID == id2) { - ro2 = i; - st2 = j; - rn2 = d[nu].room[i].roomNumber; - flag = 1; - } - } - if (flag == 1) { - break; - } - }//确定学生2在寝室容器中的位置 - d[nu].room[ro1].stu[st1].name = na2; - d[nu].room[ro1].stu[st1].studentID = id2; - d[nu].room[ro2].stu[st2].name = na1; - d[nu].room[ro2].stu[st2].studentID = id1;//更新容器信息 - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id1) { - s[i].roomNumber = stoi(rn2.c_str()); - break; - } - } - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id2) { - s[i].roomNumber = stoi(rn1.c_str()); - break; - } - } - saveDormitory(d); - saveStudent(s); - readDormitory(d); - readStudent(s);//更新文件存储 - return 1; - } - return 0;//有学生信息不存在 -}//对两位同学进行宿舍对换,由于居住于同一栋宿舍故性别必然相同,仅需调换姓名及学号信息即可 -int changeRepair(vector& d, string rn, int nu) { - for (int i = 0; i < d[nu].room.size(); i++) - { - if (d[nu].room[i].roomNumber == rn) { - d[nu].room[i].repairReport = false; - d[nu].room[i].breakdown = "无"; - saveDormitory(d); - readDormitory(d); - return 1; - } - } - return 0; -}//没用到,忘记写了这个函数了 diff --git a/src/Student.h b/src/Student.h deleted file mode 100644 index 3ae8e00..0000000 --- a/src/Student.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -#include -#include -#include -#include - -using namespace std; -struct Student { - string name;//姓名 - string passWord;//密码 - string sex;//性别 - string studentID;//学号 - int dormitoryNumber;//楼栋号 - int roomNumber;//寝室号 - Student() { - dormitoryNumber = 0; - roomNumber = 0; - }//构造函数,初始状态下学生楼栋号和寝室号为零,不过在实际写代码的时候没用到这个函数 - - string searchself(vector& s) { - string o;//本人信息临时变量 - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == studentID) { - if (s[i].dormitoryNumber == 0) { - string s1 = "学号:" + studentID + " 姓名:" + name + " 性别:" + sex + " 尚未分配宿舍\n"; - return s1; - }//楼栋号为零,尚未分配宿舍 - else { - string s1 = "学号:" + studentID + " 姓名:" + name + " 性别:" + sex + " 所在楼栋:" + to_string(dormitoryNumber) + " 寝室号:" + to_string(roomNumber) + "\n"; - return s1; - }//当楼栋号不为零时,表示 - }//当查询学生学号与学生容器中某一学生学号相同时 - }//依次查询学生容器中各个学生的信息 - return o;//未查找到该信息,返回空字符串 - }//查询本人信息,返回的值是存有本人信息的字符串 -}; -struct student { - string name;//姓名 - string sex;//性别 - string studentID;//学号 -};//小学生结构体,用于宿舍中存储学生信息 -void readStudent(vector& s) { - s.clear();//清空学生容器中信息,以便读入文件中信息,避免信息重复 - Student st;//临时变量 - ifstream ifs; - ifs.open("Student.txt", ios::in); - if (!ifs.is_open()) - return;//打开文件 - while (ifs >> st.name && ifs >> st.studentID && ifs >> st.sex && ifs >> st.passWord && ifs >> st.dormitoryNumber && ifs >> st.roomNumber) { - s.push_back(st); - }//循环读入学生信息 - ifs.close();//关闭文件 -}//读入学生信息 -void saveStudent(vector& s) { - ofstream ofs; - ofs.open("Student.txt", ios::out);//打开文件,使用out打开方式,避免存储时新存入的信息与旧信息重复 - for (vector::iterator it = s.begin(); it != s.end(); it++) { - ofs << (*it).name << " " << (*it).studentID << " " << (*it).sex << " " << (*it).passWord << " " << (*it).dormitoryNumber << " " << (*it).roomNumber << endl; - }//循环写出学生信息 - ofs.close();//关闭文件 -}//保存学生信息到文件中 -int studentLogin(vector& s, string sI, string pW) { - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == sI && s[i].passWord == pW) - return 1;//账号及密码正确 - }//循环比对容器中每个学生的学号及密码与输入的是否相同 - return 0;//当容器中没有学生学号及密码与输入信息同时符合时表示学号或密码错误,返回0 -}//学生登录,参数为学生容器,输入的密码及学号 -void changePassWordOfStudent(string id, string pw, vector& s) { - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id) { - s[i].passWord = pw; - }//学号相同时,更新本学生的密码 - }//循环比对学生容器中每个学生的学号与本次登陆的学生的学号,由于登录成功,表明本学号必定存在于容器中 - saveStudent(s); - readStudent(s);//存入文件后读入,同步更新文件中信息 -}//修改学生密码,参数为登录时学生的学号、新的密码、学生容器 diff --git a/src/menu.h b/src/menu.h deleted file mode 100644 index 1a7d9b8..0000000 --- a/src/menu.h +++ /dev/null @@ -1,532 +0,0 @@ -#pragma once -#include "Dormitory.h" -#include "Administrator.h" -#include - -using namespace std; -void add(vector& d, vector& a) { - int nu; - string id; - cout << "请输入新建楼栋号:"; - cin >> nu; - cout << "请输入新建楼栋管理员工号:"; - cin >> id; - if (judgeId(a, id) == 1 || judgeNumber(a, nu) == 1) { - cout << "该楼栋号或工号已存在!" << endl; - system("pause"); - return; - } - else { - string pw; - int f; - int r; - cout << "请输入初始管理员密码:"; - cin >> pw; - cout << "请输入楼层总数:"; - cin >> f; - cout << "请输入每层房间数:"; - cin >> r; - addDormitory(d, f, r, nu); - addAdministrator(a, id, pw, nu); - cout << "----------------------------------" << endl; - cout << "创建成功!" << endl; - system("pause"); - return; - } -}//添加新宿舍 -int menuOfStudent() { - int choice; - cout << "==================================================" << endl; - cout << "| 1、查询本人信息 |" << endl; - cout << "| 2、查询寝室信息 |" << endl; - cout << "| 3、申请保修 |" << endl; - cout << "| 4、修改密码 |" << endl; - cout << "| 0、退出 |" << endl; - cout << "==================================================" << endl; - cout << "请选择您的操作:"; - cin >> choice; - return choice; -}//学生功能菜单 -int menuOfchiefAdministrator() { - int choice; - cout << "==================================================" << endl; - cout << "| 1、分配宿舍 |" << endl; - cout << "| 2、添加宿舍 |" << endl; - cout << "| 3、查询学生信息 |" << endl; - cout << "| 4、查询寝室信息 |" << endl; - cout << "| 5、清空毕业宿舍 |" << endl; - cout << "| 6、修改密码 |" << endl; - cout << "| 0、退出 |" << endl; - cout << "==================================================" << endl; - cout << "请选择您的操作:"; - cin >> choice; - return choice; -}//总宿舍管理员功能菜单 -int menuOfAdministrator() { - int choice; - cout << "==================================================" << endl; - cout << "| 1、查询学生信息 |" << endl; - cout << "| 2、查询宿舍信息 |" << endl; - cout << "| 3、单人宿舍调整 |" << endl; - cout << "| 4、双人宿舍调整 |" << endl; - cout << "| 5、查询空闲宿舍 |" << endl; - cout << "| 6、报修处理 |" << endl; - cout << "| 7、修改密码 |" << endl; - cout << "| 0、退出 |" << endl; - cout << "==================================================" << endl; - cout << "请选择您的操作:"; - cin >> choice; - return choice; -}//宿舍管理员功能菜单 -void studnetOperate(vector& s, vector& d, string id) { - int i; - for (int j = 0; j < s.size(); j++) { - if (s[j].studentID == id) { - i = j; - break; - } - }//确定该学生在学生容器中的位置 - int choice; - do { -flag2://当学生选择出现错误时 - system("cls"); - choice = menuOfStudent(); - switch (choice) { - case 1: { - system("cls"); - string o; - o = s[i].searchself(s); - cout << o; - system("pause"); - break; - }//查询本人信息 - case 2: { - system("cls"); - string o; - o=searchRoom(d, s, id); - if (o.empty() != 1) { - cout << o; - } - else { - cout << "尚未分配宿舍!" << endl; - }//当o为空字符串时尚未分配宿舍 - system("pause"); - break; - }//查询本人宿舍 - case 3: { - system("cls"); - int flag = 0; - for (int j = 0; j < s.size(); j++) { - if (s[i].studentID == id && s[i].dormitoryNumber != 0) { - flag = 1;//已分配宿舍 - break; - } - } - if (flag == 1) { - string o; - int i; - cout << "请输入报修内容:"; - cin >> o; - cout << "是否确认报修? 1-确认 2-取消" << endl; - cin >> i; - if (i == 1) { - requestRepair(d, s, o, id); - cout << "报修成功!" << endl; - system("pause"); - } - else { - cout << "报修失败!" << endl; - system("pause"); - } - } - else { - cout << "尚未分配宿舍,报修失败!" << endl; - system("pause"); - } - break; - }//申请保修 - case 4: { - system("cls"); - string pw; - cout << "请输入新的密码:"; - cin >> pw; - changePassWordOfStudent(id,pw,s); - cout << "修改成功!" << endl; - system("pause"); - break; - }//修改密码 - case 0: - break; - default: { - cout << "您输入的选项不存在请重新选择" << endl; - Sleep(3000); - goto flag2; - break; - } - } - } while (choice != 0); - cout << "退出成功!感谢使用!" << endl; - system("pause"); -}//学生操作列表 -void chiefAdministratorOperate(vector&d,vector&a,vector&s, string chiefid) { - int choice; - do { - flag3://当总管理员功能选择有误时 - system("cls"); - choice = menuOfchiefAdministrator(); - switch (choice) { - case 1: { - system("cls"); - int nu; - string na; - string id; - string se; - string o;//临时变量 - cout << "请选择分配楼栋:"; - cin >> nu; - cout << "请依次输入学生姓名、学号、性别:" << endl; - while (cin >> na && cin >> id && cin >> se) { - if (na == "0") { - o = "排床结束!"; - cout << o << endl; - break; - } - o=arrange(d, s, na, id, se, nu); - cout << o; - }//通过while循环实现批量处理排床 - saveDormitory(d); - saveStudent(s); - system("pause"); - break; - } - case 2: { - system("cls"); - add(d, a); - break; - }//添加新宿舍 - case 3: { - system("cls"); - string id; - cout << "请输入查询学生学号:"; - cin >> id; - string o; - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id) { - o = o + "学号:" + s[i].studentID + " 姓名:" + s[i].name + " 性别:" + s[i].sex + " 所在楼栋:" + to_string(s[i].dormitoryNumber) + " 寝室号:" + to_string(s[i].roomNumber) + "\n"; - break; - } - } - if (o.empty() == 1) { - cout << "该学生不存在!" << endl; - system("pause"); - } - else { - cout << o; - system("pause"); - } - break; - }//查询学生信息 - case 4: { - system("cls"); - int nu; - string rn; - cout << "请输入查询寝室所在楼栋号:"; - cin >> nu; - cout << "请输入查询寝室号:"; - cin >> rn; - string o; - for (int i = 0; i < d.size(); i++) { - if (d[i].number == nu) { - for (int j = 0; j < d[i].room.size(); j++) { - if (d[i].room[j].roomNumber==rn){ - o = d[i].room[j].sendinfo(); - } - } - } - } - if (o.empty() == 1) { - cout << "该寝室不存在!" << endl; - system("pause"); - } - else { - cout << o; - system("pause"); - } - break; - }//查询具体寝室信息信息 - case 5: { - system("cls"); - int nu; - string rn; - string o; - cout << "请输入楼栋号:"; - cin >> nu; - if (judgeExitD(d, nu) == 0) { - cout << "该宿舍楼不存在!" << endl; - break; - } - else { - cout << "请输入待清空寝室号(或输入0退出功能):" ; - while (cin >> rn&&rn!="0") { - if (d[nu].judgeExitR(rn) == 1) { - d[nu].clearRoom(s,rn); - o = o + rn + "寝室已清空!\n"; - saveDormitory(d); - readDormitory(d); - } - else { - o = o + rn + "寝室不存在!\n"; - } - cout << o; - cout << "请输入待清空寝室号(或输入0退出功能):"; - } - } - system("pause"); - break; - }//清空寝室信息 - case 6: { - system("cls"); - string pw; - cout << "请输入新密码:"; - cin >> pw; - changePassWordOfAdministrator(a, pw, chiefid); - cout << "修改成功!" << endl; - system("pause"); - break; - }//修改密码 - case 0: - break; - default: - cout << "您的选择有误!请重新选择" << endl; - Sleep(3000); - goto flag3; - break; - } - } while (choice != 0); - cout << "退出成功!感谢使用" << endl; - system("pause"); -}//总管理员菜单 -void AdminisreatorOperate(vector& d, vector& a, vector& s, int nu) { - int choice; - do { - flag4://当选择有误时 - system("cls"); - choice = menuOfAdministrator(); - switch (choice) { - case 1:{ - system("cls"); - string id; - cout << "请输入查询学生学号:"; - cin >> id; - string o; - for (int i = 0; i < s.size(); i++) { - if (s[i].studentID == id) { - o = o + "学号:" + s[i].studentID + " 姓名:" + s[i].name + " 性别:" + s[i].sex + " 所在楼栋:" + to_string(s[i].dormitoryNumber) + " 寝室号:" + to_string(s[i].roomNumber) + "\n"; - break; - } - } - if (o.empty() == 1) { - cout << "该学生不存在!" << endl; - system("pause"); - } - else { - cout << o; - system("pause"); - } - break; - }//查询学生个人信息 - case 2: { - system("cls"); - string o; - string rn; - cout << "请输入查询寝室号:"; - cin >> rn; - int j = d[nu].judgeExitR(rn); - j = 1; - if (j == 0) { - cout << "该寝室不存在!" << endl; - system("pause"); - } - else { - for (int i = 0; i < d[nu].room.size(); i++) { - if (d[nu].room[i].roomNumber == rn) { - o = d[nu].room[i].sendinfo(); - break; - } - } - cout << o; - system("pause"); - } - break; - }//查询寝室信息 - case 3: { - flag5://当学生不存在时 - system("cls"); - string na; - string id; - string rn; - cout << "请输入需调整学生姓名:"; - cin >> na; - cout << "请输入需调整学生学号:"; - cin >> id; - if (d[nu].judgeExitS(na,id) != 1) { - cout << "该学生不存在,请重新输入!" << endl; - system("pause"); - goto flag5; - } - cout << "请输入目标寝室:"; - cin >> rn; - int o = changeRoom1(d, s, na, id, rn, nu); - if (o == 1) { - cout << "调整成功!" << endl; - system("pause"); - } - else if (o == 2) { - cout << "目标寝室已满,调整失败!" << endl; - system("pause"); - } - else if (o == 3) { - cout << "目标寝室不存在,调整失败!" << endl; - system("pause"); - } - else { - cout << "该学生不存在,调整失败!" << endl; - system("payse"); - } - break; - }//单人寝室调整 - case 4: { - system("cls"); - string na1, na2; - string id1, id2; - cout << "请依次输入两名学生的姓名和学号:"; - cin >> na1 >> id1 >> na2 >> id2; - int i = changeRoom2(d, s, na1, id1, na2, id2, nu); - if (i == 1) { - cout << "调整成功!" << endl; - system("pause"); - } - else { - cout << "调整失败!或有同学信息输入错误" << endl; - system("pause"); - } - break; - }//双人寝室调整 - case 5: { - system("cls"); - string o; - o = d[nu].showEmpty(); - cout << o; - system("pause"); - break; - }//查询空闲寝室 - case 6: { - system("cls"); - string o; - o = d[nu].searchRepair(); - if (o.empty() != 1) { - cout << o; - cout << "请输入已维修完成的寝室号(输入0退出功能):"; - string num = "-1"; - while (cin >> num && num != "0") { - o = handleRepair(d, num,nu); - cout << o; - cout << "请输入已维修完成的寝室号(输入0退出功能):"; - } - cout << "退出功能!" << endl; - system("pause"); - } - else { - cout << "本楼尚未有寝室进行报修!" << endl; - system("pause"); - } - break; - }//处理报修 - case 7: { - system("cls"); - string pw; - cout << "请输入新密码:"; - cin >> pw; - for (int i = 0; i < a.size(); i++) { - if (a[i].number == nu) { - a[i].passWord = pw; - saveAdministrator(a); - readAdministrator(a); - cout << "修改成功!" << endl; - system("payse"); - } - } - break; - }//修改密码 - case 0: - break; - default: - cout << "您的选择有误!请重新输入" << endl; - Sleep(3000); - goto flag4; - break; - } - } while (choice != 0); - cout << "退出成功!感谢使用" << endl; - system("pause"); -} -void show(vector&s, vector&d, vector&a) { - int op; - do { - flag1://当账号或密码输入错误时或选择有误时 - system("cls"); - cout << " 欢迎使用 宿舍管理系统" << endl; - cout << "请选择您的身份:1-学生 2-管理员 0-退出" << endl; - cin >> op; - switch (op) { - case 1: { - string id; - string pw; - cout << "请输入学号:"; - cin >> id; - cout << "请输入密码:"; - cin >> pw; - int i = studentLogin(s, id, pw); - if (i == 1) { - studnetOperate(s, d, id); - } - else { - cout << "账号或密码错误!" << endl; - system("pause"); - goto flag1; - } - break; - } - case 2: { - string id; - string pw; - int num; - cout << "请输入工号:"; - cin >> id; - cout << "请输入密码:"; - cin >> pw; - num = login(a, id, pw); - if (num == -1) { - cout << "账号或密码错误!" << endl; - system("pause"); - goto flag1; - } - else if (num == 0) { - chiefAdministratorOperate(d, a, s,id); - } - else { - AdminisreatorOperate(d, a, s, num-1); - } - } - case 0: - break; - default: - cout << "您的选择有误!请重新输入" << endl; - Sleep(3000); - goto flag1; - break; - } - } while (op != 0); - cout << "退出系统!感谢使用" << endl; - system("pause"); -} \ No newline at end of file diff --git a/src/room.h b/src/room.h deleted file mode 100644 index 3009c2a..0000000 --- a/src/room.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once -#include "Student.h" - -using namespace std; -struct Room { - student stu[4];//学生数组,默认为四人学生寝室 - string roomNumber;//寝室号 - string breakdown;//本寝室待修部位 - bool repairReport;//报修情况,ture为有报修,false为未报修 - Room() {};//默认构造函数 - Room(string rN) { - for (int i = 0; i < 4; i++) { - stu[i].name = "未入住"; - stu[i].sex = "不详"; - stu[i].studentID = "不详"; - } - roomNumber = rN; - breakdown = "无"; - this->repairReport = false; - }//生成宿舍楼时使用的构造函数,参数仅需寝室号即可 - void setRoom(string rn, string s1n, string s1i, string s1s, string s2n, string s2i, string s2s, string s3n, string s3i, string s3s, string s4n, string s4i, string s4s,bool r,string bd) { - roomNumber = rn; - stu[0].name = s1n; stu[0].studentID = s1i; stu[0].sex = s1s; - stu[1].name = s2n; stu[1].studentID = s2i; stu[1].sex = s2s; - stu[2].name = s3n; stu[2].studentID = s3i; stu[2].sex = s3s; - stu[3].name = s4n; stu[3].studentID = s4i; stu[3].sex = s4s; - repairReport = r; - breakdown = bd; - }//读入文件信息时使用的设置信息函数 - void saveRoom(ofstream &o) { - o << roomNumber << endl; - o << stu[0].name << " " << stu[0].sex << " " << stu[0].studentID << endl; - o << stu[1].name << " " << stu[1].sex << " " << stu[1].studentID << endl; - o << stu[2].name << " " << stu[2].sex << " " << stu[2].studentID << endl; - o << stu[3].name << " " << stu[3].sex << " " << stu[3].studentID << endl; - o << repairReport << " " << breakdown << endl; - }//写入单一(本)宿舍信息的函数,在存储宿舍时由Dormitory对象中saveRoom函数调用 - string sendinfo() { - string s;//临时变量 - s = "寝室号:" + roomNumber + "\n"; - s = s + "学号:" + stu[0].studentID + " 姓名:" + stu[0].name + " 性别:" + stu[0].sex + "\n"; - s = s + "学号:" + stu[1].studentID + " 姓名:" + stu[1].name + " 性别:" + stu[1].sex + "\n"; - s = s + "学号:" + stu[2].studentID + " 姓名:" + stu[2].name + " 性别:" + stu[2].sex + "\n"; - s = s + "学号:" + stu[3].studentID + " 姓名:" + stu[3].name + " 性别:" + stu[3].sex + "\n"; - s = s + "报修状况:"; - if (repairReport == true) { - s = s + breakdown+"\n"; - }//当本寝室有报修时,输出具体报修内容 - else - { - s = s + "未报修\n"; - }//当本寝室尚未报修时,输入未报修 - return s; - }//与Student类searcheRoom方法协作,输出本寝室信息 - int judgeEmpty() { - for (int i = 0; i < 4; i++) { - if (stu[i].name == "未入住") { - return 1; - }//当本寝室有床位为未入住状态时表示本寝室尚有空余 - } - return 0; - }//判断寝室是否尚有空余 -}; \ No newline at end of file diff --git a/src/婧.cpp b/src/婧.cpp deleted file mode 100644 index 25a7ec8..0000000 --- a/src/婧.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "menu.h" - -using namespace std; - -void main() { - vector s;//读入容器 - vector d;//宿舍容器 - vector a;//管理员容器 - readStudent(s);//读入学生信息 - readDormitory(d);//读入宿舍信息 - readAdministrator(a);//读入管理员信息 - show(s, d, a);//展示功能 - saveAdministrator(a);//保存管理员信息 - saveStudent(s);//保存学生信息 - saveDormitory(d);//保存宿舍信息 -} \ No newline at end of file