| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 634 人关注过本帖
标题:大家帮忙看看这段程序的问题~~·谢了(急!)
只看楼主 加入收藏
a442579302
Rank: 2
来 自:C入门
等 级:论坛游民
帖 子:29
专家分:39
注 册:2009-12-29
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:5 
大家帮忙看看这段程序的问题~~·谢了(急!)



还没写完  但已经有问题了  5555555~~·~~


#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define P() printf("                                                    \n")
#define SIZE 2


struct student
{
 char name[10];
 int num;
 char sex;
 int age;
 int chinese;
 int math;
 int english;
 int computer;
}s[SIZE];


void save()
{
 int i;
 FILE *fp;
 printf("please input SIZE students informations:\n");
 printf("the information include:Name  Number  Sex  Age  Chinese  Math  English  Computer\n");
 for(i=0;i<SIZE;i++)
   scanf("%s%d%c%d%d%d%d%d",s[i].name,&s[i].num,&s[i].sex,&s[i].age,&s[i].chinese,&s[i].math,&s[i].english,&s[i].computer);
 if((fp=fopen("student_list","wb"))==NULL)
  {
   printf("cannot open file\n");
   return;
  }
 for(i=0;i<SIZE;i++)
   if(fwrite(&s[i],sizeof(struct student),1,fp)!=1)
    printf("file write error\n");
 fclose(fp);
}

void read_in()
{
 int i;
 FILE *fp;
 char infile[15];

 fp=fopen("student_list","rb");

 for(i=0;i<SIZE;i++)
   fread(&s[i],sizeof(struct student),1,fp);
   fclose(fp);
}

void menu()
{
 clrscr();
 P();
 printf("       ===============================================================\n");
 printf("                                                               \n");
 printf("                Welcome to the student score management system        \n");
 printf("                                                               \n");
 printf("       ****---****----****----****________****----****----****----****\n");
 printf("       |                         |        |          made  by :      |\n");
 printf("       |                         |  MENU  |      Wang  Deng  Hong    |\n");
 printf("       |--------------------------________---------------------------|\n");
 printf("       |                                                             |\n");
 printf("       |                                                             |\n");
 printf("       | 1> Search         2> Input record        3> Modify record   |\n");
 printf("       |                                                             |\n");
 printf("       |                                                             |\n");
 printf("       | 4> Average score      5> Rankings            6> Quit        |\n");
 printf("       |                                                             |\n");
 printf("       |                                                             |\n");
 printf("       ***************************************************************\n");
 printf("                                                                      \n");
 printf("                       Please input your choice(1~6): ");
}


void menu2()
{
 clrscr();
 P();
 printf("       --------------------------Select  Menu-------------------------\n");
 P();
 printf("        1> Search on name                  2> Search on number        \n");
 P();
 printf("        3> Search on score                 4> Search on sex           \n");
 P();
 printf("                         5> Return the main menu                      \n");
 P();
 printf("       ---------------------------------------------------------------\n");
 P();
 printf("                          please choice(1~5):  ");
}


void menu2_s()
{
 clrscr();
 P();
 printf("       --------------------------Select  Menu-------------------------\n");
 P();
 printf("         1> Search Chinese score             2> Search Math score     \n");
 P();
 printf("         3> Search English score             4> Search Computer score \n");
 P();
 printf("                          5> Return superior menu                     \n");
 P();
 printf("       ---------------------------------------------------------------\n");
 printf("                           please choice(1~5):  ");
}

void menu3()
{
 clrscr();
 P();
 printf("       --------------------------Select  Menu-------------------------\n");
 P();
 printf("                 1>  Chinese                    2>  Math              \n");
 P();
 printf("                 3>  English                    4>  Computer          \n");
 P();
 printf("                         5> Return the  main  menu                     \n");
 P();
 printf("       ---------------------------------------------------------------\n");
 printf("                          please choice(1~5):  ");
}


void menu4()
{
 clrscr();
 P();
 printf("        --------------------------Select  Menu-------------------------\n");
 P();
 printf("          1> Chinese  ranking              2> math  ranking            \n");
 P();
 printf("          3> English  ranking              4> computer  ranking        \n");
 P();
 printf("          5> The total  ranking            6> Return superior menu     \n");
 P();
 printf("        ---------------------------------------------------------------\n");
 printf("                   p      lease choice(1~6):  ");  }


