From f5ee4a5cb85ccc8fb6b1e26c213af7bb4406619e Mon Sep 17 00:00:00 2001 From: robert <6708314@qq.com> Date: Thu, 1 Sep 2022 17:43:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Administrator.h | 73 ++++++ src/Dormitory.h | 419 ++++++++++++++++++++++++++++++++++ src/Student.h | 77 +++++++ src/menu.h | 532 ++++++++++++++++++++++++++++++++++++++++++++ src/room.h | 63 ++++++ src/源.cpp | 17 ++ 6 files changed, 1181 insertions(+) create mode 100644 src/Administrator.h create mode 100644 src/Dormitory.h create mode 100644 src/Student.h create mode 100644 src/menu.h create mode 100644 src/room.h create mode 100644 src/源.cpp diff --git a/src/Administrator.h b/src/Administrator.h new file mode 100644 index 0000000..d27446d --- /dev/null +++ b/src/Administrator.h @@ -0,0 +1,73 @@ +#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 new file mode 100644 index 0000000..848bf74 --- /dev/null +++ b/src/Dormitory.h @@ -0,0 +1,419 @@ +#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;//ǰλ,λûмʾ¥һλҺ4174һλ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 new file mode 100644 index 0000000..3ae8e00 --- /dev/null +++ b/src/Student.h @@ -0,0 +1,77 @@ +#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; + }//¥ŲΪʱʾ + }//ѯѧѧѧijһѧѧͬʱ + }//βѯѧиѧϢ + 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 new file mode 100644 index 0000000..1a7d9b8 --- /dev/null +++ b/src/menu.h @@ -0,0 +1,532 @@ +#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 << "ѡIJ:"; + 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 << "ѡIJ"; + 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 << "ѡIJ"; + 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 << "޸ijɹ" << 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 << "޸ijɹ" << 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 << "޸ijɹ" << 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 new file mode 100644 index 0000000..3009c2a --- /dev/null +++ b/src/room.h @@ -0,0 +1,63 @@ +#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; + }//д뵥һϢĺڴ洢ʱDormitorysaveRoom + 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; + }//StudentsearcheRoomЭϢ + 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 new file mode 100644 index 0000000..25a7ec8 --- /dev/null +++ b/src/源.cpp @@ -0,0 +1,17 @@ +#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