主要功能:(1) 学生管理:对学生基本信息的增加、修改和删除 (2) 学生查询:对学生基本信息和成绩的查询 (3) 学生选课:用于学生选择课程学习 (4) 学生成绩:对学生各科成绩的添加、修改和删除等管理 (5) 打印:用来打印学生的基本信息和成绩 参考数据表: 学生(学号,姓名,性别,年级,出生年月,系号) 成绩(学号,成绩,课程号) 课程(课程号,课程名,学分,上课时间,选课人数)用c++实现,不要用SQL
时间: 2023-09-21 17:08:15 浏览: 167
好的,以下是用C++实现学生管理系统的代码,具体需根据实际情况进行修改和完善:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 学生类
class Student {
public:
string id; // 学号
string name; // 姓名
char gender; // 性别
int grade; // 年级
string birth; // 出生年月
string dept; // 系号
};
// 成绩类
class Score {
public:
string id; // 学号
double grade; // 成绩
string course_id; // 课程号
};
// 课程类
class Course {
public:
string id; // 课程号
string name; // 课程名
int credit; // 学分
string time; // 上课时间
int num; // 选课人数
};
// 学生管理系统类
class StudentSystem {
public:
// 添加学生
void addStudent() {
Student stu;
cout << "请输入学生信息:" << endl;
cout << "学号:";
cin >> stu.id;
cout << "姓名:";
cin >> stu.name;
cout << "性别(男/女):";
cin >> stu.gender;
cout << "年级:";
cin >> stu.grade;
cout << "出生年月(如:19990101):";
cin >> stu.birth;
cout << "系号:";
cin >> stu.dept;
students.push_back(stu);
cout << "添加成功!" << endl;
}
// 修改学生信息
void modifyStudent() {
string id;
cout << "请输入要修改的学生的学号:";
cin >> id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == id) {
cout << "请输入新的学生信息:" << endl;
cout << "学号:";
cin >> students[i].id;
cout << "姓名:";
cin >> students[i].name;
cout << "性别(男/女):";
cin >> students[i].gender;
cout << "年级:";
cin >> students[i].grade;
cout << "出生年月(如:19990101):";
cin >> students[i].birth;
cout << "系号:";
cin >> students[i].dept;
cout << "修改成功!" << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 删除学生
void deleteStudent() {
string id;
cout << "请输入要删除的学生的学号:";
cin >> id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == id) {
students.erase(students.begin() + i);
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 查找学生信息
void findStudent() {
string id;
cout << "请输入要查找的学生的学号:";
cin >> id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == id) {
cout << "学号:" << students[i].id << endl;
cout << "姓名:" << students[i].name << endl;
cout << "性别:" << students[i].gender << endl;
cout << "年级:" << students[i].grade << endl;
cout << "出生年月:" << students[i].birth << endl;
cout << "系号:" << students[i].dept << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 添加成绩
void addScore() {
Score score;
cout << "请输入成绩信息:" << endl;
cout << "学号:";
cin >> score.id;
cout << "课程号:";
cin >> score.course_id;
cout << "成绩:";
cin >> score.grade;
scores.push_back(score);
cout << "添加成功!" << endl;
}
// 修改成绩
void modifyScore() {
string id, course_id;
cout << "请输入要修改的学生的学号和课程号:";
cin >> id >> course_id;
for (int i = 0; i < scores.size(); i++) {
if (scores[i].id == id && scores[i].course_id == course_id) {
cout << "请输入新的成绩:";
cin >> scores[i].grade;
cout << "修改成功!" << endl;
return;
}
}
cout << "未找到该学生成绩!" << endl;
}
// 删除成绩
void deleteScore() {
string id, course_id;
cout << "请输入要删除的学生的学号和课程号:";
cin >> id >> course_id;
for (int i = 0; i < scores.size(); i++) {
if (scores[i].id == id && scores[i].course_id == course_id) {
scores.erase(scores.begin() + i);
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该学生成绩!" << endl;
}
// 显示学生所有成绩
void showScore() {
string id;
cout << "请输入要显示成绩的学生的学号:";
cin >> id;
cout << "课程名\t成绩" << endl;
for (int i = 0; i < scores.size(); i++) {
if (scores[i].id == id) {
for (int j = 0; j < courses.size(); j++) {
if (courses[j].id == scores[i].course_id) {
cout << courses[j].name << "\t" << scores[i].grade << endl;
break;
}
}
}
}
}
// 学生选课
void selectCourse() {
string id, course_id;
cout << "请输入学生的学号和要选的课程号:";
cin >> id >> course_id;
for (int i = 0; i < courses.size(); i++) {
if (courses[i].id == course_id) {
courses[i].num++;
break;
}
}
for (int i = 0; i < scores.size(); i++) {
if (scores[i].id == id && scores[i].course_id == course_id) {
cout << "已选过该课程!" << endl;
return;
}
}
Score score;
score.id = id;
score.course_id = course_id;
score.grade = 0;
scores.push_back(score);
cout << "选课成功!" << endl;
}
// 打印学生信息和成绩
void print() {
string id;
cout << "请输入要打印信息的学生的学号:";
cin >> id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == id) {
cout << "学号:" << students[i].id << endl;
cout << "姓名:" << students[i].name << endl;
cout << "性别:" << students[i].gender << endl;
cout << "年级:" << students[i].grade << endl;
cout << "出生年月:" << students[i].birth << endl;
cout << "系号:" << students[i].dept << endl;
cout << "课程名\t成绩" << endl;
for (int j = 0; j < scores.size(); j++) {
if (scores[j].id == id) {
for (int k = 0; k < courses.size(); k++) {
if (courses[k].id == scores[j].course_id) {
cout << courses[k].name << "\t" << scores[j].grade << endl;
break;
}
}
}
}
return;
}
}
cout << "未找到该学生!" << endl;
}
// 显示所有课程信息
void showCourses() {
cout << "课程号\t课程名\t学分\t上课时间\t选课人数" << endl;
for (int i = 0; i < courses.size(); i++) {
cout << courses[i].id << "\t" << courses[i].name << "\t" << courses[i].credit << "\t" << courses[i].time << "\t" << courses[i].num << endl;
}
}
private:
vector<Student> students; // 存储学生信息的向量
vector<Score> scores; // 存储成绩信息的向量
vector<Course> courses{ {"001", "语文", 4, "周一1-2节", 0},
{"002", "数学", 5, "周二3-4节", 0},
{"003", "英语", 3, "周三5-6节", 0},
{"004", "物理", 3, "周四1-2节", 0},
{"005", "化学", 2, "周五3-4节", 0} }; // 存储课程信息的向量
};
int main() {
StudentSystem system;
int choice;
while (true) {
cout << "欢迎使用学生管理系统,请输入数字选择功能:" << endl;
cout << "1. 添加学生" << endl;
cout << "2. 修改学生信息" << endl;
cout << "3. 删除学生" << endl;
cout << "4. 查找学生信息" << endl;
cout << "5. 添加成绩" << endl;
cout << "6. 修改成绩" << endl;
cout << "7. 删除成绩" << endl;
cout << "8. 显示学生所有成绩" << endl;
cout << "9. 学生选课" << endl;
cout << "10. 打印学生信息和成绩" << endl;
cout << "11. 显示所有课程信息" << endl;
cout << "0. 退出系统" << endl;
cout << "请输入数字选择功能:";
cin >> choice;
switch (choice) {
case 1:
system.addStudent();
break;
case 2:
system.modifyStudent();
break;
case 3:
system.deleteStudent();
break;
case 4:
system.findStudent();
break;
case 5:
system.addScore();
break;
case 6:
system.modifyScore();
break;
case 7:
system.deleteScore();
break;
case 8:
system.showScore();
break;
case 9:
system.selectCourse();
break;
case 10:
system.print();
break;
case 11:
system.showCourses();
break;
case 0:
cout << "感谢使用学生管理系统!" << endl;
return 0;
default:
cout << "输入有误,请重新输入!" << endl;
break;
}
}
return 0;
}
```
阅读全文