CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

高手进来看看!!!

楼主xinteng(幽幻寒冰)2004-12-03 17:36:36 在 C/C++ / C语言 提问

有好多错误!帮忙改改  
  #include<stdio.h>  
  #include<stdlib.h>  
  #include<string.h>  
  #define   maxlen   100  
  typedef   struct   student  
  {char   name[10],no[10];  
  int   math,eng,comp;  
  }elemtype;  
  main()  
  {elemtype   stu[maxlen],x;  
  int   i,sel,p,q;  
  int   *len,addlen;  
  char   kch[10];  
  int   insert(elemtype   a[],int   *n,int   i,elemtype   x);  
  int   del(elemtype   a[],int   *n,int   i);  
  len=&addlen;  
  printf("\n\n   1............initl\n");  
  printf("2..........input   the   chengji\n");  
  printf("3..........insert\n");  
  printf("4............del\n");  
  printf("5.............modify\n");  
  printf("6.............display\n");  
  printf("7.............chazhao\n");  
  printf("8.............paixu\n");  
  printf("0.............exit\n");  
  *len=0;  
  do{printf("\n   input   your   choice:");  
  scanf("5d",&sel);  
  getchar();  
  switch(sel)  
  {case   1:printf("\n   input   the   list's   length:");  
  scanf("%d",len);  
  getchar();  
  for(i=0;i<=*len-1     ;i++)  
  {printf("\n   enter   no,name");  
  stu[i].math=0;  
  stu[i].eng=0;  
  stu[i].comp=0;  
  gets(stu[i].no);  
  getchar();  
  gets(stu[i].name);  
  }break;  
  case   2:printf("\n   input   the   kecheng   name   and   score");  
  gets(kch);  
  if(strcmp(kch,"math")==0)  
  for(i=0;i<=*len-1;++i)  
  scanf("%d",&stu[i].math);  
  else   if(strcmp(kch,"eng")==0)  
  for(i=0;i<=*len-1;++i)  
  scanf("%d",&stu[i].eng);  
  else   if(strcmp(kch,"comp")==0)  
  for(i=0;i<=*len-1;++i)  
  scanf("5d",&stu[i].comp);  
  break;  
  case   3:printf("\n   input   the   insert   position:");  
  scanf("%d",&p);  
  printf("\n   input   the   information:no,name,math,english,computer");  
  getchar();  
  gets(x.no);  
  getchar();  
  gets(x.name);  
  scanf("%d%d%d",&x.math,&x.eng,&x.comp);  
  insert(stu,len,p,x);  
  break;  
  case   4:printf("\n   input   the   delete   position:");  
  scanf("%d",&p);  
  del(stu,len,p);  
  break;  
  case   5:printf("\n   input   the   modify   element   position:");  
  scanf("%d",p);  
  printf("\n   input   the   new   information:no,name,math,eng,comp");  
  scanf("%s%s%d%d",stu[p].no,stu[p].name,&stu[p].math,&stu[p].eng,&stu[p].comp);  
  break;  
  case   6:printf("\n   input   the   start   and   end   position:");  
  scanf("%d%d",&p,&q);  
  printf("\n   noname     math     english   computer");  
  if(p>=0&&q<=*len-1)  
  for(i=p;i<=q;++i)  
  printf("\n   %8s;%8s;%8u;%8u;%8u\n",stu[i].no,stu[i].name,stu[i].math,stu[i].eng,stu[i].comp);  
  else  
  printf("\n   the   position   is   wrong");  
  break;  
  case   7:printf("input   the   student's   NO:");  
  gets(kch);  
  for(i=0;i<=*len-1;++i)  
  if(strcmp(kch,stu[i].no)==0)  
  {printf("\n   %8s;%8s;%8u;%8u;%8u\n",stu[i].no,stu[i].name,stu[i].math,stu[i].eng,stu[i].comp);  
  break;}  
  else  
  printf("\n   there   is   no   the   student's   NO");  
  break;  
  case   8:printf("   order   by   math");  
  selectsort(stu,len);  
  break;  
  case   0:exit(0);  
  }  
  }while(sel!=0);  
  }  
  int   insert(elemtype   a[],int   *n,int   i,elemtype   x)  
  {int   j;  
  if(i<0||i>*n)  
  {printf("\n   the   position   is   invalid");  
  return   0;}  
  else   if(*n==maxlen-1)  
  {printf("\n   the   list   is   full");  
  return   0;}  
  else   {for(j=*n-1;j>=i;j--)a[j+1]=a[j];  
  a[i]=x;  
  (*n)++;  
  return   1;  
  }  
  }  
  int   del(elemtype   a[],int   *n,int   i)  
  {int   j;  
  if(i<0||i>*n-1)  
  {printf("\n   the   position   is   invalid");  
  return   0;}  
  else  
  {for(j=i+1;j<=*n-1;j++)a[j+1]=a[j];  
  (*n)--;  
  return   1;  
  }  
  }  
  int   selectsort(r,n)  
  {int   i,j,k,temp;char   s[10],name;  
  for(i=0;i<n-1;i++)  
  {k=i;  
  for(j=i+1;j<n;j++)  
  if(r[j].math<r[k].math)  
  k=j;  
  if(k!=i)  
  {strcpy(s,r[i],name);  
  strcpy(r[i].name,r[k].name);  
  strcpy(r[k].name,s);  
  strcpy(strcpy(s,r[i].no);  
  strcpy(r[i],r[k]);  
  strcpy(r[k].no,s);  
  temp=stu[i].math;  
  stu[i].math=   stu[k].math;  
  stu[i].math=temp;  
  temp=stu[i].eng;  
  stu[i].eng=stu[k].eng;  
  stu[k].eng=temp;  
  temp=stu[i].comp;  
  stu[i].comp=stu[k].comp;  
  stu[k].comp=temp;  
  }  
  }  
  }  
   
  问题点数:10、回复次数:2Top

1 楼hunter606(混特)回复于 2004-12-03 17:51:42 得分 10

//   111.cpp   :   Defines   the   entry   point   for   the   console   application.  
  //  
   
  #include   "stdafx.h"  
  #include<stdio.h>  
  #include<stdlib.h>  
  #include<string.h>  
  #define   maxlen   100  
  typedef   struct   student  
  {  
  char   name[10],no[10];  
  int   math,eng,comp;  
  }elemtype;  
   
  int   selectsort(elemtype   *,int);////  
   
  main()  
  {  
  elemtype   stu[maxlen],x;  
  int   i,sel,p,q;  
  int   *len,addlen;  
  char   kch[10];  
  int   insert(elemtype   a[],int   *n,int   i,elemtype   x);  
  int   del(elemtype   a[],int   *n,int   i);  
  len=&addlen;  
  printf("\n\n   1............initl\n");  
  printf("2..........input   the   chengji\n");  
  printf("3..........insert\n");  
  printf("4............del\n");  
  printf("5.............modify\n");  
  printf("6.............display\n");  
  printf("7.............chazhao\n");  
  printf("8.............paixu\n");  
  printf("0.............exit\n");  
  *len=0;  
  do{  
  printf("\n   input   your   choice:");  
  scanf("5d",&sel);  
  getchar();  
  switch(sel)  
  {  
  case   1:  
  printf("\n   input   the   list's   length:");  
  scanf("%d",len);  
  getchar();  
  for(i=0;i<=*len-1     ;i++)  
  {  
  printf("\n   enter   no,name");  
  stu[i].math=0;  
  stu[i].eng=0;  
  stu[i].comp=0;  
  gets(stu[i].no);  
  getchar();  
  gets(stu[i].name);  
  }  
  break;  
  case   2:printf("\n   input   the   kecheng   name   and   score");  
  gets(kch);  
  if(strcmp(kch,"math")==0)  
  for(i=0;i<=*len-1;++i)  
  scanf("%d",&stu[i].math);  
  else   if(strcmp(kch,"eng")==0)  
  for(i=0;i<=*len-1;++i)  
  scanf("%d",&stu[i].eng);  
  else   if(strcmp(kch,"comp")==0)  
  for(i=0;i<=*len-1;++i)  
  scanf("5d",&stu[i].comp);  
  break;  
  case   3:printf("\n   input   the   insert   position:");  
  scanf("%d",&p);  
  printf("\n   input   the   information:no,name,math,english,computer");  
  getchar();  
  gets(x.no);  
  getchar();  
  gets(x.name);  
  scanf("%d%d%d",&x.math,&x.eng,&x.comp);  
  insert(stu,len,p,x);  
  break;  
  case   4:printf("\n   input   the   delete   position:");  
  scanf("%d",&p);  
  del(stu,len,p);  
  break;  
  case   5:printf("\n   input   the   modify   element   position:");  
  scanf("%d",p);  
  printf("\n   input   the   new   information:no,name,math,eng,comp");  
  scanf("%s%s%d%d",stu[p].no,stu[p].name,&stu[p].math,&stu[p].eng,&stu[p].comp);  
  break;  
  case   6:printf("\n   input   the   start   and   end   position:");  
  scanf("%d%d",&p,&q);  
  printf("\n   noname     math     english   computer");  
  if(p>=0&&q<=*len-1)  
  for(i=p;i<=q;++i)  
  printf("\n   %8s;%8s;%8u;%8u;%8u\n",stu[i].no,stu[i].name,stu[i].math,stu[i].eng,stu[i].comp);  
  else  
  printf("\n   the   position   is   wrong");  
  break;  
  case   7:printf("input   the   student's   NO:");  
  gets(kch);  
  for(i=0;i<=*len-1;++i)  
  if(strcmp(kch,stu[i].no)==0)  
  {printf("\n   %8s;%8s;%8u;%8u;%8u\n",stu[i].no,stu[i].name,stu[i].math,stu[i].eng,stu[i].comp);  
  break;}  
  else  
  printf("\n   there   is   no   the   student's   NO");  
  break;  
  case   8:printf("   order   by   math");  
  selectsort(stu,*len);   ///  
  break;  
  case   0:  
  exit(0);  
  }  
   
  }while(sel!=0);  
  return   0;////  
  }  
  int   insert(elemtype   a[],int   *n,int   i,elemtype   x)  
  {  
  int   j;  
  if(i<0||i>*n)  
  {  
  printf("\n   the   position   is   invalid");  
  return   0;  
  }  
  else   if(*n==maxlen-1)  
  {printf("\n   the   list   is   full");  
  return   0;}  
  else   {for(j=*n-1;j>=i;j--)a[j+1]=a[j];  
  a[i]=x;  
  (*n)++;  
  return   1;  
  }  
  }  
  int   del(elemtype   a[],int   *n,int   i)  
  {  
  int   j;  
  if(i<0||i>*n-1)  
  {  
  printf("\n   the   position   is   invalid");  
  return   0;}  
  else  
  {  
  for(j=i+1;j<=*n-1;j++)a[j+1]=a[j];  
  (*n)--;  
  return   1;  
  }  
  }  
  int   selectsort(elemtype   *r,int   n)////  
  {  
  int   i,j,k,temp;char   s[10],name;  
  for(i=0;i<n-1;i++)  
  {  
  k=i;  
  for(j=i+1;j<n;j++)  
  if(r[j].math<r[k].math)  
  k=j;  
  if(k!=i)  
  {  
  strcpy(s,r[i].name);     ///  
  strcpy(r[i].name,r[k].name);  
  strcpy(r[k].name,s);  
  strcpy(s,r[i].no);///  
  strcpy(r[i].no,r[k].no);   ///  
  strcpy(r[k].no,s);  
  temp=r[i].math;//  
  r[i].math=   r[k].math;//  
  r[i].math=temp;//  
  temp=r[i].eng;//  
  r[i].eng=r[k].eng;//  
  r[k].eng=temp;//  
  temp=r[i].comp;//  
  r[i].comp=r[k].comp;//  
  r[k].comp=temp;//  
  }  
  }  
  return   0;  
  }  
   
   
   
  修改的地方加了"//"Top

2 楼liujingfu123(Oh_My_GoD)回复于 2004-12-03 20:19:36 得分 0

靠!这么长啊?…………  
   
  Top

相关问题

关键词

  • elemtype
  • addlen
  • printf
  • maxlen
  • sel
  • getchar
  • del
  • len
  • scanf
  • position

得分解答快速导航

  • 帖主:xinteng
  • hunter606

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo