5111专享

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>

struct student {
    int Rank;
    char StudentID[8];
    char Name[20];
    double Score[5];
};

int Input(struct student std[], int n) {
    int i;
    char temp[20], ch;
    for(i = n + 1; i <= 1000; i++) {
        getchar();
        printf("\n请输入学号:");
        gets(std[i].StudentID);
        printf("请输入名字:");
        gets(std[i].Name);
        printf("请输入语文成绩:");
        gets(temp);
        std[i].Score[0] = atof(temp);
        printf("请输入数学成绩:");
        gets(temp);
        std[i].Score[1] = atof(temp);
        printf("请输入英语成绩:");
        gets(temp);
        std[i].Score[2] = atof(temp);
        std[i].Score[3] = std[i].Score[0] + std[i].Score[1] + std[i].Score[2];
        std[i].Score[4] = std[i].Score[3] / 3.0;
        printf("是否继续?y/n");
        scanf("%c", &ch);
        if(ch == 'n' || ch == 'N')
            break;
    }
    return i;
}

void Sortyw(struct student std[], int n) {
    int i, j, max;
    struct student temp;
    for(i = 1; i < n; i++) {
        max = i;
        for(j = i + 1; j <= n; j++) {
            if(std[j].Score[0] > std[max].Score[0])
                max = j;
        }
        if(i != max) {
            temp = std[i];
            std[i] = std[max];
            std[max] = temp;
        }
    }
}

void Sortzf(struct student std[], int n) {
    int i, j, low, high, mid;
    for(i = 2; i <= n; i++) {
        std[0] = std[i];
        low = 1;
        high = i - 1;
        while(low <= high) {
            mid = (low + high) / 2;
            if(std[0].Score[3] > std[mid].Score[3])
                high = mid - 1;
            else
                low = mid + 1;
        }
        for(j = i - 1; j >= high + 1; j--)
            std[j + 1] = std[j];
        std[high + 1] = std[0];
    }
}

void Display(struct student std[], int n) {
    int i;
    printf("\n学号\t姓名\t语文\t数学\t英语\t总分\t平均分\t名次\n");
    for(i = 1; i <= n; i++) {
        std[i].Rank = i;
        printf("%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%d\n", std[i].StudentID, std[i].Name, std[i].Score[0], std[i].Score[1], std[i].Score[2], std[i].Score[3], std[i].Score[4], std[i].Rank);
    }
    printf("按任意键继续...");
    getch();
}

int main() {
    struct student std[1001];
    int n = 0;
    while(1) {
        printf("\n*********学生成绩管理系统**********\n");
        printf("* 1 输入 *\n");
        printf("* 2 排序 *\n");
        printf("* 3 显示 *\n");
        printf("* 4 退出 *\n");
        printf("请选择(1-4):");
        int choice;
        scanf("%d", &choice);
        switch(choice) {
            case 1:
                n = Input(std, n);
                break;
            case 2:
                Sortzf(std, n);
                break;
            case 3:
                Display(std, n);
                break;
            case 4:
                exit(0);
            default:
                printf("无效选择,请重新输入。\n");
        }
    }
    return 0;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值