你好,我现在要用C语言做一个学生考试系统。
首先,要做一个学生和教师的登录验证,登录之后会显示学生和教师的基本信息。
当学生登录后,学生可以选择考试和查询成绩。若学生选择考试,则显示可以考试的科目与时间,当学生选择其中一个科目并进入考试,则显示考试的题目,学生需要输入自己的答案,到截止时间,考试结束,学生的选择题答案,与预先提供的标答,自动匹配批改,每道题2分。
教师登录后,可以选择管理学生信息,进行修改,包括添加、删除。也可以选择批改试卷,对学生的答案进行打分,分值为0-10分。
最后对学生成绩进行汇总,并按从高到低进行排序。
C语言,有些模块没学过
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
13条回答 默认 最新
语言-逆行者 2023-06-09 00:56关注这样?

#include <stdio.h> #include <string.h> struct student { char name[20]; char password[20]; int score; }; struct teacher { char name[20]; char password[20]; }; int student_login(struct student *students, int n) { char name[20]; char password[20]; printf("请输入用户名:"); scanf("%s", name); printf("请输入密码:"); scanf("%s", password); for (int i = 0; i < n; i++) { if (strcmp(students[i].name, name) == 0 && strcmp(students[i].password, password) == 0) { printf("登录成功!\n"); printf("欢迎您,%s!\n", students[i].name); return i; } } printf("用户名或密码错误!\n"); return -1; } int teacher_login(struct teacher *teachers, int n) { char name[20]; char password[20]; printf("请输入用户名:"); scanf("%s", name); printf("请输入密码:"); scanf("%s", password); for (int i = 0; i < n; i++) { if (strcmp(teachers[i].name, name) == 0 && strcmp(teachers[i].password, password) == 0) { printf("登录成功!\n"); printf("欢迎您,%s!\n", teachers[i].name); return i; } } printf("用户名或密码错误!\n"); return -1; } void add_student(struct student *students, int n) { printf("请输入学生姓名:"); scanf("%s", students[n].name); printf("请输入学生密码:"); scanf("%s", students[n].password); students[n].score = 0; printf("添加成功!\n"); } void delete_student(struct student *students, int n) { char name[20]; printf("请输入要删除的学生姓名:"); scanf("%s", name); for (int i = 0; i < n; i++) { if (strcmp(students[i].name, name) == 0) { for (int j = i; j < n - 1; j++) { students[j] = students[j + 1]; } printf("删除成功!\n"); return; } } printf("未找到该学生!\n"); } void print_student_scores(struct student *students, int n) { printf("%-10s%-10s\n", "姓名", "成绩"); for (int i = 0; i < n; i++) { printf("%-10s%-10d\n", students[i].name, students[i].score); } } void modify_student_score(struct student *students, int n) { char name[20]; int score; printf("请输入要修改成绩的学生姓名:"); scanf("%s", name); for (int i = 0; i < n; i++) { if (strcmp(students[i].name, name) == 0) { printf("请输入新的成绩:"); scanf("%d", &score); students[i].score = score; printf("修改成功!\n"); return; } } printf("未找到该学生!\n"); } void exam(struct student *students, int student_index) { char *subjects[] = {"数学", "语文", "英语", "物理"}; char *questions[] = { "1 + 1 = ?\nA. 1\nB. 2\nC. 3\nD. 4\n", "我国的首都是?\nA. 北京\nB. 上海\nC. 广州\nD. 深圳\n", "What's your name?\nA. Tom\nB. Mike\nC. Jack\nD. None of the above\n", "牛顿第二定律的公式为?\nA. F = ma\nB. E = mc2\nC. F = G(m1m2)/r^2\nD. P = F/A\n" }; char *answers[] = {"B", "A", "D", "A"}; int choice; printf("请选择考试科目:\n"); for (int i = 0; i < 4; i++) { printf("%d. %s\n", i + 1, subjects[i]); } scanf("%d", &choice); choice--; printf("开始考试!\n"); printf("--------------------\n"); for (int i = 0; i < 4; i++) { printf("第%d题:\n%s", i + 1, questions[i]); char answer[10]; scanf("%s", answer); if (strcmp(answer, answers[i]) == 0) { printf("你的答案是:%s,恭喜你,回答正确!\n", answer); students[student_index].score += 2; } else { printf("你的答案是:%s,很遗憾,回答错误!\n", answer); } } printf("考试结束!\n"); printf("--------------------\n"); } void init(struct student *students, int *student_count, struct teacher *teachers, int *teacher_count) { // 添加学生信息 strcpy(students[0].name, "小明"); strcpy(students[0].password, "123456"); students[0].score = 0; strcpy(students[1].name, "小红"); strcpy(students[1].password, "111111"); students[1].score = 0; *student_count = 2; // 添加教师信息 strcpy(teachers[0].name, "张老师"); strcpy(teachers[0].password, "123456"); *teacher_count = 1; } int main() { struct student students[100]; int student_count = 0; struct teacher teachers[100]; int teacher_count = 0; int student_index = -1; int teacher_index = -1; int choice; init(students, &student_count, teachers, &teacher_count); while (1) { printf("请选择登录身份:\n"); printf("1. 学生\n"); printf("2. 教师\n"); printf("3. 退出程序\n"); scanf("%d", &choice); if (choice == 1) { student_index = student_login(students, student_count); if (student_index != -1) { while (1) { printf("请选择操作:\n"); printf("1. 开始考试\n"); printf("2. 退出登录\n"); scanf("%d", &choice); if (choice == 1) { exam(students, student_index); } else if (choice == 2) { student_index = -1; break; } else { printf("输入有误,请重新输入!\n"); } } } } else if (choice == 2) { teacher_index = teacher_login(teachers, teacher_count); if (teacher_index != -1) { while (1) { printf("请选择操作:\n"); printf("1. 添加学生\n"); printf("2. 删除学生\n"); printf("3. 查看成绩\n"); printf("4. 修改成绩\n"); printf("5. 退出登录\n"); scanf("%d", &choice); if (choice == 1) { add_student(students, student_count); student_count++; } else if (choice == 2) { delete_student(students, student_count); student_count--; } else if (choice == 3) { print_student_scores(students, student_count); } else if (choice == 4) { modify_student_score(students, student_count); } else if (choice == 5) { teacher_index = -1; break; } else { printf("输入有误,请重新输入!\n"); } } } } else if (choice == 3) { break; } else { printf("输入有误,请重新输入!\n"); } } printf("程序已退出!\n"); return 0; }评论 打赏 举报 编辑记录解决 5无用