学生单科统计

// 统计学生不及格次数
int countFailedCoursesForStudent(struct Lstudent* targetStudent) {
    int failedCount = 0;
    CourseListNode* currentCourse = targetStudent->chead;
    while (currentCourse != NULL) {
        if (currentCourse->data.chengji < 60) { // 假设60分为及格线
            failedCount++;
        }
        currentCourse = currentCourse->next;
    }
    return failedCount;
}

// 计算单个学生的总成绩
float calculateTotalScoreForStudent(struct Lstudent* targetStudent) {
    float totalScore = 0.0f;
    CourseListNode* currentCourse = targetStudent->chead;
    while (currentCourse != NULL) {
        totalScore += currentCourse->data.chengji;
        currentCourse = currentCourse->next;
    }
    return totalScore;
}

// 计算单个学生的平均成绩
float calculateAverageScoreForStudent(struct Lstudent* targetStudent) {
    int courseCount = countCoursesForStudent(targetStudent);
    float totalScore = calculateTotalScoreForStudent(targetStudent);
    if (courseCount > 0) {
        return totalScore / courseCount;
    } else {
        return 0.0f; // 或者可以根据实际情况设定默认值
    }
}

// 计算单个学生的最高分
float calculateMaxScoreForStudent(struct Lstudent* targetStudent) {
    float maxScore = targetStudent->chead->data.chengji;
    CourseListNode* currentCourse = targetStudent->chead->next;
    while (currentCourse != NULL) {
        if (currentCourse->data.chengji > maxScore) {
            maxScore = currentCourse->data.chengji;
        }
        currentCourse = currentCourse->next;
    }
    return maxScore;
}

// 计算单个学生的最低分
float calculateMinScoreForStudent(struct Lstudent* targetStudent) {
    float minScore = targetStudent->chead->data.chengji;
    CourseListNode* currentCourse = targetStudent->chead->next;
    int hasScore = 0;
    while (currentCourse != NULL) {
        if (currentCourse->data.chengji > 0 && (currentCourse->data.chengji < minScore || !hasScore)) {
            minScore = currentCourse->data.chengji;
            hasScore = 1;
        }
        currentCourse = currentCourse->next;
    }
    return hasScore ? minScore : 0.0f; // 如果没有成绩,则返回0或其他默认值
}

// 计算单个学生的不及格率(百分比形式)
float calculateFailureRateForStudent(struct Lstudent* targetStudent) {
    int totalCourses = countCoursesForStudent(targetStudent);
    int failedCourses = countFailedCoursesForStudent(targetStudent);
    if (totalCourses > 0) {
        return ((float)failedCourses / totalCourses) * 100.0f;
    } else {
    // 若学生没有参加任何课程,则不及格率为0%
        return 0.0f;
    }
}

int main() {
    // 初始化链表
    struct Lstudent* head = NULL; // 初始化为空指针
    load(&head,"信息.txt");
    KGPA(head);
    ZGPA(head);
    if (head != NULL) {
        // 打印链表信息
        printStudentListAndCourses(head);

        // 其他对链表的操作...
    } else {
        printf("没有读取到任何学生信息。\n");
    }
         // 示例:分析某个学生的信息
    int targetXuehao;
    printf("请输入要分析的学生学号:\n");
    scanf("%d", &targetXuehao);

    struct Lstudent* targetStudent = findStudentByXuehao(head, targetXuehao);
    if (targetStudent == NULL) {
        printf("未找到对应学号的学生信息。\n");
    } else {
        printf("\n学生学号:%d 的成绩分析:\n", targetStudent->data.xuehao);
        printf("总成绩:%.2f\n", calculateTotalScoreForStudent(targetStudent));
        printf("平均成绩:%.2f\n", calculateAverageScoreForStudent(targetStudent));
        printf("最高分:%.2f\n", calculateMaxScoreForStudent(targetStudent));
        printf("最低分:%.2f\n", calculateMinScoreForStudent(targetStudent));
        printf("不及格课程数:%d\n", countFailedCoursesForStudent(targetStudent));
        int failCount = countFailedCoursesForStudent(targetStudent);
        float failureRate = calculateFailureRateForStudent(targetStudent);
          printf("不及格率:%.2f%%\n", failureRate);

    }

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值