| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 696 人关注过本帖
标题:有问题!求改错!
只看楼主 加入收藏
pizilong
Rank: 2
来 自:安徽
等 级:论坛游民
帖 子:11
专家分:15
注 册:2010-10-10
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:10 
有问题!求改错!
就是有错,改不出来,帮帮忙!!
#include"stdio.h"
#include<string.h>
#include<stdlib.h>


#define N 30
struct student
{
 int num;
 char name[20];
 int age;
 int Math;
 int English;
 int Physical;
 long int sum;
}stu[N];

enter()
{int i,n;
 printf("How many students(1-%d)?:",N);
 scanf("%d",&n);
 printf("\nEnter data now\n\n");
 for(i=0;i<n;i++)
  {printf("\n Input %dth student record.\n",i+1);
   input(i);
  }
 if(i!=0) save(n);
 printf_back();  /* browse or back */
}

add()
{int i,n,m,k;
 FILE *fp;
 n=load();
 printf("How many students are you want to add(1-%d)?:",N-n);
 scanf("%d",&m);
 k=m+n;
 for(i=n;i<k;i++)
  {printf("\n Input %dth student record.\n",i+1);
   input(i);
  }
 if((fp=fopen("score.txt","ab"))==NULL)
  {printf("Cannot open file.\n");
  }
 for(i=n;i<k;i++)
  if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
   printf("file write error.\n");
 fclose(fp);
 printf_back();
}

/* insert()
{int n,c;
 struct student s;
 n=load();
 puts("\n Input one data.\n");
 do
  {input(n);
   printf_face();
   printf_one(n);
   printf("\n\nAre you sure?\n\n\t 1.Sure\t2.cancel and again\t3.Back without save [ ]\b\b");
   scanf("%d",&c);
   if(c==1)
    {
     save(n+1);
     printf_back();
    }
   else if(c!=2) menu();
  }
 while(c==2);
}  */

