#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
struct Student {
std::string name;
int id;
int age;
std::string grade;
std::string classNumber;
};
class StudentManagementSystem {
private:
std::vector<Student> students;
auto findStudent(int id) -> decltype(students.begin()) {
return std::find_if(students.begin(), students.end(),
[&](const Student& student) { return student.id == id; });
}
auto findStudentByName(const std::string& name) -> decltype(students.begin()) {
return std::find_if(students.begin(), students.end(),
[&](const Student& student) { return student.name == name; });
}
public:
void addStudent(const Student& student) {
students.push_back(student);
}
bool deleteStudent(int id) {
auto it = findStudent(id);
if (it != students.end()) {
students.erase(it);
return true;
}
return false;
}
bool deleteStudentByName(const std::string& name) {
auto it = findStudentByName(name);
if (it != students.end()) {
students.erase(it);
return true;
}
return false;
}
void setBackgroundBlue() {
std::cout << "\033[44m";
}
void displayStudents() const {
for (const auto& student : students) {
std::cout << "姓名: " << student.name << ", 学号: " << student.id << ", 年龄: " << student.age
<< ", 年级: " << student.grade << ", 班级: " << student.classNumber << std::endl;
}
}
void saveToFile(const std::string& filename) c
学生管理系统(C++)
于 2024-11-02 12:56:41 首次发布