标题:求大哥们帮我看看这个程序啊,有没有什么语法错误
只看楼主
q714520540
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-5-30
结帖率:0
已结贴  问题点数:20 回复次数:2 
求大哥们帮我看看这个程序啊,有没有什么语法错误
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<mem.h>
#include<ctype.h>
#include<string.h>
typedef struct s1
{
long no;
char name[10];
    float score[3];
    float sum;
    float average;
    int order;
    struct s1 *next;
}STUDENT;

int menu_select()
{
char *menu[]={"**************MENU**************",
        "1. Enter list",
         "2. Delete arecord from list",
         "3. Print list",
         "4. Search record on number",
         "5. Save the file",
         "6. Load the file",
         "7. Computer the score",
      "8. Copy the file to new file",
         "9. Sort data",
         "10. modify data",
         "11. Append record to file",
         "12. Index on number",
        "13. total on number",
         "14. Quit"
        };
      char s[3];
      int c,i;
      clrscr();
      gotoxy(2,2);
      printf("Press any key enter menu......\n");
      clrscr();
      gotoxy(1,1);
      textcolor(1);
      textbackground(0);
      gotoxy(10,2);
      putch(0xc9);
      for(i=1;i<54;i++)
          putch(0xcd);
      putch(0xbb);
      for(i=3;i<20;i++)         
      {
gotoxy(10,i);
putch(0xba);
           gotoxy(64,i);
putch(0xba);
        }
        gotoxy(10,20);
putch(0xc8);
        for(i=1;i<54;i++)
            putch(0xcd);
        putch(0xbc);   
        window(11,3,63,19);
        clrscr();
        for(i=0;i<15;i++)
        {
gotoxy(10,i+1);
              cprintf("%s",menu[i]);
          }
          textbackground(0);
          window(1,1,80,50);
          gotoxy(20,21);
          do
          {
printf(" Enter your choice (0-14):");
               scanf("%s",s);
               c=atoi(s);
          }
          while(c<0||c>14);
          return c;
}


int menu_select2()
{
char *menu[]={"**************MENU**************",
                "1.  The student who fail in test",
                "2.  The first to fifth in grade",
                "3.  Class average on subject",
                "4.  Class total record",
                "5.  Quit"};
      char s[3];
      int c,i;
      clrscr();
      gotoxy(2,2);
      printf("Press any key enter menu\n");   
      clrscr();
      gotoxy(1,1);
      textcolor(1);
      textbackground(0);
      gotoxy(10,2);
      putch(0xc9);
      for(i=1;i<54;i++)
      putch(0xcd);
      putch(0xbb);
      for(i=3;i<12;i++)
      {
gotoxy(10,i);
putch(0xba);
                gotoxy(64,i);
putch(0xba);
      }
          gotoxy(10,12);
putch(0xc8);
          for(i=1;i<54;i++)
                putch(0xcd);
            putch(0xbc);
          window(11,3,63,11);
          clrscr();
          for(i=0;i<6;i++)
          {
gotoxy(10,i+1);
                cprintf("%s",menu[i]);
          }
          textbackground(0);
          window(1,1,80,50);
          gotoxy(20,13);
          do
          {
printf(" Enter your choice (1-5):");
                scanf("%s",s);
                c=atoi(s);
          }
          while(c<0||c>14);
          return c;
}

STUDENT *creat()
{
STUDENT *head,*p,*s;float y,z,w;
     long x; int i;
     char na[15];
             head=NULL;
         clrscr();
          printf("Please input student's number:");
            scanf("%ld",&x);
            printf("Please input name:");
            scanf("%s",na);
            printf("Please input sc1:");
            scanf("%f",&y);
            printf("Please input sc2:");
            scanf("%f",&z);
            printf("Please input sc3:");
            scanf("%f",&w);
          while(x!=0)
          {
s=(STUDENT*)malloc(sizeof(STUDENT));
                s->no=x;
                for(i=0;i<10;i++)
                {
s->name[i]=na[i];}
                    s->score[0]=y;
                    s->score[1]=z;
                    s->score[2]=w;
                    s->sum=0;
                    s->average=0;
                    s->order=0;
                    if(head==NULL)
{
head=s;p=head;
}
               else
{
                     p->next=s;
                  p=s;
}
                    printf("Please input student's number:");
                    scanf("%ld",&x);
                     if(x==0)
break;
                    printf("Please input name:");
                    scanf("%s",na);
                    printf("Please input sc1:");
                    scanf("%f",&y);
                    printf("Please input sc2:");
                    scanf("%f",&z);
                    printf("Please input sc3:");
                    scanf("%f",&w);
              }
              p->next=NULL;
              return(head);
}

void showTable1()
{
clrscr();
gotoxy(10,3);
printf("***************STUDENT INFORMATION***************");
gotoxy(1,4);
printf("-----------------------------------------------------------------------------\n");
gotoxy(1,5);
printf("|rec|  no  |  Name | sc1 | sc2 | sc3 | sum | average |order|\n");
}

void showTable2()
{
printf("-----------------------------------------------------------------------------\n");
}

STUDENT *del(STUDENT *head)
{
STUDENT *p,*q;
     long n;int flag=0;
      clrscr();
      p=head;
      q=p;p=p->next;
      printf("Please input the number you want to delete:");
      scanf("%ld",&n);
      if(q->no==n)  {head=p;free(q);flag=1;}
      while(p!=NULL)
      {
if(p->no==n)
                 {
q->next=p->next;
               free(p);
flag=1;break;
                 }
                p=p->next;
                 q=q->next;
      }
      if(flag==0)
       printf("Not find!!!\n");
           printf("Press any key to return......\n");
           getch();
           return(head);
}

void display(STUDENT *head)
{
STUDENT *p; int i=1;
      p=head;
      clrscr();
      showTable1();
      while(p!=NULL)
{
printf("|%3d|%10ld|%12s|  %5.1f|  %5.1f|  %5.1f|  %5.1f| %8.1f|%5d|\n",i,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
                p=p->next;
                i++;
      }
      showTable2();
      printf("Press any key to return......\n");
      getch();
}

void search(STUDENT*head)
{
long str; int i; int rec=1;
      STUDENT *p;p=head;
      clrscr();
      printf("Please input the number you want to get :");
      scanf("%ld",&str);
      while(p!=NULL)
      {
if(str==p->no)
i=1;
                p=p->next;
      }
      if(i==1)
      {
showTable1();    printf("|%3d|%10ld|%12s|  %5.1f|  %5.1f|  %5.1f|  %5.1f| %8.1f|%5d|\n",rec,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
                showTable2();
      }
      else
printf("Not find!");
      printf("Press any key to return!");
      getch();
}

void save(STUDENT *head)
{
FILE *fp;STUDENT *p;
      clrscr();
      if((fp=fopen("e:kesheyyp","wb"))==NULL)
       {
printf("Can't open the file!\n");
                 exit(1);
       }
       printf("\n********Saving file********\n");
       p=head;
       while(p!=NULL)
       {
fwrite(p,sizeof(STUDENT),1,fp);
                 p=p->next;
       }
       fclose(fp);
       printf("Save success!!!\n");
}

STUDENT     *load()
{
STUDENT     *p,*q,*head;
      FILE *fp;
      clrscr();
      head=NULL;
       if((fp=fopen("e:kesheyyp","rb"))==NULL)
         {
printf("Can't open the file!\n");
           exit(1);
         }
      while(!feof(fp))
      {
q=(STUDENT *)malloc(sizeof(STUDENT));
                if(fread(q,sizeof(STUDENT),1,fp)!=1)
                break;
                if(head==NULL)
{
head=q;p=head;
}
           else
{
p->next=q;p=q;
}
                p=q;
      }
      p->next=NULL;
      fclose(fp);
      printf("load success!");
      return(head);
}

STUDENT *computer(STUDENT *head)
{
STUDENT     *p;int i;
      p=head;
      while(p!=NULL)
      {
for(i=0,p->sum=0;i<3;i++)
            p->sum+=p->score[i];
                p->average=p->sum/3.0;
                p=p->next;
          }
          return(head);
}

void copynew(STUDENT*head)
{
FILE *fp;STUDENT *p;
      int i;
      clrscr();
      printf("press class number you want to save:(1,2)");
      scanf("%d,i");
      switch(i)
      {
case 1:
                        if((fp=fopen("e:kesheclass1.dat","wb"))==NULL)
                        {
printf("Can't open the file!\n");
                             exit(1);
                        }
                         printf("\n Saving file......\n");
                         p=head;
                         while(p!=NULL)
                         {
fwrite(p,sizeof(STUDENT),1,fp);
                       p=p->next;
                         }
                         fclose(fp);
                         printf("Save success!!!\n");
break;
                 case 2:
                      if((fp=fopen("e:kesheclass2.dat","wb"))==NULL)
                      {
printf("Can't open the file!\n");
                          exit(1);
                      }
                      printf("\n Saving file......\n");
                      p=head;
                      while(p!=NULL)
                      {
fwrite(p,sizeof(STUDENT),1,fp);
                        p=p->next;
                      }
                      fclose(fp);
                      printf("Save success!!!\n");
break;
            }
}

void modify(STUDENT*head)
{
STUDENT *p;float y,z,w;
     long x,str; int i;
     char na[15];
     clrscr();
      p=head;
      printf("Please input the number you want to modify :");
      scanf("%ld",&str);
      while(p!=NULL)
      {
if(str==p->no)
               {
i=1;
                    printf("Please input student's new number:");
                    scanf("%ld",&x);
                    printf("Please input new name:");
                    scanf("%s",na);
                    printf("Please input new score1:");
                    scanf("%f",&y);
                    printf("Please input new score2:");
                    scanf("%f",&z);
                    printf("Please input new score3:");
                    scanf("%f",&w);
                    p->no=x;
                   p->name[i]=na[i];
                    p->score[0]=y;
                    p->score[1]=z;
                    p->score[2]=w;
                    p->sum=0;
                   p->average=0;
                    p->order=0;
               }
               p=p->next;
          }
          if(i==1)
              printf("modify success!\n");
          else
printf("Not find!");
          printf("Press any key to return!");
      getch();
}

STUDENT *append(STUDENT*head)
{
STUDENT *p,*s; long x; int i;
      float y,z,w;
      char na[10];
      clrscr();
      p=head;
      while(p->next!=NULL)
      {
p=p->next;
      }
        printf("Please input student's number:");
        scanf("%ld",&x);
        printf("Please input name:");
        scanf("%s",na);
        printf("Please input score1:");
        scanf("%f",&y);
        printf("Please input score2:");
        scanf("%f",&z);
        printf("Please input score3:");
        scanf("%f",&w);
      while(x!=0)
      {
s=(STUDENT*)malloc(sizeof(STUDENT));
                s->no=x;
                for(i=0;i<10;i++)
                {
s->name[i]=na[i];}
                    s->score[0]=y;
                    s->score[1]=z;
                    s->score[2]=w;
                    s->sum=0;
                    s->average=0;
                    s->order=0;
                    p->next=s;
                    p=s;
                   printf("Please input student's number:");
                    scanf("%ld",&x);
                     if(x==0) break;
                        printf("Please input name:");
                    scanf("%s",na);
                    printf("Please input score1:");
                    scanf("%f",&y);
                    printf("Please input score2:");
                    scanf("%f",&z);
                    printf("Please input score3:");
                    scanf("%f",&w);
              }
              p->next=NULL;
              return(head);
}

STUDENT *sort(STUDENT *head)
{
       int i=0;
       STUDENT *p,*q,*t,*r;
       r=head->next;
       head->next=NULL;
       while(r!=NULL)
       {
t=r;
              r=r->next;
              p=head;
              q=head;
              while(t->sum<p->sum&&p!=NULL)
              {
q=p;
                    p=p->next;
              }
              if(p==q)
              {
t->next=p;
                    head=t;
              }
              else
              {
t->next=p;
                    q->next=t;
              }
       }
       p=head;
       while(p!=NULL)
         {
i++;
      p->order=i;
      p=p->next;
   }
   printf("sort sucess!!!\n");
   return (head);
}

void fail(STUDENT *head)
{
int i,flag=0; int rec=1;
        STUDENT *p;p=head;
clrscr();
      printf("Please input the subject number(1,2,3) :");
      scanf("%d",&i);
      showTable1();
      while(p!=NULL)
      {
if(p->score[i-1]<60)
               {
flag=1;     printf("|%3d|%10ld|%12s|  %5.1f|  %5.1f|  %5.1f|  %5.1f| %8.1f|%5d|\n",rec,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
                     rec++;
               }
                 p=p->next;
          }
           showTable2();
          if(flag==0)
              printf("No one fail in the subject!");
          printf("\nPress any key to return!");
          getch();
}

void five(STUDENT *head)
{
STUDENT *p;int i;
     p=sort(head);
     showTable1();
     for(i=0;i<5;i++)
{
printf("|%3d|%10ld|%12s|  %5.1f|  %5.1f|  %5.1f|  %5.1f| %8.1f|%5d|\n",i++,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
              p=p->next;  
         }
         showTable2();
         printf("\nPress any key to return!");
         getch();
}

void average(STUDENT*head)
{
float sum=0,ave;int i,j,t=0;
         STUDENT *p;
         printf("which class you want to print(1,2)");
         scanf("%d",&i);
             printf("which subject you want to print(1,2,3)");
         scanf("%d",&j);
         switch(i)
         {
case 1:
{
p=head;
                      while(p!=NULL)
                      {
if(p->no>206050500&&p->no<206050600)
                           {
sum+=p->score[j-1];
                                t++;
                           }
                           p=p->next;
                      }
break;
                 }
                   case 2:
{
p=head;
                       while(p!=NULL)
                       {
if(p->no>206050600&&p->no<206050700)
                            {
sum+=p->score[j-1];
                             t++;
                            }
                            p=p->next;
                       }
break;
                  }
               }
               clrscr();
               ave=sum/t;
               printf("class%d sub%d average is: %.2f",i,j,ave);
               printf("\nPress any key to return!");
               getch();
 }

void classscore(STUDENT*head)
{
int i,rec=1;
     STUDENT *p;
     printf("which class you want to print(1,2)");
     scanf("%d",&i);
     printf("class%d\n",i);
     showTable1();
     switch(i)
     {
case 1:
{
p=head;
                      while(p!=NULL)
                      {
if(p->no>206050500&&p->no<206050600)       {
printf("|%3d|%10ld|%12s|  %5.1f|  %5.1f|  %5.1f|  %5.1f| %8.1f|%5d|\n",rec,p->no,p->name,        p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
                                rec++;
                               }
                               p=p->next;
                      }
break;
                 }
                   case 2:
{
p=head;
                      while(p!=NULL)
                      {
if(p->no>206050600&&p->no<206050700)
{
printf("|%3d|%10ld|%12s|  %5.1f|  %5.1f|  %5.1f|  %5.1f| %8.1f|%5d|\n",rec,p->no,p->name,        p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
                            rec++;
                           }
                           p=p->next;
                      }
break;
                 }
       }
       showTable2();
       printf("\nPress any key to return!");
       getch();
}

void index(STUDENT *head)
{
int i;
      clrscr();
      gotoxy(2,24);
      printf("Press any key enter menu\n");
      getch();
      for(;;)
      {
switch(menu_select2())
                 {
case 1: fail(head);break;
                case 2: five(head);break;
                case 3: average(head);break;
                case 4: classscore(head);break;
                case 5: return;
                 }
          }
}

void main()
{
int i;
      STUDENT *head;
      clrscr();
      gotoxy(2,24);
      printf("Press any key enter menu\n");
      getch();
      for(;;)
      {
switch(menu_select())
                 {
                case 1: head=creat();break;
                case 2: head=del(head);break;
                case 3: display(head);break;
                case 4: search(head);break;
                case 5: save(head);break;
                case 6: head=load();break;
                case 7: computer(head);break;
                case 8: copynew(head);break;
                case 9: head=sort(head);break;
                case 10:modify(head);break;
                  case 11:head=append(head);break;
                case 12:index(head);break;
                case 13:
                case 14:exit(0);
搜索更多相关主题的帖子: average include number record Enter 
2011-05-31 08:33
Pirelo
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:118
专家分:550
注 册:2011-1-28
得分:10 
通过人脑编译,我发现LZ的main函数没copy完
2011-05-31 21:55
爱德华
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:183
专家分:536
注 册:2011-5-29
得分:10 

算法,数据结构,windows核心编程.
2011-06-06 15:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-341473-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.066744 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved