| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 554 人关注过本帖
标题:昨天晚上能成功运行的程序,今天不能运行了,麻烦大家帮忙看一下(参考了论 ...
取消只看楼主 加入收藏
丁宝青
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2009-12-30
结帖率:75%
收藏
已结贴  问题点数:8 回复次数:0 
昨天晚上能成功运行的程序,今天不能运行了,麻烦大家帮忙看一下(参考了论坛里的学生成绩管理系统)
#include <stdio.h>
#include <string.h>
struct student
{   int num[11];
    char name[20];
    char sex[3];
    int  English[10];
    int  Math[10];
    int  Physics[10];
    int  C[10];
}   stu[10];
    int enter (struct student stu []);
    void menu2();
    void menu();
    void scan();
    void print();
    void scanname();
    void scanno();
    void change();
    void menu3();
    void change();
    void shunxu();
    void delete();
    void save(struct student stu[]);
    void load(struct student stu[]);
    int j=0;
    int main ()
    { char a;
     menu ();
     a=getchar();
     switch(a)
    {   case '1' :system("cls"); enter(stu);break;
        case '2' :system("cls");scan(stu);break;
        case '3' :system("cls");delete(stu);break;
        case '4' :system("cls");save(stu);break;
        case '5' :system("cls");shunxu(stu);break;
        case '6' :system("cls");change(stu);break;
        case '7' :system("cls"); load(stu);break;
        case '8' :system("cls"); printf("Bye bye!\n");break;
        default:
       {system("cls");
        printf("Input wrong,please choose a new number:\n");}
        if(a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a=='7'||a=='8')
       break;
       else
       main();
    }  return 0;
}
void menu ()
{   printf("\t\t\t Students’score  management\n");
    printf("********************************************************************************\n");
    printf("Please choose one number:\n");
    printf("1.Input the student's information.\n");
    printf("2.Inquire student's information.\n");
    printf("3.Delete the student's information according to the number.\n");
    printf("4.Save the student's information.\n");
    printf("5.Rank according to the score.\n");
    printf("6.Change the information.\n");
    printf("7.Load the student's information.\n");
    printf("8.Exit!\n");
    printf("********************************************************************************\n");
    }
  int enter(struct student stu[])
    {   int i,x,k;
        for(i=j;i<=j;i++)
       {    j++;
            printf("**********************Input the information*********************\n");
            printf("The \t%dth  student:\n",j);
            printf("Number:\n");
            scanf("%d",&stu[i].num);
       for(x=1;x<=j;x++)
            {if(stu[x].num==stu[i].num)
               {printf("This number has been saved ,please input another number!\n");
                printf("The  %dth  student:\n",j);
                printf("Number:\n");
                scanf("%d",&stu[i].num);
                i--;
                x--;
                break;}
            }
            printf("Name:\n");
            scanf("%s",stu[i].name);
            printf("Sex(m/w):\n");
            scanf("%s",&stu[i].sex);
            printf("English score:\n");
           scanf("%d",stu[i].English);
            printf("Math score:\n");
            scanf("%d",stu[i].Math);
            printf("Physics score:\n");
            scanf("%d",stu[i].Physics);
            printf("C score:\n");
            scanf("%d",stu[i].C);
            printf("\n");
            printf("**************Input A back to main menu or input Enter for logging the next number************\n");
           getchar();
            if((k=getchar())=='A')
            {  system ("cls");
               main();
               break;}
    } return 0;
}
void menu2()
{   printf("*********************Inquire the student's information***********************\n");
    printf("Please choose one number from 1 to 3:\n");
    printf("1.Display all of the students’ information\n");
    printf("2.Inquire the information according to the Number\n");
    printf("3.Inquire the information according to the Name\n");
    printf("4.Back to the main menu\n");
    printf("******************************************************************************\n");
}
    void scan()
 {      char b;
        menu2();
     b=getchar();
     switch(b)
    {   case '1':system("cls");print(stu);break;
        case '2':system("cls");scanno(stu);break;
        case '3':system("cls");scanname(stu);break;
        case '4':system("cls");main();break;
        default :system ("cls");
        printf("Please choose a new number:\n");
        scan();}
  }
  void print(struct student stu[])
    {   int n;
        if(j>0)
    {   for (n=0;n<j;n++)
        {
           {printf("Number:%d\n",stu[n].num);
            printf("Name:%s\n",stu[n].name);
            printf("Sex:%s\n",stu[n].sex);
            printf("English score:%d\n",stu[n].English);
            printf("Math score:%d\n",stu[n].Math);
            printf("Physics score:%d\n",stu[n].Physics);
            printf("C score:%d\n",stu[n].C);
            printf("*******************Inquire the student's information*****************\n");
            system("cls");
            }
            if(n==(j-1))
            {printf("\nThose are all of the students's information above!\n");
            system("cls");
            scan();}
        }
    }
        else
        {   system("cls");
            printf("\nThere is no information about this student,please input!\n");
            system("cls");
            scan();
            }
}
  void scanno(struct student stu[])
  { int i,a,z=-1;
    printf("\nPlease input the number of the student that you want to inquire:\n");
    scanf("%d",&a);
    for(i=0;i<j;i++)
    {if(a==stu[i].num)z=i;}
       if(z!=-1)
       {printf("Number:%d\n",stu[z].num);
        printf("Name:%s\n",stu[z].name);
        printf("Sex:%s\n",stu[z].sex);
        printf("English score:%d\n",stu[z].English);
        printf("Math score:%d\n",stu[z].Math);
        printf("Physics score:%d\n",stu[z].Physics);
        printf("C score:%d\n",stu[z].C);
        printf("**********************Inquire the student's information*********************\n");
        system("cls");
        scan();}
        else
        {    printf("There is no information about this student!Please enter any key to return\n");
             system("cls");
             scan();}
      }
    void scanname(struct student stu[])
     {  char a[20];
        int i,n,z=1;
        printf("\nInput the name that you want to inquire:\n");
        scanf("%s",a);
        for(i=0;i<j;i++)
        {if(!strcmp(a,stu[i].name))
         break;}
        n=(!strcmp(a,stu[i].name));
        if(n==1)
       {printf("Number:%d\n",stu[z].num);
        printf("Name:%s\n",stu[z].name);
        printf("Sex:%s\n",stu[z].sex);
        printf("English score:%d\n",stu[z].English);
        printf("Math score:%d\n",stu[z].Math);
        printf("Physics score:%d\n",stu[z].Physics);
        printf("C score:%d\n",stu[z].C);
        printf("**********************Inquire the student's information*********************\n");
        system("cls");
        scan();}
        else
        {   system("cls");
            printf("\nThere is no information about this student,please input!\n");
            system("cls");
            scan();}
      }
  void menu3()
    {printf("*******************Inquire the student's information***************************\n");
     printf("Please chose one number from 1 to 2:\n");
     printf("1.Inquire the information according to the Number\n");
     printf("2.Inquire the information according to the Name\n");
     printf("3.Back to the main menu\n");
     printf("******************************************************************************\n");}
  void change(struct student stu[])
    {   char b;
        menu3();
        b=getchar();
    switch(b)
    {  case '1':system("cls");
        {   int k,i,a,z=-1;
            printf("\nPlease enter the student's number which you want to chang:\n");
            scanf("%d",&a);
            for(i=0;i<j;i++)
            {if(a==stu[i].num)
                z=i;}
        if(z!=-1)
        {   printf("The information about the student:\n");
            printf("Number:%d\n",stu[z].num);
            printf("Name:%s\n",stu[z].name);
            printf("Sex(m/w):%s\n",stu[z].sex);
            printf("English score:%d\n",stu[z].English);
            printf("Math score:%d\n",stu[z].Math);
            printf("Physics score:%d\n",stu[z].Physics);
            printf("C score:%d\n",stu[z].C);
            printf("*********************Change the student's information*********************\n");
            printf("Please enter the student's information:\n");
            printf("Number:\n");
            scanf("%d",&stu[z].num);
            printf("Name:\n");
            scanf("%s",stu[z].name);
            printf("Sex:\n");
            scanf("%s",stu[z].sex);
            printf("English score:\n");
            scanf("%d",stu[z].English);
            printf("Math score:\n");
            scanf("%d",stu[z].Math);
            printf("Physics score:\n");
            scanf("%d",stu[z].Physics);
            printf("C score:\n");
            scanf("%d",stu[z].C);
            printf("\n");
            printf("******Information has been changed! Input A back to main menu,input Enter back to chang menu ******\n");
            getchar();
            if((k=getchar())=='A')
            {  system ("cls");
               main();
                break;}
           }
            if(z==-1);
           {system("cls");
            printf("\nThere is no information about this student,please input!\n");
            system("cls");
            change(stu);
           }
            system("cls");
            change(stu);
            break;}
        case '2': system("cls");
        {    char a[5];
        int i,n,k,z=-1;
        printf("\nPlease input the student's name that you want to chang:\n");
        scanf("%s",a);
        for(i=0;i<j;i++)
        {if(!strcmp(a,stu[i].name))
         break;
        }
        n=(!strcmp(a,stu[i].name));
        if(n==1)
        {   printf("The information about the student:\n");
            printf("Number:%d\n",stu[z].num);
            printf("Name:%s\n",stu[z].name);
            printf("Sex(m/w):%s\n",stu[z].sex);
            printf("English score:%d\n",stu[z].English);
            printf("Math score:%d\n",stu[z].Math);
            printf("Physics score:%d\n",stu[z].Physics);
            printf("C score:%d\n",stu[z].C);
            printf("**********************Change the student's information********************\n");
            printf("Please enter the student's information:\n");
            printf("Number:\n");
            scanf("%d",&stu[z].num);
            printf("Name:\n");
            scanf("%s",stu[z].name);
            printf("Sex:\n");
            scanf("%s",stu[z].sex);
            printf("English score:\n");
            scanf("%d",stu[z].English);
            printf("Math score:\n");
            scanf("%d",stu[z].Math);
            printf("Physics score:\n");
            scanf("%d",stu[z].Physics);
            printf("C score:\n");
            scanf("%d",stu[z].C);
            printf("\n");
            printf("****Information has been changed! Input A back to main menu,input Enter back to chang menu ****\n");
           getchar();
            if((k=getchar())=='A')
            {  system ("cls");
               main();
                break;}
        system("cls");
        change(stu);
        }
        else
          {  printf("There is no information about this student! Please enter any key to return\n");
             system("cls");
             change(stu);}
     }break;
        case '3': system("cls");main();break;
        default : system ("cls");
        printf("Input wrong,please chose a new number:\n");
        change(stu);
      }
   }
   void shunxu(struct student stu[])
    {   int i,k,n;
        char t[30];
        for(i=0;i<j;i++)
        for(k=0;k<j-i-1;k++)
        {
        if(stu[k].num>stu[k+1].num)
          { n=stu[k].num;
            stu[k].num=stu[k+1].num;
            stu[k+1].num=n;
            strcpy (t,stu[k].name);
            strcpy (stu[k].name,stu[k+1].name);
            strcpy(stu[k+1].name,t);
            strcpy(t,stu[k].sex);  
            strcpy (stu[k].sex,stu[k+1].sex);
            strcpy(stu[k+1].sex,t);
            strcpy(t,stu[k].English);
            strcpy (stu[k].English,stu[k+1].English);
            strcpy(stu[k+1].English,t);
            strcpy(t,stu[k].Math);
            strcpy(stu[k].Math,stu[k+1].Math);
            strcpy(stu[k+1].Math,t);
            strcpy(t,stu[k].Physics);
            strcpy(stu[k].Physics,stu[k+1].Physics);
            strcpy(stu[k+1].Physics,t);
            strcpy(t,stu[k].C);
            strcpy(stu[k].C,stu[k+1].C);
            strcpy(stu[k+1].C,t);
            }
        }
        printf("\nThe order has been ranged!\n");
        system("cls");
        main();
        }
   void delete(  )
    {    int i,z=-1,a,t;
         char k;
         printf("Please input the student's number:\n");
         scanf("%d",&a);
         for(i=0;i<j;i++)
        {if(a==stu[i].num)
         z=i;}
        if(z!=-1)
        {
         {  printf("********************! Delete the student's information !******************\n");
            printf("Information about the student:\n");
            printf("Number:%d\n",stu[z].num);
            printf("Name:%s\n",stu[z].name);
            printf("Sex(m/w):%s\n",stu[z].sex);
            printf("English score:%d\n",stu[z].English);
            printf("Math score:%d\n",stu[z].Math);
            printf("Physics score:%d\n",stu[z].Physics);
            printf("C score:%d\n",stu[z].C);
          for(;z<j;z++)
           {stu[z].num=stu[z+1].num;
            strcpy (stu[z].name,stu[z+1].name);
            strcpy (stu[z].sex,stu[z+1].sex);
            strcpy (stu[z].English,stu[z+1].English);
            strcpy (stu[z].Math,stu[z+1].Math);
            strcpy (stu[z].Physics,stu[z+1].Physics);
            strcpy (stu[z].C,stu[z+1].C);}
            j--;
             printf("\n***This information has been deleted,input Enter to ruturn***\n");}
           }
            else
            printf("\nThere is no information about this student!\n");
             system("cls");
            main ( );
            if(z==-1)
           {system("cls");
            printf("\nThere is no information about this student!\n");
            system("cls");
            main();}
        }
void save(struct student stu[])
{   FILE *fp;
      int i;
      if((fp=fopen("Students' information.txt","wb"))==NULL)
    {   printf("Can't open!\n");
        return;}
    else
    {   fwrite(stu,sizeof(struct student),j,fp);
        fclose(fp);
        printf("OK,Information has been saved,input any key to return.");
        getch();
        system("cls");
        main();
        }
}
void load(struct student stu[])
     {    FILE *fp;
          int i=0;
          if((fp=fopen("Student's information.txt","rb"))==NULL)
        {  printf("Can't open!\n");
           main();}
        else
      { if(fp!=NULL)
        while(!feof(fp))
            {   fread(stu+i,sizeof(struct student),1,fp);
                i++;}
        fclose (fp);
        i--;
        printf("Date load succeed,there is %d information has been loaded,input any key to return!",i);
        j = i;
        getch();
        system("cls");
        main();
      } return --i;
     }

[ 本帖最后由 丁宝青 于 2010-1-4 12:25 编辑 ]
搜索更多相关主题的帖子: 麻烦 学生 系统 
2010-01-04 12:24
快速回复:昨天晚上能成功运行的程序,今天不能运行了,麻烦大家帮忙看一下(参考 ...
数据加载中...
 
   



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

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