• 用结构体实现一个简单的学生信息系统


    #include <stdio.h>

    #define N 30

    struct STUDENT

    {

           char sname[30];//名字

           char sclass[10];//班级

           char ID[10];//学号

           char sdor[10];//宿舍

           float sscore[4];//4科分数

    }stu[N];

    void input(struct STUDENT stu[],int n)//输入各种信息

    {

           int i;

           for(i=0;i<n;i++)

           {

                  scanf("%s %s %s %s",stu[i].sname,stu[i].sclass,stu[i].ID,stu[i].sdor);

                  for(int j=0;j<4;j++)

                  {

                         if(j!=3||i==n-1)

                         scanf("%f",&stu[i].sscore[j]);

                         else

                         {

                                scanf("%f",&stu[i].sscore[j]);

                                getchar();

                         }

                  }

           }

    }

    void output(struct STUDENT stu[],int n)//输出各种信息

    {

           int i;

           for(i=0;i<n;i++)

           {

                  printf("%s %s %s %s ",stu[i].sname,stu[i].sclass,stu[i].ID,stu[i].sdor);

                  for(int j=0;j<4;j++)

                  {

                         if(j!=3)

                         printf("%.2f ",stu[i].sscore[j]);

                         else

                         {

                                printf("%.2f\n",stu[i].sscore[j]);

                         }

                  }

           }

    }

    int max(struct STUDENT stu[],int n)//比较各学生的计算机成绩

    {

           int i,t=0;

           for(i=0;i<n;i++)

           {

                  if(stu[t].sscore[3]<stu[i].sscore[3])

                  {

                         t=i;

                  }

           }

           return t;

    }

    change(float a[],int n)//对总分进行排序

    {

           int i,j;

           float t;

           for(i=0;i<n;i++)

           {

                  for(j=0;j<n-i-1;j++)

                  {

                         if(a[j]<a[j+1])

                         {

                                t=a[j];

                                a[j]=a[j+1];

                                a[j+1]=t;

                         }

                  }

           }

    }

    int main(void)

    {

           int n,i,j;

           float a[N]={0};

           input(stu,N);

           output(stu,N);

           n=max(stu,N);

           printf("computer max information:\nname:%s\nclass:%s\nID:%s\ndormatory:%s\nscore:",stu[n].sname,stu[n].sclass,stu[n].ID,stu[n].sdor);

           for(j=0;j<4;j++)

           {

                  if(j!=3)

                         printf("%.1f ",stu[n].sscore[j]);

                  else

                         printf("%.1f\n",stu[n].sscore[j]);

           }

           for(i=0;i<N;i++)//求各学生总分到数组

           {

                  for(j=0;j<4;j++)

                  {

                         a[i]+=stu[i].sscore[j];

                  }

           }

           change(a,N);

           printf("sum:");

           for(i=0;i<N;i++)

           {

                  if(i!=(N-1))

                  {

                         printf("%.1f ",a[i]);

                  }

                  else

                  {

                         printf("%.1f\n",a[i]);

                  }

           }

    }

  • 相关阅读:
    详解MySQL中EXPLAIN解释命令(转)
    yii framework config 可以被配置的项目
    YII之yiic创建YII应用
    Yii 用户登录验证
    全选,反选,获取值ajax提交
    firefox常用插件
    file_get_contents failed to open stream: HTTP request failed(一个字符决定成败)
    linux svn服务器(一)
    js操作cookie(转载:经测试可用)
    淘宝用户api 如何获得App Key和API Secret
  • 原文地址:https://www.cnblogs.com/zhaohongjie/p/12118384.html
Copyright © 2020-2023  润新知