You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.2 KiB

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
struct Student {
int id;
std::string name;
std::string gender;
int age;
std::string major;
};
class StudentManagementSystem {
public:
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
std::vector<Student> students;
void addStudent(const Student& s) {
students.push_back(s);
}
// <20><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ
void searchStudent(int id) {
bool found = false;
for (const Student& s : students) {
if (s.id == id) {
std::cout << "ѧ<EFBFBD>ţ<EFBFBD>" << s.id << ", <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << s.name << ", <20>Ա<EFBFBD><D4B1><EFBFBD>" << s.gender << ", <20><><EFBFBD>" << s.age << ", רҵ<D7A8><D2B5>" << s.major << std::endl;
found = true;
break;
}
}
if (!found) {
std::cout << "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ŵ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << std::endl;
}
}
// ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
void deleteStudent(int id) {
auto it = students.begin();
while (it != students.end()) {
if (it->id == id) {
it = students.erase(it);
}
else {
++it;
}
}
}
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
void insertStudent(const Student& s) {
students.push_back(s);
}
// <20><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void sortByID() {
std::sort(students.begin(), students.end(), [](const Student& a, const Student& b) {
return a.id < b.id;
});
}
};
int main() {
StudentManagementSystem sms;
// <20><><EFBFBD><EFBFBD>һЩѧ<D0A9><D1A7><EFBFBD><EFBFBD>Ϣ
Student s1 = { 1, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD>", 20, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ" };
Student s2 = { 2, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Ů", 21, "<EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><EFBFBD><EFBFBD>" };
Student s3 = { 3, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD>", 19, "<EFBFBD><EFBFBD>ѧ" };
sms.addStudent(s1);
sms.addStudent(s2);
sms.addStudent(s3);
// <20><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ
sms.searchStudent(2);
// ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
sms.deleteStudent(2);
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
Student s4 = { 4, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Ů", 22, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ" };
sms.insertStudent(s4);
// <20><><EFBFBD><EFBFBD>
sms.sortByID();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>" << std::endl;
for (const Student& s : sms.students) {
std::cout << "ѧ<EFBFBD>ţ<EFBFBD>" << s.id << ", <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << s.name << ", <20>Ա<EFBFBD><D4B1><EFBFBD>" << s.gender << ", <20><><EFBFBD>" << s.age << ", רҵ<D7A8><D2B5>" << s.major << std::endl;
}
return 0;
}