1 /** 2 * 項目名稱:機房預約系統 3 * 時 間:2021-08 4 * 作 者:Bytezero!·zhenglei 5 * 6 * 系統簡介: 7 * 學校有幾個規格不同的機房,由於使用時經常出現“撞車”的現象,開發一套系統,解決這一問題 8 * 身份簡介: 9 * 學生代表:申請使用機房 10 * 教 師:審核學生的預約申請 11 * 管 理 員:給學生,教師創建賬號 12 * 機房簡介: 13 * 1號機房 ----- 最大容量20人 14 * 2號機房 ----- 最多容量50人 15 * 3號機房 ----- 最多容量100人 16 * 申請簡介: 17 * 申請的訂單每周由管理員負責清空 18 * 學生可以預約未來一周機房內的使用,預約的日期周一至周五,預約是需要選擇預約時段(上午,下午) 19 * 教師來審核預約,依據實際情況審核預約通過或者不通過 20 * 系統具體需求: 21 * 首先進入登錄界面,可選擇登錄身份有: 22 * 學生代表 23 * 老師 24 * 管理員 25 * 退出 26 * 每個身份都需要進行驗證后,進入子菜單 27 * 學生需要輸入:學號,姓名,登錄密碼 28 * 老師需要輸入:職工號,姓名,登錄密碼 29 * 管理需要輸入:管理員姓名,登錄密碼 30 * 學生具體功能 31 * 申請預約 ------ 預約機房 32 * 查看自身預約 ----- 查看自己的預約狀態 33 * 查看所有預約 ----- 查看全部預約信息以及預約狀態 34 * 取消預約 ----- 取消自身預約,預約成功或審核中的預約均可以取消 35 * 36 * 教師具體功能 37 * 查看所有預約 ----- 查看全部預約信息以及預約狀態 38 * 審核預約 ----- 對學生的預約進行審核 39 * 注銷登錄 ----- 退出登錄 40 * 管理員具體功能 41 * 添加賬號 ----- 添加學生或教師的賬號,需要檢測學生編號或教師職工編號是否重復 42 * 查看賬號 ----- 可以選擇查看學生或教師的全部信息 43 * 查看機房 ----- 查看所有機房的信息 44 * 清空預約 ----- 清空所有預約記錄 45 * 注銷登錄 ----- 退出登錄 46 * 47 **/
//運行界面
1 ComputerizedRoomReservationSystem.cpp 2 #include<iostream> 3 #include"Identity.h" 4 #include<fstream> 5 #include<string> 6 #include"global.h" 7 #include"manager.h" 8 #include"teacher.h" 9 #include"student.h" 10 using namespace std; 11 12 13 14 15 16 17 //進入學生子菜單界面 18 void studentMenu(Identity * &student) 19 { 20 while (true) 21 { 22 //調用學生子菜單 23 student->operMenu(); 24 25 Student* stu = (Student*)student; 26 27 int select = 0; 28 cin >> select; //接收用戶的選擇 29 30 if (select == 1) //申請預約 31 { 32 stu->applyOrder(); 33 34 } 35 else if (select == 2)//查看自身預約 36 { 37 stu->showMyOrder(); 38 } 39 else if (select == 3) //查看所有人預約 40 { 41 stu->showAllOrder(); 42 } 43 else if (select == 4) //取消預約 44 { 45 stu->cancelOrder(); 46 } 47 else 48 { 49 //注銷登錄 50 delete student; 51 cout << "注銷成功!" << endl; 52 system("pause"); 53 system("cls"); 54 55 return; 56 57 } 58 59 } 60 } 61 62 //進入教師子菜單界面 63 void teacherMenu(Identity*& teacher) 64 { 65 while (true) 66 { 67 //調用子菜單界面 68 teacher->operMenu(); 69 70 Teacher* tea = (Teacher*)teacher; 71 72 int select = 0; //接收用戶選擇 73 74 cin >> select; 75 if (select == 1) //查看所有預約 76 { 77 tea->showAllOrder(); 78 } 79 else if (select == 2) //審核預約 80 { 81 tea->validOrder(); 82 } 83 else 84 { 85 delete teacher; 86 cout << "注銷成功!!" << endl; 87 system("pause"); 88 system("cls"); 89 break; 90 } 91 } 92 } 93 94 95 96 97 98 99 100 101 102 103 104 //進入管理員的子菜單 105 void managerMenu(Identity*& manager) 106 { 107 while (true) 108 { 109 //調用管理員子菜單 110 manager->operMenu(); 111 112 //將父類指針轉換為 子類的指針 調用子類其他接口 113 Manager* man = (Manager*)manager; 114 115 int select = 0; 116 //接收用戶的選擇 117 cin >> select; 118 119 if (select == 1) 120 { 121 //添加賬號 122 cout << "添加賬號" << endl; 123 man->addPerson(); 124 125 } 126 else if (select == 2) //查看賬號 127 { 128 cout << "查看賬號" << endl; 129 man->showPerson(); 130 } 131 else if (select == 3) //查看機房信息 132 { 133 cout << "查看機房" << endl; 134 man->showComputer(); 135 } 136 else if (select == 4)//清空預約 137 { 138 cout << "清空預約" << endl; 139 man->cleanFile(); 140 } 141 else if (select == 0) //注銷登錄 142 { 143 delete manager; //銷毀堆區對象 144 cout << "注銷成功!" << endl; 145 system("pause"); 146 system("cls"); 147 return; 148 } 149 else //輸入有誤! 150 { 151 cout << "您輸入有誤,請重新輸入!" << endl; 152 system("pause"); 153 system("cls"); 154 155 } 156 157 } 158 } 159 160 //登錄功能 參數1 操做文件名 參數2 操作身份類型 161 void LoginIn(string fileName, int type) 162 { 163 //父類指針 用於 指向子類對象 164 Identity* person = NULL; 165 166 //讀文件 167 ifstream ifs; 168 ifs.open(fileName,ios::in); 169 170 //判斷文件是否存在 171 if (!ifs.is_open()) 172 { 173 cout << "文件不存在!" << endl; 174 ifs.close(); 175 return; 176 } 177 178 //准備接收用戶信息 179 int id = 0; 180 string name; 181 string pwd; 182 183 184 //判斷身份 185 if (type == 1) //學生身份 186 { 187 cout << "請輸入你的學號:" << endl; 188 cin >> id; 189 } 190 else if (type == 2) //老師身份 191 { 192 cout << "請輸入您的職工號:" << endl; 193 cin >> id; 194 195 } 196 cout << "請輸入用戶名:" << endl; 197 cin >> name; 198 199 cout << "請輸入密碼:" << endl; 200 cin >> pwd; 201 202 if (type == 1) 203 { 204 //學生身份驗證 205 int fId; //從文件中讀取的id號 206 string fName; //從文件中獲取的姓名 207 string fPwd; //從文件中獲取的密碼 208 209 while (ifs >> fId && ifs >> fName && ifs >> fPwd ) 210 { 211 //cout << fId << endl; 212 //cout << fName << endl; 213 //cout << fPwd << endl; 214 //cout << endl; 215 //與用戶輸入的信息做對比 216 if (id == fId && name == fName && pwd == fPwd) 217 { 218 cout << "學生驗證登錄成功!" << endl; 219 system("pause"); 220 system("cls"); 221 222 person = new Student(id,name,pwd); 223 224 //進入學生身份的子菜單 225 studentMenu(person); 226 227 228 return; 229 } 230 231 232 } 233 234 235 } 236 else if (type == 2) 237 { 238 //教師身份驗證 239 int fId; 240 string fName; 241 string fPwd; 242 243 while (ifs>>fId && ifs>>fName&&ifs>>fPwd) 244 { 245 if (fId == id && fName == name && fPwd == pwd) 246 { 247 cout << "教師登錄驗證成功!" << endl; 248 system("pause"); 249 system("cls"); 250 251 person = new Teacher(id, name, pwd); 252 253 //進入教師子菜單 254 teacherMenu(person); 255 return; 256 257 } 258 259 260 261 } 262 263 264 265 266 } 267 else if (type == 3) 268 { 269 //管理員身份驗證 270 string fName; 271 string fPwd; 272 while (ifs >> fName && ifs>>fPwd) 273 { 274 if (name == fName && pwd == fPwd) 275 { 276 cout << "管理員登錄驗證成功!" << endl; 277 system("pause"); 278 system("cls"); 279 280 person = new Manager(name, pwd); 281 282 //進入管理員子菜單 283 managerMenu(person); 284 285 return; 286 } 287 } 288 289 290 291 } 292 293 294 295 cout << "驗證登錄失敗!" << endl; 296 297 system("pause"); 298 system("cls"); 299 300 // return; 301 302 303 304 305 } 306 307 int main() 308 { 309 310 int select = 0; //用於接收用戶的選擇 311 while (true) 312 { 313 cout << "=================================== 歡迎來到(Bytezero!·zhenglei)計算機房預約系統 ===================================" << endl; 314 cout << endl << "親愛的用戶:\n 根據下面提示的信息,請輸入您的身份:\n" << endl; 315 cout << "\t\t\t\t\t --------------------------------\n"; 316 cout << "\t\t\t\t\t| |\n"; 317 cout << "\t\t\t\t\t| 1.學生代表 |\n"; 318 cout << "\t\t\t\t\t| |\n"; 319 cout << "\t\t\t\t\t| 2.老 師 |\n"; 320 cout << "\t\t\t\t\t| |\n"; 321 cout << "\t\t\t\t\t| 3.管 理 員 |\n"; 322 cout << "\t\t\t\t\t| |\n"; 323 cout << "\t\t\t\t\t| 0.退 出 |\n"; 324 cout << "\t\t\t\t\t| |\n"; 325 cout << "\t\t\t\t\t| |\n"; 326 cout << "\t\t\t\t\t --------------------------------\n"; 327 cout << " \n請輸入您的選擇:"; 328 329 cin >> select; //接受用戶的選擇 330 331 switch (select) //根據用戶選擇 實現不同的接口 332 { 333 case 1: //學生身份 334 LoginIn(STUDENT_FILE, 1); 335 break; 336 case 2: //老師身份 337 LoginIn(TEACHER_FILE, 2); 338 break; 339 case 3: //管理員身份 340 LoginIn(ADMIN_FILE,3); 341 break; 342 case 0: //退出系統 343 cout << "\t歡迎下一次使用,再見!" << endl; 344 system("pause"); 345 return 0; 346 break; 347 default: //輸入有誤 348 cout << "輸入有誤,請重新選擇!" << endl; 349 system("pause"); 350 system("cls"); 351 break; 352 } 353 354 } 355 356 357 358 359 360 361 362 363 system("pause"); 364 return 0; 365 }
1 manager.cpp 2 #include"manager.h" 3 4 //默認構造 5 Manager::Manager() 6 { 7 8 } 9 10 //有參構造 11 Manager::Manager(string name, string pwd) 12 { 13 14 //初始化管理員信息 15 this->m_Name = name; 16 this->m_Pwd = pwd; 17 18 //初始化容器 獲取到所有文件中 老師 學生信息 19 this->inttVector(); 20 21 //初始化機房的信息 22 ifstream ifs; 23 ifs.open(COMPUTER_FILE, ios::in); 24 25 ComputerRoon com; 26 while (ifs >> com.m_ComId && ifs >> com.m_MaxNum) 27 { 28 vCom.push_back(com); 29 } 30 ifs.close(); 31 cout << "當前機房的數量為:" << vCom.size() << endl; 32 } 33 34 //菜單構造 35 void Manager::operMenu() 36 { 37 cout << "=============================================== 歡迎管理員:"<<this->m_Name <<" 登錄 =============================================== " << endl; 38 cout << endl << "親愛的用戶:\n 根據下面提示的信息,請輸入您的身份:\n" << endl; 39 cout << "\t\t\t\t\t --------------------------------\n"; 40 cout << "\t\t\t\t\t| |\n"; 41 cout << "\t\t\t\t\t| 1.添加賬號 |\n"; 42 cout << "\t\t\t\t\t| |\n"; 43 cout << "\t\t\t\t\t| 2.查看賬號 |\n"; 44 cout << "\t\t\t\t\t| |\n"; 45 cout << "\t\t\t\t\t| 3.查看機房 |\n"; 46 cout << "\t\t\t\t\t| |\n"; 47 cout << "\t\t\t\t\t| 4.清空預約 |\n"; 48 cout << "\t\t\t\t\t| |\n"; 49 cout << "\t\t\t\t\t| 0.注銷登錄 |\n"; 50 cout << "\t\t\t\t\t| |\n"; 51 cout << "\t\t\t\t\t --------------------------------\n"; 52 cout << " \n請輸入您的選擇:"; 53 } 54 55 //添加賬號 56 void Manager::addPerson() 57 { 58 cout << "請輸入添加的賬號類型:" << endl; 59 cout << "1 --- 添加學生" << endl; 60 cout << "2 --- 添加老師" << endl; 61 62 string fileName; //操作文件名 63 string tip; //提示Id號 64 string errorTip; //重復錯誤提示 65 66 ofstream ofs; //文件操作對象 67 68 int select = 0; 69 cin >> select; //接收用戶的選項 70 while (true) 71 { 72 if (select == 1) 73 { 74 //添加的是學生 75 fileName = STUDENT_FILE; 76 tip = "請輸入學號:"; 77 errorTip = "學號重復,請重新輸入!"; 78 79 } 80 else if (select == 2) 81 { 82 //添加教師 83 fileName = TEACHER_FILE; 84 tip = "請輸入職工號:"; 85 errorTip = "職工號重復,請重新輸入!"; 86 87 } 88 else 89 { 90 cout << "您輸入有誤,請重新輸入!" << endl; 91 system("pause"); 92 system("cls"); 93 return; 94 } 95 96 //利用追加的方式 寫文件 97 ofs.open(fileName, ios::out | ios::app); 98 99 int id; //學號 或者 職工號 100 string name; //姓名 101 string pwd; //密碼 102 103 cout << tip << endl; 104 105 while (true) 106 { 107 cin >> id; 108 bool ret = checkRepeat(id, select); 109 if (ret) //有重復 110 { 111 cout << errorTip << endl; 112 } 113 else 114 { 115 break; 116 } 117 } 118 119 120 121 122 cout << "請輸入姓名:" << endl; 123 cin >> name; 124 125 cout << "請輸入密碼:" << endl; 126 cin >> pwd; 127 128 //文件中添加數據 129 ofs << id << " " << name << " " << pwd << " " << endl; 130 cout << "添加成功!!!" << endl; 131 132 system("pause"); 133 system("cls"); 134 135 ofs.close(); 136 137 //初始化信息 重新獲取文件中的數據 138 this->inttVector(); 139 140 return; 141 142 143 } 144 145 146 147 } 148 //打印學生 149 void printStudent(Student& s) 150 { 151 cout << "學號:" << s.m_Id << "\t姓名:" << s.m_Name << "\t密碼:" << s.m_Pwd << endl; 152 153 } 154 155 //打印老師 156 void printTeacher(Teacher& t) 157 { 158 cout << "職工號:" << t.m_EmpId << "\t姓名:" << t.m_Name << "\t密碼:" << t.m_Pwd << endl; 159 160 } 161 162 //查看賬號 163 void Manager::showPerson() 164 { 165 cout << "請選擇查看的內容:" << endl; 166 cout << "1 --- 查看所有的學生" << endl; 167 cout << "2 --- 查看所有的老師" << endl; 168 169 int select = 0; //接收用戶的選擇 170 171 cin >> select; 172 if (select == 1) 173 { 174 //查看學生 175 cout << "查看所有學生信息如下:" << endl; 176 for_each(vStu.begin(), vStu.end(), printStudent); 177 } 178 else 179 { 180 //查看教師 181 cout << "查看所有教師信息如下:" << endl; 182 for_each(vTea.begin(), vTea.end(), printTeacher); 183 } 184 system("pause"); 185 system("cls"); 186 187 } 188 189 190 //查看機房信息 191 void Manager::showComputer() 192 { 193 cout << "機房的信息如下:" << endl; 194 for (vector<ComputerRoon>::iterator it = vCom.begin(); it != vCom.end(); it++) 195 { 196 cout << "機房編號:" << it->m_ComId << "\t機房最大容量:" << it->m_MaxNum << endl; 197 } 198 system("pause"); 199 system("cls"); 200 } 201 202 203 204 205 //清空預約記錄 206 void Manager::cleanFile() 207 { 208 209 cout << "確定要清空嗎?" << endl; 210 cout << "1 --- 確定" << endl; 211 cout << "2 --- 返回" << endl; 212 213 int select = 0; 214 cin >> select; 215 216 if (select == 1) 217 { 218 ofstream ofs(ORDER_FILE, ios::trunc); 219 ofs.close(); 220 cout << "清空成功!" << endl; 221 system("pause"); 222 system("cls"); 223 224 } 225 else if (select == 2) 226 { 227 228 system("pause"); 229 system("cls"); 230 return; 231 } 232 else 233 { 234 cout << "輸入有誤,請重新輸入!" << endl; 235 system("pause"); 236 system("cls"); 237 return; 238 } 239 240 } 241 242 //初始化容器 243 void Manager::inttVector() 244 { 245 //確保容器清空狀態 246 vStu.clear(); 247 vTea.clear(); 248 249 //讀取信息 學生 250 ifstream ifs; 251 ifs.open(STUDENT_FILE, ios::in); 252 if (!ifs.is_open()) 253 { 254 cout << "文件讀取失敗!" << endl; 255 return; 256 } 257 258 Student s; 259 while (ifs>>s.m_Id&&ifs>>s.m_Name&&ifs>>s.m_Pwd) 260 { 261 vStu.push_back(s); 262 } 263 cout << "當前學生數量為:" << vStu.size() << endl; 264 ifs.close(); 265 266 //讀取信息 老師 267 ifs.open(TEACHER_FILE, ios::in); 268 Teacher t; 269 while (ifs >> t.m_EmpId && ifs >> t.m_Name && ifs >> t.m_Pwd) 270 { 271 vTea.push_back(t); 272 } 273 274 cout << "當前老師數量為:" << vTea.size() << endl; 275 ifs.close(); 276 277 278 279 } 280 281 //檢測重復 參數1 檢測 學號/職工號 參數2 檢測類型 282 bool Manager::checkRepeat(int id, int type) 283 { 284 if (type == 1) 285 { 286 //檢測學生 287 for (vector<Student>::iterator it = vStu.begin(); it != vStu.end(); it++) 288 { 289 if (id == it->m_Id) 290 { 291 return true; 292 } 293 } 294 } 295 else 296 { 297 //檢測老師 298 for (vector<Teacher>::iterator it = vTea.begin(); it != vTea.end(); it++) 299 { 300 if (id == it->m_EmpId) 301 { 302 return true; 303 } 304 } 305 306 } 307 308 return false; 309 }
1 orderFile.cpp 2 #include"orderFile.h" 3 4 5 //構造函數 6 OrderFile::OrderFile() 7 { 8 ifstream ifs; 9 ifs.open(ORDER_FILE, ios::in); 10 11 string date; //日期 12 string interval; //時間段 13 string stuId; //學生編號 14 string stuName; //學生姓名 15 string roomId; //機房編號 16 string status; //預約狀態 17 18 this->m_Size = 0; //記錄條數 19 20 while (ifs >> date && ifs >> interval && ifs 21 >> stuId && ifs >> stuName && ifs 22 >> roomId && ifs >> status) 23 { 24 //cout << date << endl; 25 //cout << interval << endl; 26 //cout << stuId<< endl; 27 //cout << stuName << endl; 28 //cout << roomId << endl; 29 //cout << status << endl; 30 31 32 33 //date : 1 34 35 string key; 36 string value; 37 map<string, string>m; 38 39 //cout << date << endl; 40 //截取日期 41 int pos = date.find(":"); // 4 42 if (pos != -1) 43 { 44 key = date.substr(0, pos); 45 value = date.substr(pos + 1, date.size() - pos - 1); //size = 9 pos = 4 size-pos = 5 46 47 m.insert(make_pair(key, value)); 48 49 } 50 51 //cout << "key = " << key << endl; 52 //cout << "value = " << value << endl; 53 54 //cout << interval << endl; 55 //截取時間段 56 pos = interval.find(":"); // 4 57 if (pos != -1) 58 { 59 key = interval.substr(0, pos); 60 value = interval.substr(pos + 1, interval.size() - pos - 1); //size = 9 pos = 4 size-pos = 5 61 62 m.insert(make_pair(key, value)); 63 64 } 65 //cout << stuId<< endl; 66 //截取學生Id 67 pos = stuId.find(":"); // 4 68 if (pos != -1) 69 { 70 key = stuId.substr(0, pos); 71 value = stuId.substr(pos + 1, stuId.size() - pos - 1); //size = 9 pos = 4 size-pos = 5 72 73 m.insert(make_pair(key, value)); 74 75 } 76 77 //cout << stuName << endl; 78 //截取學生姓名 79 pos = stuName.find(":"); // 4 80 if (pos != -1) 81 { 82 key = stuName.substr(0, pos); 83 value = stuName.substr(pos + 1, stuName.size() - pos - 1); //size = 9 pos = 4 size-pos = 5 84 85 m.insert(make_pair(key, value)); 86 87 } 88 89 90 //cout << roomId << endl; 91 //截取機房Id 92 93 pos = roomId.find(":"); // 4 94 if (pos != -1) 95 { 96 key = roomId.substr(0, pos); 97 value = roomId.substr(pos + 1, roomId.size() - pos - 1); //size = 9 pos = 4 size-pos = 5 98 99 m.insert(make_pair(key, value)); 100 101 } 102 103 //cout << status << endl; 104 //截取預約狀態 105 pos = status.find(":"); // 4 106 if (pos != -1) 107 { 108 key = status.substr(0, pos); 109 value = status.substr(pos + 1, status.size() - pos - 1); //size = 9 pos = 4 size-pos = 5 110 111 m.insert(make_pair(key, value)); 112 113 } 114 115 //將小 map 容器 放入 大的 map容器中 116 this->m_orderData.insert(make_pair(this->m_Size, m)); 117 this->m_Size++; 118 119 120 } 121 ifs.close(); 122 123 //測似 最大map容器 124 //for (map<int, map<string, string>>::iterator it = m_orderData.begin(); it != m_orderData.end(); it++) 125 //{ 126 // cout << "條數為: = " << it->first << "\tvalue = " << endl; 127 // for (map<string, string>::iterator mit = (*it).second.begin(); mit != it->second.end(); mit++) 128 // { 129 // cout << " key = " << mit->first << " value = " << mit->second << " "; 130 131 132 // } 133 // cout << endl; 134 //} 135 136 } 137 138 //更新預約記錄 139 void OrderFile::updateOrder() 140 { 141 if (this->m_Size == 0) 142 { 143 return; //預約記錄為條,直接 return 144 } 145 146 ofstream ofs(ORDER_FILE, ios::out | ios::trunc); 147 for (int i = 0; i < this->m_Size; i++) 148 { 149 ofs << "date:" << this->m_orderData[i]["date"] << " "; 150 ofs << "interval:" << this->m_orderData[i]["interval"] << " "; 151 ofs << "stuId:" << this->m_orderData[i]["stuId"] << " "; 152 ofs << "stuName:" << this->m_orderData[i]["stuName"] << " "; 153 ofs << "roomId:" << this->m_orderData[i]["roomId"] << " "; 154 ofs << "status:" << this->m_orderData[i]["status"] << endl; 155 156 157 } 158 ofs.close(); 159 }
1 student.cpp 2 #include"student.h" 3 4 5 //默認構造 6 Student::Student() 7 { 8 9 } 10 11 //有參構造 參數 學號 姓名 密碼 12 Student::Student(int id, string name, string pwd) 13 { 14 //初始化屬性 15 this->m_Id = id; 16 this->m_Name = name; 17 this->m_Pwd = pwd; 18 19 //初始化機房信息 20 ifstream ifs; 21 ifs.open(COMPUTER_FILE, ios::in); 22 23 ComputerRoon com; 24 while (ifs >> com.m_ComId && ifs >> com.m_MaxNum) 25 { 26 //將讀取的信息放入到 容器中 27 vCom.push_back(com); 28 } 29 ifs.close(); 30 } 31 32 33 //菜單界面 34 void Student::operMenu() 35 { 36 cout << "============================================= 歡迎學生用戶:" << this->m_Name << " 登錄 ============================================= " << endl; 37 cout << endl << "親愛的學生用戶:\n 根據下面提示的信息,請輸入您的選擇:\n" << endl; 38 cout << "\t\t\t\t\t --------------------------------\n"; 39 cout << "\t\t\t\t\t| |\n"; 40 cout << "\t\t\t\t\t| 1.申請預約 |\n"; 41 cout << "\t\t\t\t\t| |\n"; 42 cout << "\t\t\t\t\t| 2.查看我的預約 |\n"; 43 cout << "\t\t\t\t\t| |\n"; 44 cout << "\t\t\t\t\t| 3.查看所有預約 |\n"; 45 cout << "\t\t\t\t\t| |\n"; 46 cout << "\t\t\t\t\t| 4.取消預約 |\n"; 47 cout << "\t\t\t\t\t| |\n"; 48 cout << "\t\t\t\t\t| 0.注銷登錄 |\n"; 49 cout << "\t\t\t\t\t| |\n"; 50 cout << "\t\t\t\t\t --------------------------------\n"; 51 cout << " \n請輸入您的選擇:"; 52 } 53 54 55 //申請預約 56 void Student::applyOrder() 57 { 58 cout << "機房開放時間為:周一至周五!" << endl; 59 cout << "請輸入申請預約的時間:" << endl; 60 cout << "1 ··· 周一" << endl; 61 cout << "2 ··· 周二" << endl; 62 cout << "3 ··· 周三" << endl; 63 cout << "4 ··· 周四" << endl; 64 cout << "5 ··· 周五" << endl; 65 66 int date = 0; //日期 67 int interval = 0; //時間段 68 int room = 0; //機房編號 69 70 while (true) 71 { 72 cin >> date; 73 if (date >= 1 && date <= 5) 74 { 75 break; 76 } 77 cout << "輸入日期有誤,請重新輸入" << endl; 78 } 79 80 cout << "請輸入申請預約的時間段:" << endl; 81 cout << "1 --- 上午" << endl; 82 cout << "2 --- 下午" << endl; 83 84 while (true) 85 { 86 cin >> interval; 87 if (interval >= 1 && interval <= 2) 88 { 89 break; 90 } 91 cout << "輸入時間段有誤,請重新輸入" << endl; 92 } 93 94 cout << "請選擇機房:" << endl; 95 for (int i = 0; i < vCom.size(); i++) 96 { 97 cout << vCom[i].m_ComId << "號機房容量為:" << vCom[i].m_MaxNum << endl; 98 99 } 100 101 while (true) 102 { 103 cin >> room; 104 if (room >= 1 && room <= 3) 105 { 106 break; 107 } 108 cout << "機房輸入有誤,請重新輸入!" << endl; 109 } 110 cout << "預約成功,審核中" << endl; 111 112 ofstream ofs; 113 ofs.open(ORDER_FILE,ios::app); 114 115 ofs << "date:" << date << "\t"; 116 ofs << "interval:" << interval << "\t"; 117 ofs << "stuId:" << this->m_Id << "\t"; 118 ofs << "stuName:" << this->m_Name << "\t"; 119 ofs << "roomId:" << date << "\t"; 120 ofs << "status:" << 1 << endl; 121 122 ofs.close(); 123 system("pause"); 124 system("cls"); 125 126 127 } 128 129 //查看自身的預約 130 void Student::showMyOrder() 131 { 132 OrderFile of; 133 if (of.m_Size == 0) 134 { 135 cout << "沒有預約記錄!" << endl; 136 system("pause"); 137 system("cls"); 138 return; 139 } 140 141 for (int i = 0; i < of.m_Size; i++) 142 { 143 //找到自身預約 144 //sting 裝 int 145 //stting 利用 .c_str() 轉 const char * 146 //利用 atoi (const char *)轉 int 147 if (this->m_Id == atoi(of.m_orderData[i]["stuId"].c_str())) 148 { 149 cout << "預約日期:周" << of.m_orderData[i]["date"]; 150 cout << "\t時間段:" << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); 151 cout << "\t機房編號:" << of.m_orderData[i]["roomId"]; 152 string status = "\t狀態:"; 153 //1.審核中 2.已預約 -1 預約失敗 0取消預約 154 if (of.m_orderData[i]["status"] == "1") 155 { 156 status += "審核中"; 157 } 158 else if (of.m_orderData[i]["status"] == "2") 159 { 160 status += "預約成功"; 161 } 162 else if (of.m_orderData[i]["status"] == "3") 163 { 164 status += "預約失敗,審核未通過!"; 165 } 166 else 167 { 168 status += "預約已取消!!"; 169 } 170 cout << status << endl; 171 172 } 173 } 174 system("pause"); 175 system("cls"); 176 177 178 } 179 180 181 //查看所有預約 182 void Student::showAllOrder() 183 { 184 185 OrderFile of; 186 if (of.m_Size == 0) 187 { 188 cout << "無預約記錄!" << endl; 189 190 system("pause"); 191 system("cls"); 192 return; 193 } 194 for (int i = 0; i < of.m_Size; i++) 195 { 196 cout << i + 1 << "、"; 197 cout << "預約的日期: 周" << of.m_orderData[i]["date"]; 198 cout << "\t時間段:" << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); 199 cout << "\t學號:" << of.m_orderData[i]["stuId"]; 200 cout << "\t姓名:" << of.m_orderData[i]["stuName"]; 201 cout << "\t機房編號:" << of.m_orderData[i]["roomId"]; 202 string status = "狀態:"; 203 204 //1. 審核中 2.已預約 -1預約失敗 0取消預約 205 if (of.m_orderData[i]["status"] == "1") 206 { 207 status += "審核中"; 208 } 209 else if (of.m_orderData[i]["status"] == "2") 210 { 211 status += "預約成功!"; 212 } 213 else if (of.m_orderData[i]["status"] == "-1") 214 { 215 status += "預約失敗,審核未通過!"; 216 } 217 else 218 { 219 status += "預約已取消!!"; 220 } 221 cout << status << endl; 222 } 223 system("pause"); 224 system("cls"); 225 226 227 } 228 229 230 //取消預約 231 void Student::cancelOrder() 232 { 233 OrderFile of; 234 if (of.m_Size == 0) 235 { 236 cout << "無預約記錄" << endl; 237 system("pause"); 238 system("cls"); 239 return; 240 } 241 cout << "審核中或者預約成功的記錄可以取消,請輸入取消的記錄" << endl; 242 vector<int>v; //存放在最大容器中的下標編號 243 int index = 1; 244 for (int i = 0; i < of.m_Size; i++) 245 { 246 //判斷是自身的學號 247 if (this->m_Id == atoi(of.m_orderData[i]["stuId"].c_str())) 248 { 249 //再篩選狀態 審核中 或者 預約成功 250 if (of.m_orderData[i]["status"] == "1" || of.m_orderData[i]["stuId"] == "2") 251 { 252 v.push_back(i); 253 cout << index++ << "、 "; 254 cout << "預約日期: 周" << of.m_orderData[i]["date"]; 255 cout << "\t時間段:" << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); 256 cout << "\t機房編號:" << of.m_orderData[i]["roomId"]; 257 258 string status = "狀態:"; 259 if (of.m_orderData[i]["status"] == "1") 260 { 261 status += "審核中"; 262 } 263 else if (of.m_orderData[i]["status"] == "2") 264 { 265 status += "預約成功!"; 266 } 267 cout << status<<endl; 268 269 270 } 271 272 273 } 274 } 275 276 cout << "請輸入取消的記錄,0代表返回" << endl; 277 int select = 0; 278 while (true) 279 { 280 cin >> select; 281 if (select >= 0 && select <= v.size()) 282 { 283 if (select == 0) 284 { 285 break; 286 } 287 else 288 { 289 of.m_orderData[v[select - 1]]["status"] = "0"; 290 291 of.updateOrder(); 292 293 cout << "已取消預約!!" << endl; 294 break; 295 296 } 297 298 } 299 300 cout << "輸入有誤,重新輸入!" << endl; 301 } 302 303 system("pause"); 304 system("cls"); 305 }
1 teacher.cpp 2 #include"teacher.h" 3 4 5 //默認構造 6 Teacher::Teacher() 7 { 8 9 } 10 11 12 //有參構造 13 Teacher::Teacher(int empId, string name, string pwd) 14 { 15 //初始化屬性 16 this->m_EmpId = empId; 17 this->m_Name = name; 18 this->m_Pwd = pwd; 19 20 } 21 22 //菜單界面 23 void Teacher::operMenu() 24 { 25 cout << "============================================= 歡迎教師用戶:" << this->m_Name << " 登錄 ============================================= " << endl; 26 cout << endl << "親愛的教師用戶:\n 根據下面提示的信息,請輸入您的選擇:\n" << endl; 27 cout << "\t\t\t\t\t --------------------------------\n"; 28 cout << "\t\t\t\t\t| |\n"; 29 cout << "\t\t\t\t\t| 1.查看所有預約 |\n"; 30 cout << "\t\t\t\t\t| |\n"; 31 cout << "\t\t\t\t\t| |\n"; 32 cout << "\t\t\t\t\t| |\n"; 33 cout << "\t\t\t\t\t| 2.審核預約 |\n"; 34 cout << "\t\t\t\t\t| |\n"; 35 cout << "\t\t\t\t\t| |\n"; 36 cout << "\t\t\t\t\t| |\n"; 37 cout << "\t\t\t\t\t| 0.注銷登錄 |\n"; 38 cout << "\t\t\t\t\t| |\n"; 39 cout << "\t\t\t\t\t --------------------------------\n"; 40 cout << " \n請輸入您的選擇:"; 41 } 42 43 44 //查看所有預約 45 void Teacher::showAllOrder() 46 { 47 OrderFile of; 48 if (of.m_Size == 0) 49 { 50 cout << "無預約記錄!" << endl; 51 system("pause"); 52 system("cls"); 53 return; 54 } 55 for (int i = 0; i < of.m_Size; i++) 56 { 57 cout << i + 1 << "、 "; 58 cout << "預約日期:周" << of.m_orderData[i]["date"]; 59 cout << "\t時間段:" << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); 60 cout << "\t學號:" << of.m_orderData[i]["stuId"]; 61 cout << "\t姓名:" << of.m_orderData[i]["stuName"]; 62 cout << "\t機房編號:" << of.m_orderData[i]["roomId"]; 63 64 string status = "\t狀態: "; 65 //1 審核中 2已預約 -1預約失敗 0取消預約 66 if (of.m_orderData[i]["status"] == "1") 67 { 68 status += "審核中"; 69 } 70 else if (of.m_orderData[i]["status"] == "2") 71 { 72 status += "預約成功!!"; 73 } 74 else if (of.m_orderData[i]["status"] == "-1") 75 { 76 status += "預約失敗,審核未通過!!"; 77 } 78 else 79 { 80 status += "預約已經取消!!"; 81 } 82 cout << status << endl; 83 84 } 85 system("pause"); 86 system("cls"); 87 } 88 89 //審核預約 90 void Teacher::validOrder() 91 { 92 OrderFile of; 93 if (of.m_Size == 0) 94 { 95 cout << "無預約記錄" << endl; 96 system("pause"); 97 system("cls"); 98 99 return; 100 } 101 102 vector<int>v; 103 int index = 0; 104 cout << "待審核的預約記錄如下:" << endl; 105 106 for (int i = 0; i < of.m_Size; i++) 107 { 108 if (of.m_orderData[i]["status"] == "1") 109 { 110 v.push_back(i); 111 cout << ++index << " 、"; 112 cout << "預約日期:周" << of.m_orderData[i]["date"]; 113 cout << "\t時間段:" << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); 114 cout << "\t學生編號:" << of.m_orderData[i]["stuId"]; 115 cout << "\t學生姓名:" << of.m_orderData[i]["stuName"]; 116 cout << "\t機房編號:" << of.m_orderData[i]["roomId"]; 117 118 string status = "\t狀態:審核中!!!"; 119 120 cout << status << endl; 121 122 } 123 } 124 125 cout << "請輸入審核的預約記錄: 0代表返回!" << endl; 126 int select = 0; //接收用戶選擇的預約記錄 127 int ret = 0; //接收預約結果記錄 128 129 while (true) 130 { 131 cin >> select; 132 if (select >= 0 && select <= v.size()) 133 { 134 if (select == 0) 135 { 136 break; 137 } 138 else 139 { 140 cout << "請輸入審核結果:" << endl; 141 cout << "1、通過" << endl; 142 cout << "2、不通過" << endl; 143 cin >> ret; 144 if (ret == 1) 145 { 146 //通過 147 of.m_orderData[v[select - 1]]["status"] = "2"; 148 } 149 else 150 { 151 //不通過 152 of.m_orderData[v[select - 1]]["status"] = "-1"; 153 154 } 155 of.updateOrder(); //更新預約記錄 156 cout << "審核完畢!!!" << endl; 157 break; 158 } 159 160 } 161 cout << "輸入有誤,請重新輸入!!" << endl; 162 } 163 system("pasue"); 164 system("cls"); 165 }
1 computerRoom.h 2 #pragma once 3 #include <iostream> 4 using namespace std; 5 6 //機房類 7 class ComputerRoon 8 { 9 public: 10 11 12 int m_ComId; //機房id號 13 14 int m_MaxNum; //機房最大容量 15 }; 16 17 18 19 20 21 22 23 global.h 24 #pragma once 25 26 //管理員文件 27 #define ADMIN_FILE "admin.txt" 28 29 //學生文件 30 #define STUDENT_FILE "student.txt" 31 32 //教師文件 33 #define TEACHER_FILE "teacher.txt" 34 35 //機房信息文件 36 #define COMPUTER_FILE "computer.txt" 37 38 //訂單文件 39 #define ORDER_FILE "order.txt" 40 41 42 43 44 45 46 Identity.h 47 #pragma once 48 #include<iostream> 49 50 using namespace std; 51 52 //身份抽象類 53 class Identity 54 { 55 public: 56 57 //操作菜單 純虛函數 58 virtual void operMenu() = 0; 59 60 61 //用戶名 62 string m_Name; 63 64 65 //密碼 66 string m_Pwd; 67 68 }; 69 70 71 72 73 74 75 manager.h 76 #pragma once 77 78 #include<iostream> 79 using namespace std; 80 #include"Identity.h" 81 #include<string> 82 #include<fstream> 83 #include"global.h" 84 #include<vector> 85 #include"student.h" 86 #include"teacher.h" 87 #include<algorithm> 88 #include"computerRoom.h" 89 90 //管理員的類 91 class Manager:public Identity 92 { 93 public: 94 95 //默認構造 96 Manager(); 97 98 //有參構造 99 Manager(string name,string pwd); 100 101 //菜單構造 102 virtual void operMenu(); 103 104 //添加賬號 105 void addPerson(); 106 107 //查看賬號 108 void showPerson(); 109 110 111 //查看機房信息 112 void showComputer(); 113 114 //清空預約記錄 115 void cleanFile(); 116 117 //初始化容器 118 void inttVector(); 119 120 //檢測重復 參數1 檢測 學號/職工號 參數2 檢測類型 121 bool checkRepeat(int id, int type); 122 123 //學生容器 124 vector<Student>vStu; 125 126 //教師容器 127 vector<Teacher>vTea; 128 129 //機房信息 130 vector<ComputerRoon>vCom; 131 132 133 }; 134 135 136 137 138 139 140 141 142 143 144 orderFile.h 145 #pragma once 146 #include<iostream> 147 using namespace std; 148 #include"global.h" 149 #include<fstream> 150 #include<map> 151 #include<string> 152 153 class OrderFile 154 { 155 156 public: 157 158 //構造函數 159 OrderFile(); 160 161 //更新預約記錄 162 void updateOrder(); 163 164 //記錄預約條數 165 int m_Size; 166 167 //記錄所有預約信息的容器 key記錄條數 value具體記錄 鍵值對信息 168 map<int, map<string, string>>m_orderData; 169 170 171 172 }; 173 174 175 176 177 178 179 student.h 180 #pragma once 181 #include<iostream> 182 using namespace std; 183 #include"Identity.h" 184 #include<vector> 185 #include"computerRoom.h" 186 #include<fstream> 187 #include"global.h" 188 #include"orderFile.h" 189 190 191 //學生類 192 class Student :public Identity 193 { 194 public: 195 196 //默認構造 197 Student(); 198 199 //有參構造 參數 學號 姓名 密碼 200 Student(int id, string name, string pwd); 201 202 203 //菜單界面 204 virtual void operMenu(); 205 206 207 //申請預約 208 void applyOrder(); 209 210 //查看自身的預約 211 void showMyOrder(); 212 213 214 //查看所有預約 215 void showAllOrder(); 216 217 218 //取消預約 219 void cancelOrder(); 220 221 //學生學號 222 int m_Id; 223 224 //機房容器 225 vector<ComputerRoon>vCom; 226 227 228 }; 229 230 231 232 233 234 235 236 teacher.h 237 238 #pragma once 239 #include<iostream> 240 using namespace std; 241 #include"Identity.h" 242 #include"orderFile.h" 243 #include<vector> 244 245 246 //老師類 247 class Teacher :public Identity 248 { 249 public: 250 251 //默認構造 252 Teacher(); 253 254 255 //有參構造 256 Teacher(int empId, string name, string pwd); 257 258 //菜單界面 259 virtual void operMenu(); 260 261 262 //查看所有預約 263 void showAllOrder(); 264 265 //審核預約 266 void validOrder(); 267 268 269 270 //職工號 271 int m_EmpId; 272 273 274 };
//后台給出管理員的 用戶名和密碼 +登錄 (如果添加相同Id,會提示添加失敗)
3.管理員 登錄錯誤
管理員登錄正確
並進入下一頁
可以添加賬號 老師 和 學生
//添加學生
//顯示學生賬號 沒有會有提示
//注冊教師賬號+顯示
3.機房信息
0.注銷登錄
1.學生登錄
0
//申請
//2查看
3查看所有
4.取消預約
0.注銷登錄
3.教師登錄
登錄教師子界面
//查看預約
2審核預約
//通過 (結果老師 學生 均可看見)
//學生角度
//不通過
//學生角度