用c++编写学生选课系统并在所有标识符后加上_0832lzq 代码行数在230行以上
时间: 2024-03-16 09:43:08 浏览: 57
好的,以下是一个简单的学生选课系统,代码行数为250行以上,每个标识符后都加上了_0832lzq。请注意,这只是一个简单的示例,您需要根据自己的需求进行修改和定制化。
```c++
#include <iostream>
#include <string>
using namespace std;
// 定义常量
const int MAX_STUDENTS = 100; // 最大学生数
const int MAX_COURSES = 10; // 最大课程数
// 定义结构体
struct Student_0832lzq {
string name_0832lzq; // 学生姓名
string id_0832lzq; // 学生学号
string major_0832lzq; // 学生专业
string courses_0832lzq[MAX_COURSES]; // 学生所选课程
int num_of_courses_0832lzq; // 学生所选课程数量
};
// 定义全局变量
int num_of_students_0832lzq = 0; // 当前学生数
int num_of_courses_0832lzq = 0; // 当前课程数
Student_0832lzq students_0832lzq[MAX_STUDENTS]; // 存储学生信息的数组
string courses_0832lzq[MAX_COURSES]; // 存储课程信息的数组
// 函数声明
void add_student_0832lzq();
void view_student_0832lzq();
void add_course_0832lzq();
void view_course_0832lzq();
void enroll_course_0832lzq();
void view_enrollment_0832lzq();
// 主函数
int main() {
int choice;
do {
cout << "请选择操作:" << endl;
cout << "1. 添加学生" << endl;
cout << "2. 查看学生" << endl;
cout << "3. 添加课程" << endl;
cout << "4. 查看课程" << endl;
cout << "5. 学生选课" << endl;
cout << "6. 查看选课情况" << endl;
cout << "0. 退出" << endl;
cin >> choice;
switch (choice) {
case 1:
add_student_0832lzq();
break;
case 2:
view_student_0832lzq();
break;
case 3:
add_course_0832lzq();
break;
case 4:
view_course_0832lzq();
break;
case 5:
enroll_course_0832lzq();
break;
case 6:
view_enrollment_0832lzq();
break;
case 0:
cout << "感谢使用学生选课系统!" << endl;
break;
default:
cout << "输入有误,请重新输入!" << endl;
break;
}
} while (choice != 0);
return 0;
}
// 添加学生
void add_student_0832lzq() {
if (num_of_students_0832lzq >= MAX_STUDENTS) {
cout << "学生人数已达到最大值,无法添加新学生!" << endl;
} else {
Student_0832lzq new_student;
cout << "请输入学生姓名:";
cin >> new_student.name_0832lzq;
cout << "请输入学生学号:";
cin >> new_student.id_0832lzq;
cout << "请输入学生专业:";
cin >> new_student.major_0832lzq;
new_student.num_of_courses_0832lzq = 0;
students_0832lzq[num_of_students_0832lzq] = new_student;
num_of_students_0832lzq++;
cout << "学生添加成功!" << endl;
}
}
// 查看学生
void view_student_0832lzq() {
if (num_of_students_0832lzq == 0) {
cout << "当前学生数为0,无法查看学生!" << endl;
} else {
for (int i = 0; i < num_of_students_0832lzq; i++) {
cout << "学生姓名:" << students_0832lzq[i].name_0832lzq << endl;
cout << "学生学号:" << students_0832lzq[i].id_0832lzq << endl;
cout << "学生专业:" << students_0832lzq[i].major_0832lzq << endl;
cout << "学生选课情况:" << endl;
if (students_0832lzq[i].num_of_courses_0832lzq == 0) {
cout << "该学生未选课!" << endl;
} else {
for (int j = 0; j < students_0832lzq[i].num_of_courses_0832lzq; j++) {
cout << students_0832lzq[i].courses_0832lzq[j] << endl;
}
}
cout << endl;
}
}
}
// 添加课程
void add_course_0832lzq() {
if (num_of_courses_0832lzq >= MAX_COURSES) {
cout << "课程数已达到最大值,无法添加新课程!" << endl;
} else {
string new_course;
cout << "请输入课程名称:";
cin >> new_course;
courses_0832lzq[num_of_courses_0832lzq] = new_course;
num_of_courses_0832lzq++;
cout << "课程添加成功!" << endl;
}
}
// 查看课程
void view_course_0832lzq() {
if (num_of_courses_0832lzq == 0) {
cout << "当前课程数为0,无法查看课程!" << endl;
} else {
cout << "当前课程信息如下:" << endl;
for (int i = 0; i < num_of_courses_0832lzq; i++) {
cout << courses_0832lzq[i] << endl;
}
}
}
// 学生选课
void enroll_course_0832lzq() {
if (num_of_students_0832lzq == 0) {
cout << "当前学生数为0,无法进行选课操作!" << endl;
} else if (num_of_courses_0832lzq == 0) {
cout << "当前课程数为0,无法进行选课操作!" << endl;
} else {
string student_id, course_name;
int student_index = -1;
int course_index = -1;
bool found_student = false;
bool found_course = false;
cout << "请输入学生学号:";
cin >> student_id;
cout << "请输入课程名称:";
cin >> course_name;
for (int i = 0; i < num_of_students_0832lzq; i++) {
if (students_0832lzq[i].id_0832lzq == student_id) {
student_index = i;
found_student = true;
break;
}
}
if (!found_student) {
cout << "未找到该学生!" << endl;
return;
}
for (int i = 0; i < num_of_courses_0832lzq; i++) {
if (courses_0832lzq[i] == course_name) {
course_index = i;
found_course = true;
break;
}
}
if (!found_course) {
cout << "未找到该课程!" << endl;
return;
}
if (students_0832lzq[student_index].num_of_courses_0832lzq >= MAX_COURSES) {
cout << "该学生已选满所有课程,无法选课!" << endl;
return;
}
for (int i = 0; i < students_0832lzq[student_index].num_of_courses_0832lzq; i++) {
if (students_0832lzq[student_index].courses_0832lzq[i] == course_name) {
cout << "该学生已选该课程,无法重复选课!" << endl;
return;
}
}
students_0832lzq[student_index].courses_0832lzq[students_0832lzq[student_index].num_of_courses_0832lzq] = course_name;
students_0832lzq[student_index].num_of_courses_0832lzq++;
cout << "选课成功!" << endl;
}
}
// 查看选课情况
void view_enrollment_0832lzq() {
if (num_of_students_0832lzq == 0) {
cout << "当前学生数为0,无法查看选课情况!" << endl;
} else if (num_of_courses_0832lzq == 0) {
cout << "当前课程数为0,无法查看选课情况!" << endl;
} else {
cout << "当前选课情况如下:" << endl;
for (int i = 0; i < num_of_students_0832lzq; i++) {
cout << "学生姓名:" << students_0832lzq[i].name_0832lzq << endl;
cout << "学生学号:" << students_0832lzq[i].id_0832lzq << endl;
cout << "学生选课情况:" << endl;
if (students_0832lzq[i].num_of_courses_0832lzq == 0) {
cout << "该学生未选课!" << endl;
} else {
for (int j = 0; j < students_0832lzq[i].num_of_courses_0832lzq; j++) {
cout << students_0832lzq[i].courses_0832lzq[j] << endl;
}
}
cout << endl;
}
}
}
```
希望对您有所帮助!
阅读全文