#include <iostream>
#include <string>
using namespace std;

const int MAX_STUDENTS = 100;

struct Student {
    int id;
    string name;
    int age;
};

Student students[MAX_STUDENTS];
int studentCount = 0;

// 创建学生
void createStudent(int id, const string& name, int age) {
    if (studentCount >= MAX_STUDENTS) {
        cout << "学生数量已达上限！" << endl;
        return;
    }
    students[studentCount++] = {id, name, age};
    cout << "学生添加成功！" << endl;
}

// 读取所有学生
void readStudents() {
    if (studentCount == 0) {
        cout << "暂无学生信息。" << endl;
        return;
    }
    for (int i = 0; i < studentCount; ++i) {
        cout << "ID: " << students[i].id
             << ", 姓名: " << students[i].name
             << ", 年龄: " << students[i].age << endl;
    }
}

// 更新学生信息
void updateStudent(int id, const string& name, int age) {
    for (int i = 0; i < studentCount; ++i) {
        if (students[i].id == id) {
            students[i].name = name;
            students[i].age = age;
            cout << "学生信息更新成功！" << endl;
            return;
        }
    }
    cout << "未找到该ID的学生。" << endl;
}

// 删除学生
void deleteStudent(int id) {
    for (int i = 0; i < studentCount; ++i) {
        if (students[i].id == id) {
            for (int j = i; j < studentCount - 1; ++j) {
                students[j] = students[j + 1];
            }
            --studentCount;
            cout << "学生删除成功！" << endl;
            return;
        }
    }
    cout << "未找到该ID的学生。" << endl;
}

int main() {
    int choice;
    while (true) {
        cout << "\n学生管理系统\n";
        cout << "1. 添加学生\n";
        cout << "2. 查看所有学生\n";
        cout << "3. 更新学生信息\n";
        cout << "4. 删除学生\n";
        cout << "0. 退出\n";
        cout << "请选择操作：";
        cin >> choice;
        if (choice == 0) break;
        if (choice == 1) {
            int id, age;
            string name;
            cout << "输入ID 姓名 年龄：";
            cin >> id >> name >> age;
            createStudent(id, name, age);
        } else if (choice == 2) {
            readStudents();
        } else if (choice == 3) {
            int id, age;
            string name;
            cout << "输入要更新的学生ID：";
            cin >> id;
            cout << "输入新姓名和新年龄：";
            cin >> name >> age;
            updateStudent(id, name, age);
        } else if (choice == 4) {
            int id;
            cout << "输入要删除的学生ID：";
            cin >> id;
            deleteStudent(id);
        } else {
            cout << "无效操作，请重新选择。" << endl;
        }
    }
    return 0;
}