惰.. 2023-06-10 12:18 采纳率: 33.3%
浏览 114
已结题

考试模块的完善及试卷的录入

学生考试系统:实现学生的试卷管理、考试、批改和成绩统计功能。系统可以管理多个考试科目和学生信息,包括试卷内容和学生答案。教师可以录入试卷,学生可以进行考试,系统需要支持试卷的批改和成绩的统计。

  • 写回答

13条回答 默认 最新

  • 语言-逆行者 2023-06-10 12:42
    关注

    不是提问过一次了吗,我的链接里面就有我的回答代码,怎么回事?不符合可以回复交流,有帮助记得采纳

    
    #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;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(12条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月15日
  • 已采纳回答 6月15日
  • 创建了问题 6月10日