buluoqingyun24 2023-06-05 13:47 采纳率: 50%
浏览 44
已结题

关于#c语言#的问题,请各位专家解答!

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define Max 30

int Menu(void);
void Readscore(float score[], long ID[], int n,char name[][21]);
void Average(float socore[], int n);
void Scoreuprand(float score[], long ID[], char name[][21], int n);
void IDfind(float score[], long ID[], char name[][21], int n);
void Namefind(float score[], long ID[], char name[][21], int n);
void Verious(float score[], int n);
void Mingzi(char name[], char m[]);
void Xuehao(long* px, long* py);
void Fenshu(float* px, float* py);
void Chengjidan(float score[], long ID[], char name[][21],int n);
int main()
{
    int x;
    int n;
    char name[Max][21];
    float score[Max];
    long ID[Max];
    
    printf("****************************************\n");
    printf("*         欢迎使用学生管理系统         *\n");
    printf("****************************************\n");
    printf("请输入所在班级人数:");
    scanf_s("%d", &n);
    getchar();
    while (1)
    {
        x = Menu();
        switch (x)
        {
        case 1: Readscore(score, ID, n, name);   break;
        case 2: Average(score, n);               break;
        case 3: Scoreuprand(score, ID, n, name); break;
        case 4: IDfind(score, ID, n, name);      break;
        case 5: Namefind(score, ID, n, name);    break;
        case 6: Verious(score, n);               break;
        case 7: Chengjidan(score, ID, name, n);  break;
        case 0: return 0;                        break;
        default:printf("输入错误,请重新输入!");
        }
    }
}
int Menu(void)
{
    int x;
    system("cls");
    printf("****************************************\n");
    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("*            0.退出                    *\n");
    printf("*            请输入你的选择:           *\n");
    printf("****************************************\n");
    scanf("%d", &x);
    return x;
}

void Readscore(float score[], long ID[], int n, char name[][21])
{
    system("cls");
    printf("*               成绩录入               *\n");
    int i;
    printf("输入学号,姓名和成绩:\n");
    for (i = 0; i < n; i++)
    {
        //gets(ID[i], name[i], score[i]);
        scanf("%1D %s %f", &ID[i], name+i, &score[i]);
    }
    system("pause");
}

void Average(float score[], int n)
{
    system("cls");
    printf("*              总分和平均分              *\n");
    int i, sum = 0;
    for (i = 0; i < n; i++)
    {
        sum += score[i];
    }
    printf("*    成绩总和:%d    成绩平均分:%d     *\n", sum, sum / (float)n);
    system("pause");
}

void Scoreuprand(float score[], long ID[], char name[][21], int n)
{
    system("cls");
    printf(" *                 成绩表               * \n");
    int i, j;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (score[i]>score[j])
            {
                Fenshu(&score[i], &score[j]);
                Mingzi(name[i], name[j]);
                Xuehao(&ID[i], &ID[j]);
            }
        }
    }
    Chengjidan(score, ID, name, n);
    system("pause");
}

void IDfind(float score[], long ID[], char name[][21], int n)
{
    system("cls");
    printf("*               学号查询               *\n");
    int low = 0, high = n - 1, ret,i, k;
    printf("*请输入要查询的学生学号:*\n");
    ret=scanf("%1d", &k);
    while (ret != 1)
    {
        while (getchar() != '\n');
        printf("*请输入正确的学号:*\n");
        scanf("%1d", &k);
    }
    for (i = 0; i < n; i++)
    {
        if (k == ID[i])
        {
            printf("查询结果:\n");
            printf("\n学号:%1d ",ID[i]);
            printf("姓名; %s  ",name[i]);
            printf("成绩:%f\n",score[i]);
            break;
        }
        if (k == (n - 1) && k != ID[i])
        {
            printf("未找到该同学,请重新输入学号\n");
        }
    }
    system("pause");
}

void Namefind(float score[], long ID[], char name[][21], int n)
{
    system("cls");
    printf("*               姓名查询               *\n");
    long i = 0;
    char cha[11];
    char chu[11] = "0";
    while (1)
    {
        printf("请输入需要查询的姓名:\n");
        scanf("%s", cha);
        if (strcmp(cha, chu) == 0)
        {
            printf("即将返回主菜单\n");
            return (0);
        }
        for (i = 0; i < n; i++)
        {
            if (strcmp(cha, name[i]) == 0)
            {
                printf("姓名:%s", name[i]);
                printf("学号:%1d", ID[i]);
                printf("成绩:%f\n", score[i]);
                break;
            }
            if (i == (n - 1) && strcmp(cha, name[i]) != 0)
            {
                printf("未找到该同学,请重新输入姓名\n");
            }
        }
        system("pause");
    }
}

