|
|
@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
#include<iostream>
|
|
|
|
|
|
|
|
#include<vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Student {
|
|
|
|
|
|
|
|
string name;
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Room {
|
|
|
|
|
|
|
|
vector<Student> students;
|
|
|
|
|
|
|
|
int roomNumber;
|
|
|
|
|
|
|
|
vector<string> facilities; // 设施列表
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct InspectionResult {
|
|
|
|
|
|
|
|
Room* room;
|
|
|
|
|
|
|
|
string result; // 检查结果
|
|
|
|
|
|
|
|
string feedback; // 反馈意见
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class DormitoryManagementSystem {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void studentManagement() {
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
|
|
|
cout << "1. 添加学生\n2. 删除学生\n3. 查看所有学生\n";
|
|
|
|
|
|
|
|
cin >> choice;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (choice) {
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
|
|
|
|
Student s;
|
|
|
|
|
|
|
|
cout << "请输入学生姓名和学号:\n";
|
|
|
|
|
|
|
|
cin >> s.name >> s.id;
|
|
|
|
|
|
|
|
students.push_back(s);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
|
|
|
|
if (!students.empty()) {
|
|
|
|
|
|
|
|
cout << "请选择要删除的学生编号(1- " << students.size() << "):" << endl;
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
cin >> index;
|
|
|
|
|
|
|
|
if (index > 0 && index <= students.size()) {
|
|
|
|
|
|
|
|
students.erase(students.begin() + index - 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cout << "无效的选择!" << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cout << "没有学生信息可供管理!" << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3: {
|
|
|
|
|
|
|
|
for (Student s : students) {
|
|
|
|
|
|
|
|
cout << "姓名:" << s.name << ", 学号:" << s.id << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void roomAllocation() {
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
|
|
|
cout << "1. 分配宿舍\n2. 取消分配宿舍\n3. 查看所有宿舍\n";
|
|
|
|
|
|
|
|
cin >> choice;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (choice) {
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
|
|
|
|
Student s;
|
|
|
|
|
|
|
|
int roomNum;
|
|
|
|
|
|
|
|
cout << "请输入学生姓名或学号和要分配的宿舍号:\n";
|
|
|
|
|
|
|
|
cin >> s.name >> roomNum;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 找到学生
|
|
|
|
|
|
|
|
for (auto it = students.begin(); it != students.end(); ++it) {
|
|
|
|
|
|
|
|
if ((*it).name == s.name || (*it).id == roomNum) {
|
|
|
|
|
|
|
|
s = *it;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 找到空宿舍
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (Room r : rooms) {
|
|
|
|
|
|
|
|
if (r.students.size() < 4) { // 假设每个宿舍住4人
|
|
|
|
|
|
|
|
r.students.push_back(s);
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
|
|
|
cout << "没有空闲宿舍。\n";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cout << "已将学生" << s.name << "分配至宿舍" << roomNum << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
|
|
|
|
//...
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3: {
|
|
|
|
|
|
|
|
for (Room r : rooms) {
|
|
|
|
|
|
|
|
cout << "宿舍号:" << r.roomNumber << ", 居住学生:\n";
|
|
|
|
|
|
|
|
for (Student s : r.students) {
|
|
|
|
|
|
|
|
cout << "姓名:" << s.name << ", 学号:" << s.id << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void roomInspection() {
|
|
|
|
|
|
|
|
int roomNum;
|
|
|
|
|
|
|
|
cout << "请输入要进行卫生检查的宿舍号:\n";
|
|
|
|
|
|
|
|
cin >> roomNum;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 找到宿舍
|
|
|
|
|
|
|
|
Room* targetRoom = nullptr;
|
|
|
|
|
|
|
|
for (Room& r : rooms) {
|
|
|
|
|
|
|
|
if (r.roomNumber == roomNum) {
|
|
|
|
|
|
|
|
targetRoom = &r;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetRoom == nullptr) {
|
|
|
|
|
|
|
|
cout << "未找到该宿舍信息!" << endl;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 进行卫生检查
|
|
|
|
|
|
|
|
string result;
|
|
|
|
|
|
|
|
cout << "请输入检查结果(如“干净”、“不干净”等):\n";
|
|
|
|
|
|
|
|
cin >> result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 记录检查结果
|
|
|
|
|
|
|
|
inspections.push_back({ targetRoom, result });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通知学生
|
|
|
|
|
|
|
|
cout << "检查结果已记录,并通知了相关学生。\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void facilityManagement() {
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
|
|
|
cout << "1. 添加设施\n2. 移除设施\n3. 查看所有设施\n";
|
|
|
|
|
|
|
|
cin >> choice;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (choice) {
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
|
|
|
|
int roomNum;
|
|
|
|
|
|
|
|
string facility;
|
|
|
|
|
|
|
|
cout << "请输入要添加设施的宿舍号和设施名称:\n";
|
|
|
|
|
|
|
|
cin >> roomNum >> facility;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 找到宿舍
|
|
|
|
|
|
|
|
Room* targetRoom = nullptr;
|
|
|
|
|
|
|
|
for (Room& r : rooms) {
|
|
|
|
|
|
|
|
if (r.roomNumber == roomNum) {
|
|
|
|
|
|
|
|
targetRoom = &r;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetRoom == nullptr) {
|
|
|
|
|
|
|
|
cout << "未找到该宿舍信息!" << endl;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加设施
|
|
|
|
|
|
|
|
targetRoom->facilities.push_back(facility);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "已成功为宿舍" << roomNum << "添加设施" << facility << endl;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
|
|
|
|
//...
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3: {
|
|
|
|
|
|
|
|
for (Room r : rooms) {
|
|
|
|
|
|
|
|
cout << "宿舍号:" << r.roomNumber << ", 设施:\n";
|
|
|
|
|
|
|
|
for (string facility : r.facilities) {
|
|
|
|
|
|
|
|
cout << facility << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
vector<Student> students;
|
|
|
|
|
|
|
|
vector<Room> rooms;
|
|
|
|
|
|
|
|
vector<InspectionResult> inspections;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
DormitoryManagementSystem system;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
cout << "1. 学生信息管理\n2. 宿舍分配管理\n3. 宿舍卫生检查\n4. 宿舍设施管理\n5. 退出\n";
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
|
|
|
cin >> choice;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (choice) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
system.studentManagement();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
system.roomAllocation();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
system.roomInspection();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
system.facilityManagement();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|