C++实现学生信息管理系统的完整代码示例和功能说明

C++实现的学生信息管理系统的主要功能是实现学生信息的增加、删除、修改和查询。它可以帮助用户快速管理学生信息,提高工作效率。

使用方法

1. 编译程序:将源代码文件存入同一个文件夹,使用g++编译程序,例如:g++ main.cpp -o main.exe;

2. 运行程序:双击生成的可执行文件,例如:main.exe;

3. 功能说明:程序运行后,会提示用户输入学生信息,包括学号、姓名、性别、年龄等,用户输入完成后,可以选择添加、删除、修改和查询学生信息的功能;

// 添加学生信息
void addStudent(vector &students)
{
    Student stu;
    cout << "Please enter student's ID: ";
    cin >> stu.id;
    cout << "Please enter student's name: ";
    cin >> stu.name;
    cout << "Please enter student's gender: ";
    cin >> stu.gender;
    cout << "Please enter student's age: ";
    cin >> stu.age;
    students.push_back(stu);
    cout << "Add student successfully!" << endl;
}

// 删除学生信息
void deleteStudent(vector &students)
{
    int id;
    cout << "Please enter student's ID: ";
    cin >> id;
    for (int i = 0; i < students.size(); i++)
    {
        if (students[i].id == id)
        {
            students.erase(students.begin() + i);
            cout << "Delete student successfully!" << endl;
        }
    }
}

// 修改学生信息
void modifyStudent(vector &students)
{
    int id;
    cout << "Please enter student's ID: ";
    cin >> id;
    for (int i = 0; i < students.size(); i++)
    {
        if (students[i].id == id)
        {
            cout << "Please enter student's name: ";
            cin >> students[i].name;
            cout << "Please enter student's gender: ";
            cin >> students[i].gender;
            cout << "Please enter student's age: ";
            cin >> students[i].age;
            cout << "Modify student successfully!" << endl;
        }
    }
}

// 查询学生信息
void queryStudent(vector &students)
{
    int id;
    cout << "Please enter student's ID: ";
    cin >> id;
    for (int i = 0; i < students.size(); i++)
    {
        if (students[i].id == id)
        {
            cout << "The student's name is: " << students[i].name << endl;
            cout << "The student's gender is: " << students[i].gender << endl;
            cout << "The student's age is: " << students[i].age << endl;
        }
    }
}

以上就是,它可以帮助用户快速管理学生信息,提高工作效率。

本文链接:http://task.lmcjl.com/news/8390.html

展开阅读全文