2007
06-19

各位大侠,小弟是新手,现在在做一个作业,如下:


NN >= 10)个学生的数据信息,每个包含:


学号        num [10](字符串)、


姓名(拼音)— name[25](字符串)、


性别        sex(字符,MF)、


年龄        age(整型)、


三门课程成绩(稿数、英语、计算机)— score [3 ](单精度)。


设计一个系统,完成下列功能:


1.  定义及输出。用结构体类型数据及其赋初值的方法把学生的数据送到结构体数组中(第一个数据用自己的真实数据,其它数据自定,但注意要有符合第4个功能两项统计输出的数据。),然后把它们打印出来。


2.  计算并排序。计算每个学生三门课程的总分(sum,单精度)及平均分(aver,单精度,输出一位小数),将包括所有数据的结构体数组元素按总分从大到小的顺序排序打印出来。


3.  查找。任意输入一位学生的姓名,打印出他的所有数据。要求能多次查找。


4.  统计。统计输出不及格的学生名单和对应的课程。统计输出有2门以上(含2门)课程不及格的学生名单,作为留级的学生。


  我不是想抄作业,我只想知道怎么做查找那部分,我试过很多方法了,都不行。有谁能帮帮我吗??


高手,在吗??》有 10 条评论

  1. ybdesire 说:

    把你编的程序都发上来,要不没法给你看啊!!!!!

  2. Nick 说:

    #include<stdio.h>

    #define N10

    < ?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

       struct student

       {

       char num[11];

       char name [25];

       char sex;

       int age;

       float score[3];

       float sum;

       float aver;

       }stu[10]={“3106005746″,”Huang huan”,’M',20,{90,90,90},0,0,

                 “0000000001″,”huang Lei”,’M',20,{59,59,90},0,0,

                 “0000000002″,”huang Ming”,’F',20,{89,70,90},0,0,

                 “0000000003″,”Jin Ling”,’F',20,{20,84,30},0,0,

                 “0000000004″,”Li Ming”,’F',20, {89,50,90},0,0,

                 “0000000005″,”Li Hua”,’F',20, {20,40,50},0,0,

                 “0000000006″,”Li Ming”,’F',20, {95,84,85},0,0,

                 “0000000007″,”Li chao”,’F',20, {60,60,70},0,0,

                 “0000000008″,”Li jia”,’F',20, {96,84,90},0,0,

                 “0000000009″,”Li shan you”,’F',20,{89,84,90},0,0};

     

          void main()

      {

       int p;

       float Sum(float x,float y,float z); 

     

       int h;

       float Aver(float X,float Y,float Z);

     int a,j,t; 

     

       { int i;

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

      { printf(“\nNo.:%11s  name:%-11s  sex:%c  age:%d\nmatch:%< ?:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />3.1f   English:%3.1f   computer:%3.1f\n “,stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].score[0],stu[i].score[1],stu[i].score[2]);}

       

      }

    printf(“\n\n”);

     

     stu[0].sum=Sum(stu[0].score[0],stu[0].score[1],stu[0].score[2]);

     stu[1].sum=Sum(stu[1].score[0],stu[1].score[1],stu[1].score[2]);

     stu[2].sum=Sum(stu[2].score[0],stu[2].score[1],stu[2].score[2]);

     stu[3].sum=Sum(stu[3].score[0],stu[3].score[1],stu[3].score[2]);

     stu[4].sum=Sum(stu[4].score[0],stu[4].score[1],stu[4].score[2]);

     stu[5].sum=Sum(stu[5].score[0],stu[5].score[1],stu[5].score[2]);

     stu[6].sum=Sum(stu[6].score[0],stu[6].score[1],stu[6].score[2]);

     stu[7].sum=Sum(stu[7].score[0],stu[7].score[1],stu[7].score[2]);

     stu[8].sum=Sum(stu[8].score[0],stu[8].score[1],stu[8].score[2]);

     stu[9].sum=Sum(stu[9].score[0],stu[9].score[1],stu[9].score[2]);

     

     

    printf(“huang hun’sum:\n%f\nhuang Lei’sum:\n%f\nhuang Ming’sum:\n%f\nJin Ling’sum:\n%f\nLi Ming’sum:\n%f\nLi Hua’sum:\n%f\nLi Ming’sum:\n%f\nLi chao’sum:\n%f\nLi jia’sum:\n%f\nLi shan you’sum:\n%f\n\n”,stu[0].sum,stu[1].sum,stu[2].sum,stu[3].sum,stu[4].sum,stu[5].sum,stu[6].sum,stu[7].sum,stu[8].sum,stu[9].sum);

    stu[0].aver=Aver(stu[0].score[0],stu[0].score[1],stu[0].score[2]);

    stu[1].aver=Aver(stu[1].score[0],stu[1].score[1],stu[1].score[2]);

    stu[2].aver=Aver(stu[2].score[0],stu[2].score[1],stu[2].score[2]);

    stu[3].aver=Aver(stu[3].score[0],stu[3].score[1],stu[3].score[2]);

    stu[4].aver=Aver(stu[4].score[0],stu[4].score[1],stu[4].score[2]);

    stu[5].aver=Aver(stu[5].score[0],stu[5].score[1],stu[5].score[2]);

    stu[6].aver=Aver(stu[6].score[0],stu[6].score[1],stu[6].score[2]);

    stu[7].aver=Aver(stu[7].score[0],stu[7].score[1],stu[7].score[2]);

    stu[8].aver=Aver(stu[8].score[0],stu[8].score[1],stu[8].score[2]);

    stu[9].aver=Aver(stu[9].score[0],stu[9].score[1],stu[9].score[2]);

    printf(“huang hun’aver:\n%3.1f\nhuang Lei’aver:\n%3.1f\nhuang Ming’aver:\n%3.1f\nJin Ling’aver:\n%3.1f\nLi Ming’aver:\n%3.1f\nLi Hua’aver:\n%3.1f\nLi Ming’aver:\n%3.1f\nLi chao’aver:\n%3.1f\nLi jia’aver:\n%3.1f\nLi shan you’aver:\n%3.1f\n\n”,stu[0].aver,stu[1].aver,stu[2].aver,stu[3].aver,stu[4].aver,stu[5].aver,stu[6].aver,stu[7].aver,stu[8].aver,stu[9].aver);

     

    for(a=0;a<9;a++)

     {for(j=0;j<9-a;j++)

      if(stu[j].sum<stu[j+1].sum)

       {

        t=stu[j].sum;

        stu[j].sum=stu[j+1].sum;

        stu[j+1].sum=t;

       }

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

       printf(“\nNo.:%11s name:%-11s sex:%c age:%d  \nmatch:%3.1f English:%3.1f computer:%3.1f sum:%f aver:%3.1f\n\n”,stu[j].num,stu[j].name,stu[j].sex,stu[j].age,stu[j].score[0],stu[j].score[1],stu[j].score[2],stu[j].sum,stu[j].aver);

      }

      for(p=0;p<10;p++)

     {

         if(stu[p].score[0]<60)

             printf(“\n  %s match:%3.1f“,stu[p].name,stu[p].score[0]);

         if(stu[p].score[1]<60)

             printf(“\n  %s English:%3.1f“,stu[p].name,stu[p].score[1]);

         if(stu[p].score[2]<60)

             printf(“\n  %s computer:%3.1f“,stu[p].name,stu[p].score[2]);

     }printf(“\nNo pass:”);

      for(p=0;p<10;p++)

         if((stu[p].score[0]<60)&&(stu[p].score[1]<60)||(stu[p].score[1]<60)&&(stu[p].score[2]<60)||(stu[p].score[0]<60)&&(stu[p].score[2]<60))

         printf(“\n%s”,stu[p].name);

        

     

     

     

    }

     

     

    float Sum(float x,float y,float z)

    {

    float m;

    m=x+y+z;

    return(m);

    }

     

     

    float Aver(float X,float Y,float Z)

    {

    float M;

    M=(X+Y+Z)/3;

    return(M);

    }

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  3. linder99 说:

    for(a=0;a<9;a++)

     {for(j=0;j<9-a;j++)

      if(stu[j].sum<stu[j+1].sum)

       {

        t=stu[j].sum;

        stu[j].sum=stu[j+1].sum;

        stu[j+1].sum=t;

       }

    你这里只实现了总分的交换,没有真正实现排序

    应该是

    struct student max;  /*max请在定义struct student的地方定义*/

    for(a=0;a<9;a++)

     {for(j=0;j<9-a;j++)

      if(stu[j].sum<stu[j+1].sum)

       {

        max=stu[j];

        stu[j]=stu[j+1];

        stu[j+1]=max;}

    这样才真正把stu这个结构体数组排序

  4. linder99 说:

    这样不知道算查找没  

       char ch;

       j=1;

       while(j==1)

       {

        j=0;

        printf(“You want to search?Please enter (Y or N) to continue!”);

       if((ch=getchar())==Y)

       {

          j=1;

          char names[25];

          printf(“please input the student’s name:\n”);

          scant(“%s”,names);

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

         

          if(stu[i].name[25]==names[25])

          {

            ptintf(“%s    %s    %c    %d    %f    %f    %f    %f    %f”,stu[i].num,stu[i].name,&stu[i].sex,&stu[i].age,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum,stu[i].aver);

           i=10;

         }

      }

    }

  5. linder99 说:

    http://www.vcgood.com/bbs/forum_posts.asp?TID=1621&PN=1

    我在这里写了个差不多的,自己去看下

  6. Nick 说:

    多谢大哥的热心帮忙!!!

  7. Nick 说:

    [QUOTE=linder99]

    for(a=0;a<9;a++)

     {for(j=0;j<9-a;j++)

      if(stu[j].sum<stu[j+1].sum)

       {

        t=stu[j].sum;

        stu[j].sum=stu[j+1].sum;

        stu[j+1].sum=t;

       }

    你这里只实现了总分的交换,没有真正实现排序

    应该是

    struct student max;  /*max请在定义struct student的地方定义*/

    for(a=0;a<9;a++)

     {for(j=0;j<9-a;j++)

      if(stu[j].sum<stu[j+1].sum)

       {

        max=stu[j];

        stu[j]=stu[j+1];

        stu[j+1]=max;}

    这样才真正把stu这个结构体数组排序

    [/QUOTE]

    哦,难怪我运行的时候总得不到需要的效果,但这个max应该怎么定义啊,可以说一下吗,大哥??

  8. linder99 说:

    你程序的开始

    struct student

       {

       char num[11];

       char name [25];

       char sex;

       int age;

       float score[3];

       float sum;

       float aver;

       }max,stu[10]={“3106005746  /* (看好这行)*/

  9. Nick 说:

    哦……原来如此………..

    谢谢大哥的帮忙,小弟在这里谢过啦!!!

  10. Nick 说:

    #include<stdio.h>
    #define N10

       struct student
       {
       char num[11];
       char name [25];
       char sex;
       int age;
       float score[3];
       float sum;
       float aver;
       }stu[10]={“3106005746″,”huanghuan”,’M',20,{90,90,90},0,0,
                 “3821469781″,”huanglei”,’M',21,{59,59,90},0,0,
                 “3821469872″,”huangming”,’F',17,{89,70,90},0,0,
                 “3569821453″,”jinling”,’F',20,{20,84,30},0,0,
                 “3201469874″,”liming”,’F',20, {89,50,90},0,0,
                 “3023651205″,”lihua”,’F',48, {20,40,50},0,0,
                 “3000254686″,”liming”,’F',20, {95,84,85},0,0,
                 “3502360477″,”lichao”,’F',20, {60,60,70},0,0,
                 “3410369808″,”lijia”,’F',20, {96,84,90},0,0,
                 “3021023659″,”lishanyou”,’F',19,{89,84,90},0,0};

           main()
      {
       int i,c,g,p,G[10],H[10];
    char u;
       float Sum(float x,float y,float z); 

       int h,k;
       float Aver(float X,float Y,float Z);
     int a,j,t,b;
      clrscr();
      printf(“    At 0, Of the total student . \n    At 1,according to an output of the students score.\n    At 2,according to an output of the students average.\n    At 3,increasing ranked by score.\n    At 4,output failing students and the failure of the subjects.\n    At 5,output not advancing to the students.\n”);             
     
     
     
     
     
      scanf(“%d”,&b);
        
       
       
      
       { int i;
       if(b==0)
      {
       for(i=0;i<10;i++)
      { printf(“\nNo.:%11s  name:%-11s  sex:%c  age:%d\nmatch:%3.1f   English:%3.1f   computer:%3.1f\n “,stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
       
     }printf(“      At 0 RETURN:”);
    scanf(“%d”,&c);
    if(c==0)
    {return(main());}
    }

    }

     stu[0].sum=Sum(stu[0].score[0],stu[0].score[1],stu[0].score[2]);
     stu[1].sum=Sum(stu[1].score[0],stu[1].score[1],stu[1].score[2]);
     stu[2].sum=Sum(stu[2].score[0],stu[2].score[1],stu[2].score[2]);
     stu[3].sum=Sum(stu[3].score[0],stu[3].score[1],stu[3].score[2]);
     stu[4].sum=Sum(stu[4].score[0],stu[4].score[1],stu[4].score[2]);
     stu[5].sum=Sum(stu[5].score[0],stu[5].score[1],stu[5].score[2]);
     stu[6].sum=Sum(stu[6].score[0],stu[6].score[1],stu[6].score[2]);
     stu[7].sum=Sum(stu[7].score[0],stu[7].score[1],stu[7].score[2]);
     stu[8].sum=Sum(stu[8].score[0],stu[8].score[1],stu[8].score[2]);
     stu[9].sum=Sum(stu[9].score[0],stu[9].score[1],stu[9].score[2]);

     if(b==1)
     

    {printf(“huang hun’sum:\n%f\nhuang Lei’sum:\n%f\nhuang Ming’sum:\n%f\nJin Ling’sum:\n%f\nLi Ming’sum:\n%f\nLi Hua’sum:\n%f\nLi Ming’sum:\n%f\nLi chao’sum:\n%f\nLi jia’sum:\n%f\nLi shan you’sum:\n%f\n\n”,stu[0].sum,stu[1].sum,stu[2].sum,stu[3].sum,stu[4].sum,stu[5].sum,stu[6].sum,stu[7].sum,stu[8].sum,stu[9].sum);
    printf(“      At 0 RETURN:”);
    scanf(“%d”,&c);

    if(c==0)
    return(main());}

     

    stu[0].aver=Aver(stu[0].score[0],stu[0].score[1],stu[0].score[2]);
    stu[1].aver=Aver(stu[1].score[0],stu[1].score[1],stu[1].score[2]);
    stu[2].aver=Aver(stu[2].score[0],stu[2].score[1],stu[2].score[2]);
    stu[3].aver=Aver(stu[3].score[0],stu[3].score[1],stu[3].score[2]);
    stu[4].aver=Aver(stu[4].score[0],stu[4].score[1],stu[4].score[2]);
    stu[5].aver=Aver(stu[5].score[0],stu[5].score[1],stu[5].score[2]);
    stu[6].aver=Aver(stu[6].score[0],stu[6].score[1],stu[6].score[2]);
    stu[7].aver=Aver(stu[7].score[0],stu[7].score[1],stu[7].score[2]);
    stu[8].aver=Aver(stu[8].score[0],stu[8].score[1],stu[8].score[2]);
    stu[9].aver=Aver(stu[9].score[0],stu[9].score[1],stu[9].score[2]);
     if(b==2)
     

    {printf(“huang hun’aver:\n%5.1f\nhuang Lei’aver:\n%5.1f\nhuang Ming’aver:\n%5.1f\nJin Ling’aver:\n%3.1f\nLi Ming’aver:\n%3.1f\nLi Hua’aver:\n%3.1f\nLi Ming’aver:\n%3.1f\nLi chao’aver:\n%3.1f\nLi jia’aver:\n%5.1f\nLi shan you’aver:\n%3.1f\n\n”,stu[0].aver,stu[1].aver,stu[2].aver,stu[3].aver,stu[4].aver,stu[5].aver,stu[6].aver,stu[7].aver,stu[8].aver,stu[9].aver);
    printf(“      At 0 RETURN:”);
    scanf(“%d”,&c);
    if(c==0)
    return(main());}

     
     

    if(b==3)
    {
     for(k=0;k<10;k++)
     {G[k]=stu[k].sum;}
    for(a=0;a<9;a++)
     {for(j=0;j<9-a;j++)
      if(G[j]>G[j+1])
       {
        t=G[j];
        G[j]=G[j+1];
        G[j+1]=t;
       }
         for(i=0;i<10;i++)
         {
          if(G[10-a]==stu[i].sum)
       {printf(“\nNo.:%11s name:%-11s sex:%c age:%d  \nmatch:%3.1f English:%3.1f computer:%3.1f sum:%f aver:%3.1f\n\n”,stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum,stu[i].aver);}
    }}printf(“      At 0 RETURN:”);
    scanf(“%d”,&c);
    if(c==0)
    return(main());
      }

    if(b==4)
     

    {
      for(p=0;p<10;p++)
     {
         if(stu[p].score[0]<60)
            {printf(“  %s match:%3.1f\n”,stu[p].name,stu[p].score[0]);}
         if(stu[p].score[1]<60)
            {printf(“  %s English:%3.1f\n”,stu[p].name,stu[p].score[1]);}
         if(stu[p].score[2]<60)
            {printf(“  %s computer:%3.1f\n”,stu[p].name,stu[p].score[2]);}
      }
    printf(“      At 0 RETURN:”);
    scanf(“%d”,&c);
    if(c==0)

    return(main());
     
    }
     
      if(b==5)
      {

      {printf(“\nNo pass:\n”);
      for(p=0;p<10;p++)
         {if((stu[p].score[0]<60)&&(stu[p].score[1]<60)||(stu[p].score[1]<60)&&(stu[p].score[2]<60)||(stu[p].score[0]<60)&&(stu[p].score[2]<60))
         printf(“%s\n”,stu[p].name);}
       printf(“      At 0 RETURN:”);
       scanf(“%d”,&c);
       if(c==0)
       return(main());}}
    if(b==6)
     search() ;                /*该函数为无参函数,无返回值,其作用是按姓名查找相应的学生记录*/
    {char name[25];               /*定义一个字符数组name来存放要查找的学生的姓名*/
     int flag,sign=1;                 /*flag为一个标志,当其为1时表示找到指定的学生姓名,为0时则表示未找到,sign也为一个标志,来代表要不要退出查找*/
     int i;
     char r[2];                   /*用来后面存放用户的选择*/            
     clrscr();
     while(sign)
      {printf(“Please input the name of the person who you want to search for:\n”);     /*输入要查找的学生姓名*/
       scanf(“%s”,name);
       flag=0;                 
       clrscr();
                 
       for(i=0;i<10;i++)        
        {if(strcmp(stu[i].name,name)==0)
         {flag=1;
          printf(“\nNo.:%11s name:%-11s sex:%c age:%d  \nmatch:%3.1f English:%3.1f computer:%3.1f sum:%f aver:%3.1f\n\n”,stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum,stu[i].aver);}

          break;
         } }
       if(flag==0)printf(“Can’t find!\n”);
       printf(“Do you want to continue?(Y/N)\n”);   /*询问是否继续查找*/
       scanf(“%s”,r);
       if(r[0]==’N'||r[0]==’n')           /*当不想再继续查找时输入’N'或’n'*/
        sign=0;                           /*令其为0,结束上面的循环,即退出查找*/
      }
    };

    float Sum(float x,float y,float z)
    {
    float m;
    m=x+y+z;
    return(m);
    }

    float Aver(float X,float Y,float Z)
    {
    float M;
    M=(X+Y+Z)/3;
    return(M);
    }

    这是我最后写的,但最后输出那部不知到出什么问题了,输出的sum是0而aver则输出一大串负数,高手能帮我看看吗???还是感激!!!

     

     

     

     

     

     

     

留下一个回复