modify()
{struct student s;
 FILE *fp;
 int i,n,k,w0=1,w1,w2=0;
 n=load();
 do
  {
   k=-1;
   printf_face();
   for(i=0;i<n;i++)
    {if((i!=0)&&(i%10==0))
      {printf("\n\nRemember NO.031073- which needed modify.Pass any key to continue ...");
       getch();
       puts("\n\n");
      }
     printf_one(i);
     printf("\n");
    }
   do
    {printf("\n\nEnter NO.031073- that you want to modify!  NO.:031073-");
     scanf("%d",&s.num);
     for(i=0;i<n;i++)
      if(s.num==stu[i].num)
       {k=i;
 s=stu[i];  /* chengji beifei */
       }
      if(k==-1) printf("\n\nNO exist!please again");
    }
   while(k==-1);
   printf_face();
   printf_one(k);
   w1=modify_data(k,n);
   if(w1==1)
    {printf("\nSuccessful ^_^.\n\nAre you modify another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
     scanf("%d",&w0);
     w2=1;
    }
   else
    {w0=0;      /* end */
     if(w2==1)
      stu[k]=s;
    }
   if(w0!=1&&w2==1) save(n);  /* w0!=1 return    w2==1 modify */
  }
 while(w0==1);
 menu();
}

delete()
{struct student s;
 FILE *fp;
 int i,n,k,w0=1,w1,w2=0;
 n=load();
 do
  {
   k=-1;
   printf_face();
   for(i=0;i<n;i++)
    {if((i!=0)&&(i%10==0))
      {printf("\n\nRemember NO.031073- which needed delete.Pass any key to continue ...");
       getch();
       puts("\n\n");
      }
     printf_one(i);
     printf("\n");
    }
   do
    {printf("\n\nEnter NO.031073- that you want to delete!  NO.:031073-");
     scanf("%d",&s.num);
     for(i=0;i<n;i++)
      if(s.num==stu[i].num)
       {k=i;
 s=stu[i];  /* chengji beifei */
       }
      if(k==-1) printf("\n\nNO exist!please again");
    }
   while(k==-1);
   printf_face();
   printf_one(k);
   printf("\nAre you sure?\n\n\t1.Sure2.Back without save in this time [ ]\b\b");
   scanf("%d",&w1);
   if(w1==1)
    {
     stu[k].sum=0;
     printf("\nSuccessful ^_^.\n\nAre you delete another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
     scanf("%d",&w0);
     w2=1;
    }
   else
    {w0=0;      /* end */
     if(w2==1)
      stu[k]=s;
    }
   if(w0!=1&&w2==1) save(n);
  }
 while(w0==1);
 menu();
}



modify_score()
{struct student s;
 FILE *fp;
 int i,n,k,w0=1,w1,w2=0;
 n=load();
 do
  {
   k=-1;
   printf_face();
   for(i=0;i<n;i++)
    {if((i!=0)&&(i%10==0))
      {printf("\n\nRemember NO.031073 which score needed modify.Pass any key to continue ...");
       getch();
       puts("\n\n");
      }
     printf_one(i);
     printf("\n");
    }
   do
    {printf("\n\nEnter NO.031073- that you want to modify!  NO.:031073-");
     scanf("%d",&s.num);
     for(i=0;i<n;i++)
      if(s.num==stu[i].num)

       {k=i;
 s=stu[i];  /* chengji beifei */
       }
      if(k==-1) printf("\n\nNO exist!please again");
    }
   while(k==-1);
   printf_face();
   printf_one(k);
   w1=modify_score1(k);
   if(w1==1)
    {printf("\nSuccessful ^_^.\n\nAre you modify another score?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
     scanf("%d",&w0);
     w2=1;
    }
   else
    {w0=0;      /* end */
     if(w2==1)
      stu[k]=s;
    }
   if(w0!=1&&w2==1) save(n);  /* w0!=1 return    w2==1 modify */
  }
 while(w0==1);
 menu();
}

order()
{int i,j,k,n;
 struct student s;
 n=load();
 for(i=0;i<n-1;i++)
  {k=i;
   for(j=i+1;j<n;j++)
    if(stu[j].num<stu[k].num) k=j;
    s=stu[i];stu[i]=stu[k];stu[k]=s;
  }
 save(n);
 puts("\n\n");
 printf_back();
}

browse()
{int i,j,n;
 n=load();
 printf_face();
 for(i=0;i<n;i++)
  {if((i!=0)&&(i%10==0))
    {printf("\n\nPass any key to contiune ...");
     getch();
     puts("\n\n");
    }
   printf_one(i);
   printf("\n");
  }
 printf("\tThere are %d record.\n",n);
 printf("\nPass any key to back...");
 getch();
 menu();
}




save(int n)
{FILE *fp;
 int i;
 if((fp=fopen("score.txt","wb"))==NULL)
  {printf("\nCannot open file\n");
   return NULL;
  }
 for(i=0;i<n;i++)
  if(stu[i].sum!=0)
   if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
    printf("file write error\n");
 fclose(fp);
}

load()
{FILE *fp;
 int i;
 if((fp=fopen("score.txt","rb"))==NULL)
  {printf("\nCannot open file\n");
   return NULL;
  }
 for(i=0;!feof(fp);i++)
  fread(&stu[i],sizeof(struct student),1,fp);
 fclose(fp);
 return(i-1);
}

no_input(int i,int n)
{int k,w1;
 do
  {w1=0;
   printf("NO.:031073-");
   scanf("%d",&stu[i].num);
   if(stu[i].num<1 || stu[i].num>N)
     {puts("Input error! Only be made up of(1-N).Please reinput!\n");
      w1=1;
     }
   if(w1!=1)
     for(k=0;k<n;k++)
      if(k!=i&&(stu[k].num==stu[i].num))
       {puts("This record is exist. Please reinput!\n");
 w1=1;break;
       }
   }
  while(w1==1);
}


enter_score(int i)
{printf("Math  English  Physical");
 scanf("%d %d %d",&stu[i].Math,&stu[i].English,&stu[i].Physical);
}
sum(int i)
{
 stu[i].sum=stu[i].Math+stu[i].English+stu[i].Physical;
}

input(int i)
{no_input(i,i);
 printf("name:   age:");
 scanf("%s %d",stu[i].name,&stu[i].age);
 enter_score(i);
 sum(i);
}



modify_score1(int i)
{int c,w1;
 do
  {
   puts("\nmodify by=>\n\n 1.Math 2.English 3.Physical4.all score 5.cancel and back");
   printf("Which you needed?:[ ]\b\b");
   scanf("%d",&c);
   if(c>5||c<1)
    {puts("\nChoice error! Please again!");
     getchar();
    }
  }
 while(c>5||c<1);
 do
  {switch(c)
    {
     case 1:printf("Math:");scanf("%d",&stu[i].Math);break;
     case 2:printf("English:");scanf("%d",&stu[i].English);break;
     case 3:printf("Physical:");scanf("%d",&stu[i].Physical);break;
     case 4:enter_score(i);break;
     case 5:break;
    }
  if(c>0&&c<5) sum(i);
  puts("\nNow:\n");
  printf_face();
  printf_one(i);
  printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");
  scanf("%d",&w1);
 }
 while(w1==2);
 return(w1);
}

modify_data(int i,int n)
{int c,w1;
 do
  {
   puts("\nmodify by=>\n\n 1.NO. 2.name 3.age 4.Math 5.English 6.Physical7.all score 8.all data 9.cancel and back");
   printf("Which you needed?:[ ]\b\b");
   scanf("%d",&c);
   if(c>9||c<1)
    {puts("\nChoice error! Please again!");
     getchar();
    }
  }
 while(c>9||c<1);
 do
  {switch(c)
    {case 1:no_input(i,n);break;
     case 2:printf("name:");scanf("%s",stu[i].name);break;
     case 3:printf("age:");scanf("%d",&stu[i].age);break;
     case 4:printf("Math:");scanf("%d",&stu[i].Math);break;
     case 5:printf("English:");scanf("%d",&stu[i].English);break;
     case 6:printf("Physical:");scanf("%d",&stu[i].Physical);break;
     case 7:enter_score(i);break;
     case 8:input(i);break;
     case 9:break;
    }
  if(c>3&&c<8) sum(i);
  puts("\nNow:\n");
  printf_face();
  printf_one(i);
  printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");
  scanf("%d",&w1);
 }
 while(w1==2);
 return(w1);
}

printf_face()
{printf("\nNO.031073  name   age  Math  English  Physical  sum\n");
}

printf_one(int i)
{
 printf("%6d %8s %4d",stu[i].num,stu[i].name,stu[i].age);
 printf("%5d %5d %8d %10d",stu[i].Math,stu[i].English,stu[i].Physical,stu[i].sum);
}

printf_back()
{int k,w;
 printf("\n\n\tSuccessful.^_^\n\n");
 printf("What do you want to do?\n\n\t1.Browse all now\t2.Back:[ ]\b\b");
 scanf("%d",&w);
 if(w==1) browse();
 else menu();
}
menu()
{int w1;
 char n;
 do
  {
   puts("\t\t****************MENU****************\n\n");
   puts("\t\t\t\tA.Enter new data");
   puts("\t\t\t\tB.Addition data");
   puts("\t\t\t\tC.Modify data");
   puts("\t\t\t\tD.Delete data");
   puts("\t\t\t\tE.Modify score");
   puts("\t\t\t\tF.Order by number");
   puts("\t\t\t\tG.Browse all");
   puts("\t\t\t\tH.Exit");
   puts("\n\n\t\t************************************\n");
   printf("Choice your number(A-H):[ ]\b\b");
   n=getchar();
   printf("\n");
   if(n<'A'||n>'H')
      w1=1;
   else w1=0;
  }
 while(w1==1);
 switch(n)
  {case 'A':enter();break;
   case 'B':add();break;
   case 'C':modify();break;
   case 'D':delete();break;
   case 'E':modify_score();break;
   case 'F':order();break;
   case 'G':browse();break;
   case 'H':exit(0);
  }
}
char password[7]="123456";
main()
{   
 char s[7];
 printf("\t\t请输入密码:\n\t\t\n\t\t");
 scanf("%s",s);
 if(!strcmp(s,password))
 {
        printf("\n\t\t恭喜你进入学生成绩管理系统\n");
  menu();
 }
    else
 {   
  printf("\t\t 密码错误\n\n");
  main();
 }
搜索更多相关主题的帖子: 改错 
2010-12-02 20:43
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:3 
看看,

我就是真命天子,顺我者生,逆我者死!
2010-12-02 21:45
zghnxzdcx
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:550
专家分:1176
注 册:2010-4-6
收藏
得分:3 
好长的程序,你能不能按照模块加上注释,再注明模块之间的关系,以及出错的是哪个模块?

你永远不可能战胜一个纯傻子,因为他会把你的智商拉到和他同一个水平,然后用他的丰富经验打败你。
2010-12-02 21:50
tang_ke
Rank: 2
来 自:西安电子科技大学
等 级:论坛游民
帖 子:45
专家分:46
注 册:2010-10-12
收藏
得分:3 
看来您的编程习惯还是不好啊。。。。。。
2010-12-02 22:03
pizilong
Rank: 2
来 自:安徽
等 级:论坛游民
帖 子:11
专家分:15
注 册:2010-10-10
收藏
得分:0 
嗯!新手,才学编程!
2010-12-03 13:01
风卷云
Rank: 1
等 级:新手上路
帖 子:5
专家分:2
注 册:2010-12-3
收藏
得分:3 
可以自己先检查一下出错的大约是哪块,这也太长了,也没有注释啊
2010-12-03 15:55
闾致富
Rank: 2
等 级:论坛游民
帖 子:20
专家分:42
注 册:2010-11-17
收藏
得分:3 
看花眼了!
写的明了些吧!
2010-12-03 17:15
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:3 
我推荐楼主用一下BlueGug推荐的那个工具~
2010-12-03 17:34
ququguoguo
Rank: 2
等 级:论坛游民
帖 子:73
专家分:90
注 册:2010-10-20
收藏
得分:3 
。。。太特么长了。。。。
2010-12-03 17:41
a343637412
Rank: 7Rank: 7Rank: 7
来 自:そ ら
等 级:黑侠
帖 子:357
专家分:620
注 册:2010-9-26
收藏
得分:3 
....我也是新人,不过没你牛
2010-12-03 19:25
快速回复:有问题!求改错!
数据加载中...
 
   



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

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