| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 559 人关注过本帖
标题:调不出来 高手帮看看 (在线等)
取消只看楼主 加入收藏
wench001
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-5-20
收藏
 问题点数:0 回复次数:0 
调不出来 高手帮看看 (在线等)
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXN 300
#define MAX_NAME 20
#define LEN   struct student
 typedef struct student{
   int  num;
   char name[MAX_NAME];
          int  english;
          int  math;
          int  computer;
          int  mark_ave;
} STUDENT;

/*-----------input sub program---------*/

void input(STUDENT stu[], int len)
{
   int no;
   char ch[MAX_NAME];
   int i=0 ;
   putchar('\n');
   printf("%s\n", "Enter the new records.And if you want exit, enter -1.");
   printf("%s\n", "format: number");
   printf("%s\n", "        name english math computer");
   putchar('\n');
   printf("such as:\n");
   printf("1\n");
   printf("Gates 100 100 100 \n");
   while(i<len){
   printf("please input code :") ;
   scanf("%d", &no);
   if(no==-1)
   {len=i;
    break;
   }
   while(no !=0) {
     stu[i].num = no;
     scanf("%s %d %d %d %d %d", stu[i].name, &stu[i].english, &stu[i].math,&stu[i].computer,&stu[i].mark_ave);
     i++;
     scanf("%d", &no);
   }
   }
}


/*---------------output sub program---------------*/

void output(STUDENT stu[], int len)
{
  int i;

  clrscr();
  printf("%8s", "number");
  printf("%8s", "name");
  printf("%8s", "english");
  printf("%8s", "math");
  printf("%10s", "computer");
  putchar('\n');

  for (i =0; i < 80; i++)
    putchar('=');
  putchar('\n');

  for (i = 0; i< len; i++)
  {
    printf("%8d", stu[i].num);
    printf("%8s", stu[i].name);
    printf("%8d", stu[i].english);
    printf("%8d", stu[i].math);
    printf("%10d", stu[i].computer);
    putchar('\n');
  }

  for (i =0; i < 80; i++)
    putchar('=');
  putchar('\n');
  printf("Press enter to continue.");
  getchar();
  getchar();
}
/*--------------sort sub program------------*/
void sort(STUDENT stu[], int len)
{
  int i,j,k;
  STUDENT temp;

  for (i=0; i<len-1; i++) {
    for (k=i, j=i+1; j<len; j++)
      if (stu[k].mark_ave > stu[j].mark_ave) k=j;

    if (k != i) {
      temp = stu[i];
      stu[i] = stu[k];
      stu[k] = temp;
    }
  }
}

 




/*--------------------find sub program-----------------------*/

void find(STUDENT stu[], int len)
{
  int find_no, result ;
  int i;

  lab: result=0;
  printf("%s\n", "Enter the number which you want to find. If you want exit, enter -1.");
  scanf("%d", &find_no);
  if (find_no == -1) return;     /*exit the fine sub program*/
  while( stu[result].num != find_no && result < len) result ++;
  if (result >= len ) {
    printf("%s\n", "There is no the record which you want.");
    goto lab;
  }
  else {
    clrscr();
    printf("%s\n", "The flowing record is you want.");

    for (i =0; i < 80; i++)
    putchar('=');
    putchar('\n');

    printf("%8s", "number");
    printf("%8s", "name");
    printf("%8s", "english");
    printf("%8s", "math");
    printf("%10s", "computer");
    printf("%12d", stu[result].mark_ave);
    putchar('\n');

 

    printf("%8d", stu[result].num);
    printf("%8s", stu[result].name);
    printf("%8d", stu[result].english);
    printf("%8d", stu[result].math);
    printf("%10d", stu[result].computer);
    printf("%12d", stu[result].mark_ave);
   
    putchar('\n');

    for (i =0; i < 80; i++)
    putchar('=');
    putchar('\n');

    goto lab;
  }
}


/*-----------------insert sub program-------------*/

void insert(STUDENT stu[], int len)
{
  int no, pos, english, math, computer,mark_ave, i;
  char name[MAX_NAME];
  lab: printf("%s\n", "Enter the new records. If you want exit, enter -1.");
  printf("%s\n", "format: number");
  printf("%s\n", "        name english math computer average total");

  scanf("%d", &no);
  if (no == -1) return ;
  stu[len].num = no;
 
  scanf("%s %d %d %d %d %d", name, &english, &math, &computer,&mark_ave);

  pos = 0;
  while ((stu[pos].mark_ave < mark_ave) && (pos < len) )
    pos ++;
  for (i = len-1; i >= pos; i--)
    stu[i+1] = stu[i];
  stu[pos].num = no;
  strcpy(stu[pos].name, name);
  stu[pos].english = english;
  stu[pos].math = math;
  stu[pos].computer = computer;

  len=len+1;
  goto lab;
}

/*--------------delete sub program--------------*/

void delete(STUDENT stu[], int len)
{
  int no, i, pos;

  lab: pos=0;
  printf("%s\n", "Enter the number which you want to delete. If you want exit, enter -1.");

  scanf("%d", &no);
  if (no == -1) return;
  while( (stu[pos].num != no) && (pos < len) ) pos = pos +1;
  if (pos >= len) {
    printf("%s\n", "There is no the record which you want.");
    goto lab;
  }
  else {
    for (i = pos+1;i < len; i++)
      stu[i-1] = stu[i];
    len = len -1;
    if (len == 0) {
      printf("%s\n", "The number of records is zero, press enter to return.");
      getchar();
      getchar();
      return;
    }
  goto lab;
  }

}


/*---------------stat sub program------------*/

void stat(STUDENT stu[], int len)
{
  int no_59=0, no_69=0, no_79=0, no_89=0, no_100=0;
  int i;

  for (i = 0;i < len; i++) {
    if (stu[i].mark_ave <=59) no_59++;
    else if (stu[i].mark_ave <=69) no_69++;
         else if (stu[i].mark_ave <=79) no_79++;
              else if (stu[i].mark_ave <= 89) no_89++;
                   else no_100++;
  }

  clrscr();
  for (i =0; i < 80; i++)
    putchar('=');
    putchar('\n');
  printf("%10s", "score");
  printf("%10s", "0--59");
  printf("%10s", "60--69");
  printf("%10s", "70--79");
  printf("%10s", "80--89");
  printf("%10s", "90--100");
  putchar('\n');
  putchar('\n');

  printf("%10s", "student");
  printf("%10d", no_59);
  printf("%10d", no_69);
  printf("%10d", no_79);
  printf("%10d", no_89);
  printf("%10d", no_100);

  putchar('\n');

  for (i =0; i < 80; i++)
    putchar('=');
  putchar('\n');
  printf("Press enter to return.");
  getchar();
  getchar();
}
/*------------write--------------*/
void write(STUDENT stu[],int len)
{ FILE *ft;
  if((ft=fopen("c:\\stu.dat","wb"))==NULL)
    {printf("!!error\n");}
  if(fwrite(stu,sizeof(LEN),len,ft)!=len)
    {printf("error\n");}
  fclose(ft);
}
/*------------read-------------*/
void read(STUDENT stu[],int len)
{
 int i;
 FILE *f;
 if((f=fopen("c:\\stu.dat","rb"))==NULL)
 {printf("!!error\n");

 }
 rewind(f);
 for(i=0;i<len;i++)
 if(fread(&stu[i],sizeof(LEN),1,f)!=1)
 { printf("!!error");}
 fclose(f);
}


/*---------------manu------------*/

void paint()
{
  int i;

  clrscr();
  printf("%43s\n", "Manu");

  for (i = 0; i < 80; i++)
    putchar('=');
  putchar('\n');

  printf("             1 input                            2 output\n");
  printf("             3 sort(average)                    4 find(number)\n");
  printf("             5 insert                           6 delete(number)\n");
  printf("             7 stat(average)                    8 write\n");
  printf("             9 read                             0 quit\n");
  for (i = 0; i<= 79; i++)
    putchar('=');
  putchar('\n');

  printf("%s\n", "Please enter the command:");

}

/*------------main program---------------*/

main()
{
  STUDENT stu[MAXN];
  char ctrl_ch;
  int len=0;
  FILE *fp;
   fp=fopen("stu.dat","wt");
    if(fp==NULL)
    {
       printf("!error\n");
       exit(0);
   }



   read(stu,len);

  paint();
  scanf("%c", &ctrl_ch);
  while (ctrl_ch != '0') {
    switch(ctrl_ch) {
      case '1':
 input(stu,  len);
 break;
      case '2':
 output(stu, len);
 break;
      case '3':
 sort(stu, len);
 break;
      case '4':
 find(stu, len);
 break;
      case '5':
 insert(stu, len);
 break;
      case '6':
 delete(stu, len);
 break;
      case '7':
 stat(stu, len);
 break;
      case '8':
          read(stu,len);
      case '9':
          write(stu,len);
      default:
 if (ctrl_ch != '\n') printf("%s\n", "Error command.");
 break;
    }
    if (ctrl_ch != '\n') paint();
    scanf("%c", &ctrl_ch);
  }
  getch();
}

     CPU 操作错误啊!@!!!
搜索更多相关主题的帖子: 在线 
2008-05-29 20:05
快速回复:调不出来 高手帮看看 (在线等)
数据加载中...
 
   



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

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