void Verious(float score[], int n)
{
    system("cls");
    printf("*                成绩分类               *\n");
    int i;
    float x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0;
    for (i = 0; i < n; i++)
    {
        if (score[i] >= 90 && score[i]<=100)
        {
            x1++;
        }
        else if (score[i] >= 80 && score[i]<=90)
        {
            x2++;
        }
        else if (score[i] >= 70 && score[i]<=80)
        {
            x3++;
        }
        else if (score[i] >= 60 && score[i]<=70)
        {
            x4++;
        }
        else
        {
            x5++;
        }
    }
    printf("优秀人数:   %.f");
    printf("良好人数:    %.f");
    printf("较好人数:   %.f");
    printf("及格人数:   %.f");
    printf("不及格人数: %.f");
    system("pause");
}

void Mingzi(char name[], char m[])
{
    char s[21];
    strcpy(s, name);
    strcpy(name, m);
    strcpy(m, s);
}

void Xuehao(long* px, long* py)
{
    int x;
    x = *px;
    *px = *py;
    *py = x;
}

void Fenshu(float* px, float* py)
{
    int x;
    x = *px;
    *px = *py;
    *py = x;
}

void Chengjidan(float score[], long ID[], char name[][21], int n)
{
    int i;
    if (n == 0)
    {
        printf("未录入成绩!");
    }
    printf("姓名          学号          分数\n");
    for (i = 0; i < n; i++)
    {
        printf("%d   %d   %d   %d\n",i+1,name[i],ID[i],score[i]);
    }
    system("pause");
}


  • 写回答

