栀子花次奥
2021-05-31 08:38
采纳率: 100%
浏览 58

求助C语言的问题 ,求大佬解决

 

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 已采纳

    部分功能代码,按照这个完善一下就可以。

    #include "stdio.h"
    
    #define N 2
    struct Student
    {
    	//学号
    	int		num; //成员变量或者一个数据项
    	//姓名
    	char	name[20];
    	//性别
    	char	sex; //M,F
    	//成绩
    	float	html;	
    	float	ppt;
    	float	cyuyan;
    	float	sum;
    }st[N];
    void input();
    void display();
    void main()
    {
        input();
        display();
    }
    //输入函数
    void input()
    {
    	int i;
    	for(i=0;i<N;i++)
    	{
    		printf("请输入第%d个学生的学号,姓名,性别,html,ppt,cyuyan:",i+1);
    		scanf("%d",&st[i].num);
    		scanf("%s ",st[i].name);
    		scanf("%c ",&st[i].sex);
    		scanf("%f",&st[i].html);
    		scanf("%f",&st[i].ppt);
    		scanf("%f",&st[i].cyuyan);
    		st[i].sum = st[i].html+st[i].ppt+st[i].cyuyan;
    	}
    		
    }
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • CSDN专家-Fay 2021-05-31 08:41
    #include <stdio.h>
    #include <stdlib.h>
    #define N 30
    void Readscore(int id[],int score[],int n);
    int Average(int score[],int n);
    void Scoresort(int id[],int score[],int n);
    void Idsort(int id[],int score[],int n);
    int Selectsort(int id[],int score[],int n,int x);
    void Scoreclass(int score[],int n);
    void Showinfo(int id[],int score[],int n);
    int main()
    {
      int num,score[N],aver,n,sum,id[N],i,m,x,k,great=0,better=0,middle=0,low=0,lower=0;
    
    
    while(1){
    //首页选择
        printf("----------------\n");
        printf("1.Input record\n");
        printf("2.Caculate total and average score of course\n");
        printf("3.Sort in descending order by score\n");
        printf("4.Sort in ascending order by number\n");
        printf("5.Search by number\n");
        printf("6.Sta1tistic analysis\n");
        printf("7.List record\n");
        printf("0.Exit\n");
        printf("Please enter your choice\n");
        scanf("%d",&num);
    //用户输入功能
    
        switch(num){
            case 0:
    
                break;
            case 1:
                printf("Input n:\n");
                scanf("%d",&n);
                Readscore(id,score,n);
                break;
    
            case 2:
                sum=Average(score,n);
                printf("Sum score is %d\n",sum);
                printf("Average score is %d\n",sum/n);
                break;
            case 3:
                Scoresort(id,score,n);
                for(i=0;i<=n-1;i++){
                    printf("%3d%5d\n",id[i],score[i]);
                }
                break;
            case 4:
                Idsort(id,score,n);
                for(i=0;i<=n-1;i++){
                    printf("%3d%5d\n",id[i],score[i]);
                }
                break;
            case 5:
                printf("Input id:\n");
                scanf("%d",&x);
                m=Selectsort(id,score,n,x);
                if(m==-1){
                    printf("查询错误\n");
                }else{
                    printf("----------------\n");
                    printf("id:%3d score:%3d 排名:%3d\n",id[m],score[m],m+1);
                }
                break;
            case 6:
                Scoreclass(score,n);
                break;
            case 7:
                Showinfo(id,score,n);
                sum=Average(score,n);
                printf("----------------\n");
                printf("Sum score is %d\n",sum);
                printf("Average score is %d\n",sum/n);
                break;
    
    
            default:
                printf("Invalid operator\n");
    
    
    
    
      }
    }
    }
    //输出分数段
    void Scoreclass(int score[],int n){
    
        int i,j,count,k;
        double bate,m;
        m=n;
        int begin[5]={0,60,70,80,90};
        int end[5]={59,69,79,89,100};
        char* class[5]={"不及格","及格","中等","良好","优秀"};
    
        for(i=0,j=0;i<=n,j<5;i++,j++){
                count =0;
                bate=0;
           for(k=0;k<n;k++){
              if((begin[i]<=score[k])&&(end[i]>=score[k])){
                 count+=1;
                 bate=(100*count)/m;
              }
    
           }
    
           printf("%s的学生人数为:%d ,所占百分比为%.2f\n",class[j],count,bate/100);
    
        }
    
    }
    //输出每个学生的学号和成绩
    void Showinfo(int id[],int score[],int n){
        int i;
        for(i=0;i<=n-1;i++){
            printf("id:%3d score:%3d\n",id[i],score[i]);
        }
    }
    //根据学号查询学生成绩
    int Selectsort(int id[],int score[],int n,int x){
        int temp_score,i,j,temp_id,k;
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(score[i]<score[j]){
                        temp_score = score[i];
                        score[i]=score[j];
                        score[j]=temp_score;
                        temp_id=id[i];
                        id[i]=id[j];
                        id[j]=temp_id;
                }
            }
        }
        for(k=0;k<n;k++){
            if(id[k]==x)
                return k;
    
        }return -1;
    
    
    
    
    }
    //根据学号从小到大打印成绩
    void Idsort(int id[],int score[],int n){
        int temp_score,i,j,temp_id;
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(id[i]>id[j]){
                        temp_score = score[i];
                        score[i]=score[j];
                        score[j]=temp_score;
                        temp_id=id[i];
                        id[i]=id[j];
                        id[j]=temp_id;
                }
            }
        }
    
    
    }
    //从高到低打印成绩
    void Scoresort(int id[],int score[],int n){
        int temp_score,i,j,temp_id;
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(score[i]<score[j]){
                        temp_score = score[i];
                        score[i]=score[j];
                        score[j]=temp_score;
                        temp_id=id[i];
                        id[i]=id[j];
                        id[j]=temp_id;
                }
            }
        }
    
    
    }
    //计算班级平均分
    int Average(int score[],int n){
        int i,sum=0;
        for(i=0;i<n;i++){
            sum+=score[i];
        }
        return sum;
    }
    //录入学生成绩
    void Readscore(int id[],int score[],int n){
    
    
        int i;
        for(i=0;i<n;i++){
            printf("Input student's id and score:");
            scanf("%d %d",&id[i],&score[i]);
            if(score[i]<0){
                printf("成绩输入错误\n");
                return 0;
            }
        }
    
    }
    
    评论
    解决 无用
    打赏 举报
  • 有问必答小助手 2021-05-31 16:45

    您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

    ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

    【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
    【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题