search()
{
 int i;
 clrscr();
 menu2();
 scanf("%d",&i);
 printf("\n");
 switch(i)
 {
  case 1:search_na();break;
  case 2:search_nu();break;
  case 3:search_sc();break;
  case 4:search_se();break;
  case 5:break;
  default:printf("input error!\n press any botton to continue");
 }
}


search_sc()
{
 int i;
 char j;
 clrscr();
 menu2_s();
 scanf("%d",&i);
 printf("\n");
 switch(i)
 {case 1:score_ch();break;
  case 2:score_ma();break;
  case 3:score_en();break;
  case 4:score_co();break;
  case 5:break;
  default:printf("input error!  input again?(Y/N): ");scanf("%c",&j);
  if((j=='Y')||(j=='y')) search();
  if((j=='N')||(j=='n')) break;
 }
}


 search_na()
{
 char a[10];int i,t;char j;
 printf("\nplease input the name you want to search: ");
 printf("\n");
 scanf("%s",a);
 printf("\n************************************STUDENT************************************\n");
    printf("-------------------------------------------------------------------------------\n");
    printf("Name\t|Num\t|Sex\t|Age\t|Chi\t|Math\t|Eng\t|Com\t|   \n");
    printf("-------------------------------------------------------------------------------\n");
   for(i=0,t=0;i<SIZE;i++)
   {
    if(strcmp(a,s[i].name)==0)
    printf("%s\t %d\t %c\t %d\t %d\t %d\t %d\t %d\t\n",s[i].name,s[i].num,s[i].sex,s[i].age,s[i].chinese,s[i].math,s[i].english,s[i].computer),t++;
   }
   printf("**************************************END**************************************\n");
   if(t==0)
   {
    printf("There is no this student!\ninput again?(Y/N): ");
    scanf("%c",&j);
    if((j=='Y')||(j=='y')) search_na();
    if((j=='N')||(j=='n')) search();
   }
}


search_nu()
{int k,i,t;
 char j;
 printf("please input the number you want to search: ");
 scanf("%d",&k);
 printf("\n************************************STUDENT************************************\n");
    printf("-------------------------------------------------------------------------------\n");
    printf("Name\t|Num\t|Sex\t|Age\t|Chi\t|Math\t|Eng\t|Com\t|   \n");
    printf("-------------------------------------------------------------------------------\n");
    for(i=0,t=0;i<SIZE;i++)
   {
    if(k==s[i].num)
    printf("%s\t %d\t %c\t %d\t %d\t %d\t %d\t %d\t\n",s[i].name,s[i].num,s[i].sex,s[i].age,s[i].chinese,s[i].math,s[i].english,s[i].computer),t++;
   }
    printf("**************************************END**************************************\n");
   if(t==0)
   {
    printf("There is no this student!\ninput again?(Y/N): ");
    scanf("%c",&j);
    if((j=='Y')||(j=='y')) search_nu();
    if((j=='N')||(j=='n')) search();
   }
}


search_se()
{int i;
 char j,k,t;
 printf("please input the sex(f/m): ");
 scanf("%c",&j);
 printf("\n************************************STUDENT************************************\n");
    printf("-------------------------------------------------------------------------------\n");
    printf("Name\t|Num\t|Sex\t|Age\t|Chi\t|Math\t|Eng\t|Com\t|   \n");
    printf("-------------------------------------------------------------------------------\n");
    for(i=0,t=0;i<SIZE;i++)
    {
     if(j==s[i].sex)
     printf("%s\t %d\t %c\t %d\t %d\t %d\t %d\t %d\t\n",s[i].name,s[i].num,s[i].sex,s[i].age,s[i].chinese,s[i].math,s[i].english,s[i].computer),t++;
    }
 printf("**************************************END**************************************\n");
}