4条回答 默认 最新

  • 少林and叔叔 2023-06-05 14:38
    关注

    本来是真心不想给你改这个程序的,里面好多基本规则都没有遵守,后面还是给你修改了。
    都验证可以的,源码如下:

    #include    <stdio.h>
    #include    <string.h>
    #include    <stdlib.h>
    #define Max 30
     
    typedef struct
    {
        char name[21];
        double score;
        char ID[21];
    }Student_Struct;
    
    int Menu(void);
    
    void Readscore(Student_Struct *student,int n);
    void Average(Student_Struct *student, int n);
    void Scoreuprand(Student_Struct *student, int n);
    void Chengjidan(Student_Struct *student, int n);
    void IDfind(Student_Struct *student, int n);
    void Namefind(Student_Struct *student, int n);
    void Verious(Student_Struct *student, int n);
    
    
    int main()
    {
        int x;
        int n;
        //char name[Max][21];
        //float score[Max];
        //long ID[Max];
        Student_Struct student_structure[Max];
        
        printf("****************************************\n");
        printf("*         欢迎使用学生管理系统         *\n");
        printf("****************************************\n");
        printf("请输入所在班级人数:");
        scanf("%d", &n);
        //getchar();
        while (1)
        {
            x = Menu();
    
            switch (x)
            {
            case 1: 
                    Readscore(student_structure, n);   
                    break;
            case 2: 
                    Average(student_structure, n);               
                    break;
            case 3: 
                    Scoreuprand(student_structure, n);
                    break;
            case 4: 
                    IDfind(student_structure, n);      
                    break;
            case 5: 
                    Namefind(student_structure, n);  
                    break;
            case 6: 
                    Verious(student_structure, n);             
                    break;
            case 7: 
                    Chengjidan(student_structure, n);
                    //Chengjidan(score, ID, name, n);  
                    break;
            case 0: 
                    return 0;                        
                    break;
            default:
                    printf("输入错误,请重新输入!");
                    break;
            }
    
        }
    }
    int Menu(void)
    {
        int x;
        system("cls");
        printf("****************************************\n");
        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("*            0.退出                    *\n");
        printf("*            请输入你的选择:           *\n");
        printf("****************************************\n");
        scanf("%d", &x);
        return x;
    }
    void Readscore(Student_Struct *student,int n)
    {
        system("cls");
        printf("*               成绩录入               *\n");
        int i;
        printf("输入学号,姓名和成绩:\n");
        for (i = 0; i < n; i++)
        {
            scanf("%s %s %lf", student[i].ID, student[i].name, &student[i].score);
        }
        system("pause");
    }
    
    
    void Average(Student_Struct *student, int n)
    {
        system("cls");
        printf("*              总分和平均分              *\n");
        int i;
        double sum = 0;
        for (i = 0; i < n; i++)
        {
            sum += student[i].score;
        }
        printf("*    成绩总和:%lf    成绩平均分:%lf    *\n", sum, sum / n);
        system("pause");
    }
    
    void Mingzi(char *name, char *m)
    {
        char s[21];
        strcpy(s, name);
        strcpy(name, m);
        strcpy(m, s);
    }
     
    void Xuehao(char *px, char *py)
    {
        char s[21];
    
        strcpy(s, px);
        strcpy(px, py);
        strcpy(py, s);
       
    }
     
    void Fenshu(double *px, double *py)
    {
        double x;
        x = *px;
        *px = *py;
        *py = x;
    }
    void Chengjidan(Student_Struct *student, int n)
    {
        int i;
        if (n == 0)
        {
            printf("未录入成绩!");
        }
        printf("     姓名          学号          分数\n");
        for (i = 0; i < n; i++)
        {
            printf("%d   %s   %s   %lf\n",i+1,student[i].name,student[i].ID,student[i].score);
        }
        system("pause");
    }
    void Scoreuprand(Student_Struct *student, int n)
    {
        int i, j;
        system("cls");
        printf(" *                 成绩表               * \n");
        
        for (i = 0; i < n; i++)
        {
            for (j = i + 1; j < n; j++)
            {
                if (student[i].score>student[j].score)
                {
                    Fenshu(&student[i].score, &student[j].score);
                    Mingzi(student[i].name, student[j].name);
                    Xuehao(student[i].ID, student[j].ID);
                }
            }
        }
        Chengjidan(student, n);
        system("pause");
    }
    
    void IDfind(Student_Struct *student, int n)
    {
        int low = 0, high = n - 1, ret,i;
        char k[21];
        system("cls");
        printf("*               学号查询               *\n");
        
    
        printf("*请输入要查询的学生学号:*\n");
        ret=scanf("%s", k);
        /*
        while (ret != 1)
        {
            while (getchar() != '\n');
            printf("*请输入正确的学号:*\n");
            scanf("%1d", &k);
        }
        */
        for (i = 0; i < n; i++)
        {
            if (strcmp(k,student[i].ID)==0)
            {
                printf("查询结果:\n");
                printf("\n学号:%s ",student[i].ID);
                printf("姓名; %s  ",student[i].name);
                printf("成绩:%f\n",student[i].score);
                break;
            }
            if (i == (n - 1))
            {
                printf("未找到该同学,请重新输入学号\n");
            }
        }
        system("pause");
    }
    
    void Namefind(Student_Struct *student, int n)
    {
        system("cls");
        printf("*               姓名查询               *\n");
        long i = 0;
        char name[21];
        char chu[21] = "0";
        while (1)
        {
            printf("请输入需要查询的姓名:\n");
            scanf("%s", name);
            if (strcmp(name, chu) == 0)
            {
                printf("即将返回主菜单\n");
                return (0);
            }
            for (i = 0; i < n; i++)
            {
                if (strcmp(name, student[i].name) == 0)
                {
                    printf("姓名:%s", student[i].name);
                    printf("学号:%s", student[i].ID);
                    printf("成绩:%lf\n", student[i].score);
                    break;
                }
                if (i == (n - 1))
                {
                    printf("未找到该同学,请重新输入姓名\n");
                }
            }
            system("pause");
        }
    }
    
    void Verious(Student_Struct *student, int n)
    {
        system("cls");
        printf("*                成绩分类               *\n");
        int i;
        int x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0;
        for (i = 0; i < n; i++)
        {
            if (student[i].score >= 90 && student[i].score<=100)
            {
                x1++;
            }
            else if (student[i].score >= 80)
            {
                x2++;
            }
            else if (student[i].score >= 70)
            {
                x3++;
            }
            else if (student[i].score >= 60)
            {
                x4++;
            }
            else
            {
                x5++;
            }
        }
        printf("优秀人数:   %d\n",x1);
        printf("良好人数:    %d\n",x2);
        printf("较好人数:   %d\n",x3);
        printf("及格人数:   %d\n",x3);
        printf("不及格人数: %d\n",x4);
        system("pause");
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 6月13日
  • 已采纳回答 6月5日
  • 创建了问题 6月5日

悬赏问题

  • ¥15 mySQL5.7.34安装遇到的问题
  • ¥15 结构功能耦合指标计算
  • ¥20 visual studio中c语言用ODBC链接SQL SERVER
  • ¥50 AI大模型精调(百度千帆、飞浆)
  • ¥15 非科班怎么跑代码?如何导数据和调参
  • ¥15 福州市的全人群死因监测点死亡原因报表
  • ¥15 Altair EDEM中生成一个颗粒,并且各个方向没有初始速度
  • ¥15 系统2008r2 装机配置推荐一下
  • ¥500 服务器搭建cisco AnyConnect vpn
  • ¥15 悬赏Python-playwright部署在centos7上