c++学生信息管理系统
时间: 2023-07-01 10:26:25 浏览: 59
c++实现学生信息系统管理
5星 · 资源好评率100%
学生信息管理系统可以用 C++ 编写,主要包括以下功能:
1. 添加学生信息
2. 删除学生信息
3. 修改学生信息
4. 查询学生信息
5. 显示所有学生信息
6. 退出系统
具体实现可以使用 C++ 中的数据结构,如数组、链表等。以下是一个简单的示例代码:
```cpp
#include <iostream>
#include <string>
using namespace std;
struct Student {
string name;
int age;
string id;
};
const int MAX_STUDENT_NUM = 100;
Student students[MAX_STUDENT_NUM];
int studentCount = 0;
void addStudent() {
if (studentCount >= MAX_STUDENT_NUM) {
cout << "学生信息已满,无法添加!" << endl;
return;
}
Student student;
cout << "请输入学生姓名:";
cin >> student.name;
cout << "请输入学生年龄:";
cin >> student.age;
cout << "请输入学生学号:";
cin >> student.id;
students[studentCount++] = student;
cout << "添加成功!" << endl;
}
void deleteStudent() {
if (studentCount <= 0) {
cout << "学生信息为空,无法删除!" << endl;
return;
}
string id;
cout << "请输入要删除的学生学号:";
cin >> id;
int index = -1;
for (int i = 0; i < studentCount; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
cout << "未找到该学生信息!" << endl;
} else {
for (int i = index; i < studentCount - 1; i++) {
students[i] = students[i + 1];
}
studentCount--;
cout << "删除成功!" << endl;
}
}
void updateStudent() {
if (studentCount <= 0) {
cout << "学生信息为空,无法修改!" << endl;
return;
}
string id;
cout << "请输入要修改的学生学号:";
cin >> id;
int index = -1;
for (int i = 0; i < studentCount; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
cout << "未找到该学生信息!" << endl;
} else {
Student student;
cout << "请输入学生姓名:";
cin >> student.name;
cout << "请输入学生年龄:";
cin >> student.age;
cout << "请输入学生学号:";
cin >> student.id;
students[index] = student;
cout << "修改成功!" << endl;
}
}
void queryStudent() {
if (studentCount <= 0) {
cout << "学生信息为空!" << endl;
} else {
string id;
cout << "请输入要查询的学生学号:";
cin >> id;
int index = -1;
for (int i = 0; i < studentCount; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
cout << "未找到该学生信息!" << endl;
} else {
cout << "姓名:" << students[index].name << endl;
cout << "年龄:" << students[index].age << endl;
cout << "学号:" << students[index].id << endl;
}
}
}
void showAllStudents() {
if (studentCount <= 0) {
cout << "学生信息为空!" << endl;
} else {
for (int i = 0; i < studentCount; i++) {
cout << "姓名:" << students[i].name << endl;
cout << "年龄:" << students[i].age << endl;
cout << "学号:" << students[i].id << endl << endl;
}
}
}
int main() {
int choice;
while (true) {
cout << "1. 添加学生信息" << endl;
cout << "2. 删除学生信息" << endl;
cout << "3. 修改学生信息" << endl;
cout << "4. 查询学生信息" << endl;
cout << "5. 显示所有学生信息" << endl;
cout << "6. 退出系统" << endl;
cout << "请选择功能:";
cin >> choice;
switch (choice) {
case 1:
addStudent();
break;
case 2:
deleteStudent();
break;
case 3:
updateStudent();
break;
case 4:
queryStudent();
break;
case 5:
showAllStudents();
break;
case 6:
cout << "退出系统!" << endl;
return 0;
default:
cout << "无效的选择!" << endl;
break;
}
}
}
```
以上代码实现了一个简单的学生信息管理系统,可以通过菜单进行各种操作,包括添加、删除、修改、查询和显示学生信息。
阅读全文