#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//课程结构体
typedef struct {
char courseID[20];
char courseName[50];
char courseLocation[20];
int totalHours;
int lectureHours;
int labHours;
int credits;
int semester;
} Course;
//学生结构体
typedef struct {
char studentID[20];
Course enrolledCourses[10];
Course droppedCourses[10];
int enrolledCount;
int droppedCount;
double courseGrades[10];
} Student;
//教师结构体
typedef struct {
char teacherName[50];
char password[20];
Course managedCourses[10];
int managedCount;
} Teacher;
//教务管理员结构体
typedef struct {
char password[20];
Student students[100];
Teacher teachers[50];
Course courses[100];
int studentCount;
int teacherCount;
int courseCount;
} Admin;
void studentMode(Admin *admin);
void teacherMode(Admin *admin);
void adminMode(Admin *admin);
void saveData(const Admin *admin);
void loadData(Admin *admin);
void manageCoursesForTeacher(Admin *admin, Teacher *teacher);
void viewEnrolledStudents(Admin *admin, Teacher *teacher);
void postGrades(Admin *admin, Teacher *teacher);
void manageStudents(Admin *admin);
void manageTeachers(Admin *admin);
void manageCourses(Admin *admin);
void viewStudentCourses(Admin *admin);
void changeAdminPassword(Admin *admin);
void changeTeacherPassword(Admin *admin);
void viewStudentGrades(Admin *admin);
int main() {
Admin admin;
strcpy(admin.password, "123");
//从文件加载数据
loadData(&admin);
while (1) {
printf("*******选择模式*******\n");
printf("\n");
printf("1. 学生模式\n");
printf("2. 教师模式\n");
printf("3. 管理员模式\n");
printf("4. 退出\n");
printf("\n");
printf("**********************\n");
printf("\n");
printf("请选择你的身份:");
int choice;
if (scanf("%d", &choice) != 1) {
// 输入错误处理
while (getchar() != '\n');
// 清空输入缓冲区
printf("\n无效选择,再次尝试\n\n");
continue;
}
printf("\n");
switch (choice) {
case 1:
studentMode(&admin);
break;
case 2:
teacherMode(&admin);
break;
case 3:
adminMode(&admin);
break;
case 4:
saveData(&admin);
return 0;
default:
printf("\n");
printf("无效选择,再次尝试\n");
printf("\n");
}
}
return 0;
}
//学生模式
void studentMode(Admin *admin) {
char studentID[20];
printf("输入学生ID: ");
scanf("%s", studentID);
int studentIndex = -1;
for (int i = 0; i < admin->studentCount; i++) {
if (strcmp(admin->students[i].studentID, studentID) == 0) {
studentIndex = i;
break;
}
}
if (studentIndex == -1) {
printf("\n");
printf("无此学生信息\n");
printf("\n");
return;
}
Student *student = &admin->students[studentIndex];
while (1) {
printf("******学生菜单********\n");
printf("\n");
printf("1. 查看课程\n");
printf("2. 选择选修课程\n");
printf("3. 退课\n");
printf("4. 查看已选择选修课程\n");
printf("5. 查看退课课程\n");
printf("6. 查看成绩\n");
printf("7. 返回\n");
printf("\n");
printf("**********************\n");
printf("\n");
printf("请输入你的选择:");
int choice;
if (scanf("%d", &choice) != 1) {
while (getchar() != '\n');
printf("\n无效选择,再次尝试\n\n");
continue;
}
printf("\n");
if (choice == 7) break;
switch (choice) {
case 1:
for (int i = 0; i < admin->courseCount; i++) {
printf("%s - %s - %d 学分\n", admin->courses[i].courseName, admin->courses[i].courseLocation, admin->courses[i].credits);
}
break;
case 2: {
char courseID[20];
printf("输入要选择选修课ID: ");
scanf("%s", courseID);
int found = 0;
for (int i = 0; i < admin->courseCount; i++) {
if (strcmp(admin->courses[i].courseID, courseID) == 0) {
student->enrolledCourses[student->enrolledCount++] = admin->courses[i];
printf("\n");
printf("课程已注册成功\n");
printf("\n");
found = 1;
break;
}
}
if (!found) {
printf("\n");
printf("无此课程\n");
printf("\n");
}
break;
}
case 3: {
char courseID[20];
printf("输入要删除课程ID: ");
scanf("%s", courseID);
int found = 0;
for (int i = 0; i < student->enrolledCount; i++) {
if (strcmp(student->enrolledCourses[i].courseID, courseID) == 0) {
student->droppedCourses[student->droppedCount++] = student->enrolledCourses[i];
for (int j = i; j < student->enrolledCount - 1; j++) {
student->enrolledCourses[j] = student->enrolledCourses[j + 1];
}
student->enrolledCount--;
printf("\n");
printf("课程已删除成功\n");
printf("\n");
found = 1;
break;
}
}
if (!found) {
printf("在已选择选修课程中没有找到该课程\n");
}
break;
}
case 4:
for (int i = 0; i < student->enrolledCount; i++) {
printf("%s - %s - %d 学分\n", student->enrolledCourses[i].courseName, student->enrolledCourses[i].courseLocation, student->enrolledCourses[i].credits);
}
break;
case 5:
for (int i = 0; i < student->droppedCount; i++) {
printf("%s - %s - %d 学分\n", student->droppedCourses[i].courseName, student->droppedCourses[i].courseLocation, student->droppedCourses[i].credits);
}
break;
case 6:
for (int i = 0; i < student->enrolledCount; i++) {
printf("Course ID: %s - 成绩: %.2f\n", student->enrolledCourses[i].courseID, student->courseGrades[i]);
}
break;
default:
printf("\n");
printf("无效选择,再次尝试\n");
printf("\n");
}
}
}
//教师模式
void teacherMode(Admin *admin) {
char teacherName[50], password[20];
printf("输入教师姓名: ");
scanf("%s", teacherName);
printf("输入密码: ");
scanf("%s", password);
int teacherIndex = -1;
for (int i = 0; i < admin->teacherCount; i++) {
if (strcmp(admin->teachers[i].teacherName, teacherName) == 0 && strcmp(admin->teachers[i].password, password) == 0) {
teacherIndex = i;
break;
}
}
if (teacherIndex == -1) {
printf("\n");
printf("登录凭据无效\n");
printf("\n");
return;
}
Teacher *teacher = &admin->teachers[teacherIndex];
while (1) {
printf("******教师菜单********\n");
吼哟gen
- 粉丝: 0
- 资源: 1
最新资源
- 这是一个以20位中国著名书法家的风格编写的汉字作品的数据集 每个子集中有1000-7000张jpg图像(平均5251张图像)
- 【Academic tailor】学术小裁缝必备知识点:全局注意力机制(GAM)pytorch
- 数据科学领域的主流数据集类型及其应用分析
- 【Academic tailor】学术小裁缝必备知识点:全局注意力机制(GAM)TensorFlow
- Apple MacBook Pro和macOS Monterey用户的全方位使用指南
- 知识付费系统-直播+讲师入驻+课程售卖+商城系统-v2.1.9版本搭建以及资源分享下载
- Python爬虫技术深度解析与实战应用指南
- 用户手册User Guide的写法 简单规范模板.doc
- 计算机网络期末考试试卷-覆盖基础知识及应用技能的全面考核
- linphone sdk 编译后的share 文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