score_ch()
{int i,k,j;
 char t;
 printf("please input a score: ");
 scanf("%d",&i);
 do
 {
  if((i<0)&&(i>100))
   {printf("score input error!\nplease input again: ");
    scanf("%d",&i);
    printf("\n");
   }
  else break;
 }while(1);
 for(j=0,k=0;j<SIZE;j++)
  {if(i==s[i].chinese)
   printf("These students have this score:\n");
   printf("------Name\tSex\tNumber\tAge\tchinese------\n");
   printf("      %s\t%c\t%d\t%d\t%d      \n"),k++;
  }
 if(k==0)
   {
    printf("There is no student have this score!\ninput again?(Y/N): ");
    scanf("%c",&t);
    if((t=='Y')||(t=='y')) score_ch();
    if((t=='N')||(t=='n')) search();
   }
}


score_ma()
{int i,k,j;
 char t;
 printf("please input a score: ");
 scanf("%d",&i);
 do
 {
  if((i<0)&&(i>100))
   {printf("score input error!\nplease input again: ");
    scanf("%d",&i);
    printf("\n");
   }
  else break;
 }while(1);
 for(j=0,k=0;j<SIZE;j++)
  {if(i==s[i].chinese)
   printf("These students have this score:\n");
   printf("------Name\tSex\tNumber\tAge\tmath------\n");
   printf("      %s\t%c\t%d\t%d\t%d      \n"),k++;
  }
 if(k==0)
   {
    printf("There is no student have this score!\ninput again?(Y/N): ");
    scanf("%c",&t);
    if((t=='Y')||(t=='y')) score_ma();
    if((t=='N')||(t=='n')) search();
   }
}



score_en()
{int i,k,j;
 char t;
 printf("please input a score: ");
 scanf("%d",&i);
 do
 {
  if((i<0)&&(i>100))
   {printf("score input error!\nplease input again: ");
    scanf("%d",&i);
    printf("\n");
   }
  else break;
 }while(1);
 for(j=0,k=0;j<SIZE;j++)
  {if(i==s[i].chinese)
   printf("These students have this score:\n");
   printf("------Name\tSex\tNumber\tAge\tenglish------\n");
   printf("      %s\t%c\t%d\t%d\t%d      \n"),k++;
  }
 if(k==0)
   {
    printf("There is no student have this score!\ninput again?(Y/N): ");
    scanf("%c",&t);
    if((t=='Y')||(t=='y')) score_en();
    if((t=='N')||(t=='n')) search();
   }
}



score_co()
{int i,k,j;
 char t;
 printf("please input a score: ");
 scanf("%d",&i);
 do
 {
  if((i<0)&&(i>100))
   {printf("score input error!\nplease input again: ");
    scanf("%d",&i);
    printf("\n");
   }
  else break;
 }while(1);
 for(j=0,k=0;j<SIZE;j++)
  {if(i==s[i].chinese)
   printf("These students have this score:\n");
   printf("------Name\tSex\tNumber\tAge\tcomputer------\n");
   printf("      %s\t%c\t%d\t%d\t%d      \n"),k++;
  }
 if(k==0)
   {
    printf("There is no student have this score!\ninput again?(Y/N): ");
    scanf("%c",&t);
    if((t=='Y')||(t=='y')) score_co();
    if((t=='N')||(t=='n')) search();
   }
}


input()
{
}

modify()
{
}

average()
{int i;
 clrscr();
 menu3();
 scanf("%d",&i);
  switch(i)
  {case 1:ave_ch();break;
   case 2:ave_ma();break;
   case 3:ave_en();break;
   case 4:ave_co();break;
   default:printf("input error!\n");average();break;
   }
}


ave_ch()
{char i;
 float j,k,t;
 j=ch_cl(s);
 k=ch_b(s);
 t=ch_g(s);
 printf("\n----------------Chinese average score----------------\n");
 printf("   class\t  boys\t  girls\t\n");
 P();
 printf("  %f\t  %f\t  %f\t\n",j,k,t);
}


int ch_cl(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   sum+=s[i].chinese;
 ave=sum/SIZE;
  return(ave);
}

int ch_b(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='m')
    sum+=s[i].chinese;
    }
 ave=sum/SIZE;
 return(ave);;
}


int ch_g(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='g')
    sum+=s[i].chinese;
    }
 ave=sum/SIZE;
 return(ave);;
}

ave_ma()
{char i;
 float j,k,t;
 j=ma_cl(s);
 k=ma_b(s);
 t=ma_g(s);
 printf("\n----------------Math average score----------------\n");
 printf("   class\t  boys\t  girls\t\n");
 P();
 printf("  %f\t  %f\t  %f\t\n",j,k,t);
}

int ma_cl(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   sum+=s[i].math;
 ave=(float)sum/SIZE;
  return(ave);
}

int ma_b(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='m')
    sum+=s[i].math;
    }
 ave=(float)sum/SIZE;
 return(ave);;
}


int ma_g(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='g')
    sum+=s[i].math;
    }
 ave=(float)sum/SIZE;
 return(ave);;
}

ave_en()
{char i;
 float j,k,t;
 j=en_cl(s);
 k=en_b(s);
 t=en_g(s);
 printf("\n----------------English average score----------------\n");
 printf("   class\t  boys\t  girls\t\n");
 P();
 printf("  %f\t  %f\t  %f\t\n",j,k,t);
}


int en_cl(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   sum+=s[i].english;
 ave=(float)sum/SIZE;
  return(ave);
}

int en_b(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='m')
    sum+=s[i].english;
    }
 ave=(float)sum/SIZE;
 return(ave);;
}


int en_g(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='g')
    sum+=s[i].english;
    }
 ave=(float)sum/SIZE;
 return(ave);;
}

ave_co()
{char i;
 float j,k,t;
 j=co_cl(s);
 k=co_b(s);
 t=co_g(s);
 printf("\n----------------Computer average score----------------\n");
 printf("   class\t  boys\t  girls\t\n");
 P();
 printf("  %f\t  %f\t  %f\t\n",j,k,t);
}


int co_cl(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   sum+=s[i].computer;
 ave=(float)sum/SIZE;
  return(ave);
}

int co_b(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='m')
    sum+=s[i].computer;
    }
 ave=(float)sum/SIZE;
 return(ave);;
}


int co_g(struct student s[])
{int ave;
 int sum=0,i;
 for(i=0;i<SIZE;i++)
   {if(s[i].sex=='g')
    sum+=s[i].computer;
    }
 ave=(float)sum/SIZE;
 return(ave);;
}





ranking()
{
}



main()
{int i;
 clrscr();
 textcolor(11);
 textbackground(5);
 clrscr();
 read_in();
 do
   {

    menu();
    scanf("%d",&i);
    switch(i)
    {case 1:search();break;
     case 2:input();break;
     case 3:modify();break;
     case 4:average();break;
     case 5:ranking();break;
     case 6:exit(0);break;
     }
    }
   while(1);
}







搜索更多相关主题的帖子: computer english Chinese include please 
2009-12-29 13:02
a442579302
Rank: 2
来 自:C入门
等 级:论坛游民
帖 子:29
专家分:39
注 册:2009-12-29
收藏
得分:0 
对了    本人初学不久
还不会用链表 见笑了。。。。

理想很丰满·~现实很骨感!
2009-12-29 13:11
liangwenbc
Rank: 3Rank: 3
来 自:广州
等 级:论坛游侠
帖 子:168
专家分:174
注 册:2008-6-11
收藏
得分:0 
现在的初学者都很厉害啊

qq7434391
2009-12-29 14:05
a442579302
Rank: 2
来 自:C入门
等 级:论坛游民
帖 子:29
专家分:39
注 册:2009-12-29
收藏
得分:0 
大哥们   指点下啊!
为什么我调用 search_na()/*按姓名查找*/   会自动弹回主菜单?
还有我文件存取也有问题啊!

哎! 这是我人生写的第一个程序,高手们帮帮忙吧,感激不尽!

难道是我写的风格不好?......

理想很丰满·~现实很骨感!
2009-12-29 19:39
maoyan20034
Rank: 2
等 级:论坛游民
帖 子:27
专家分:46
注 册:2009-11-30
收藏
得分:10 
好长的程序,既然能学这么长了,应该去学下调试,VC++里断点调试

有时候沉迷是一种境界!
不是非主流!不是信春哥! 是C语言!

  
2009-12-29 21:43
ljc_zy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:131
注 册:2009-7-14
收藏
得分:10 
模块化编程
一个个功能加。不然调试很麻烦的。

恋恋花事 www.
2009-12-29 22:09
快速回复:大家帮忙看看这段程序的问题~~·谢了(急!)
数据加载中...
 
   



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

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