用c++写一个学生学籍管理系统
时间: 2023-08-04 17:28:46 浏览: 96
用C++写的一个学籍管理系统源码.zip
5星 · 资源好评率100%
好的,我可以为您提供一个简单的学生学籍管理系统的C++代码框架,您可以根据自己的需求进行修改和完善。
```c++
#include <iostream>
#include <string>
using namespace std;
// 学生类
class Student {
public:
string name; // 姓名
int age; // 年龄
string gender; // 性别
string id; // 学号
// 构造函数
Student(string n, int a, string g, string i) {
name = n;
age = a;
gender = g;
id = i;
}
// 显示学生信息
void display() {
cout << "姓名:" << name << endl;
cout << "年龄:" << age << endl;
cout << "性别:" << gender << endl;
cout << "学号:" << id << endl;
}
};
// 学生管理系统类
class StudentManager {
private:
Student* students; // 学生数组
int count; // 学生数量
public:
// 构造函数
StudentManager() {
students = new Student[100];
count = 0;
}
// 添加学生
void addStudent() {
string name, gender, id;
int age;
cout << "请输入学生姓名:";
cin >> name;
cout << "请输入学生年龄:";
cin >> age;
cout << "请输入学生性别:";
cin >> gender;
cout << "请输入学生学号:";
cin >> id;
Student student(name, age, gender, id);
students[count] = student;
count++;
cout << "添加成功!" << endl;
}
// 显示所有学生信息
void displayAll() {
for (int i = 0; i < count; i++) {
students[i].display();
cout << endl;
}
}
// 查找学生
Student* findStudent(string id) {
for (int i = 0; i < count; i++) {
if (students[i].id == id) {
return &students[i];
}
}
return NULL;
}
// 删除学生
void deleteStudent(string id) {
for (int i = 0; i < count; i++) {
if (students[i].id == id) {
for (int j = i; j < count - 1; j++) {
students[j] = students[j + 1];
}
count--;
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 修改学生信息
void modifyStudent(string id) {
Student* student = findStudent(id);
if (student != NULL) {
string name, gender;
int age;
cout << "请输入学生姓名:";
cin >> name;
cout << "请输入学生年龄:";
cin >> age;
cout << "请输入学生性别:";
cin >> gender;
student->name = name;
student->age = age;
student->gender = gender;
cout << "修改成功!" << endl;
}
else {
cout << "未找到该学生!" << endl;
}
}
};
// 主函数
int main() {
StudentManager manager;
int choice;
string id;
do {
cout << "请选择操作:" << endl;
cout << "1.添加学生" << endl;
cout << "2.显示所有学生" << endl;
cout << "3.查找学生" << endl;
cout << "4.删除学生" << endl;
cout << "5.修改学生信息" << endl;
cout << "0.退出" << endl;
cout << "请选择:";
cin >> choice;
switch (choice) {
case 1:
manager.addStudent();
break;
case 2:
manager.displayAll();
break;
case 3:
cout << "请输入学生学号:";
cin >> id;
manager.findStudent(id)->display();
break;
case 4:
cout << "请输入学生学号:";
cin >> id;
manager.deleteStudent(id);
break;
case 5:
cout << "请输入学生学号:";
cin >> id;
manager.modifyStudent(id);
break;
case 0:
break;
default:
cout << "输入错误,请重新输入!" << endl;
break;
}
cout << endl;
} while (choice != 0);
return 0;
}
```
这个代码框架包含了基本的学生信息的添加、显示、查找、删除和修改等功能。您可以根据自己的需求进行修改和完善。
阅读全文