论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

不要看代码冗长,我们只抓算法

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:45:12


#include"stdio.h"
#include"string.h"
#include"math.h"
#define N 27
void change_position(struct cla *p1,struct cla *p2);
void hong_guan();
void ordered_by_average(struct cla *p,int n);
void print_cal11_list(struct cla *p,int n);
void print_score11_list(struct subject *p,int n);
void read_a_person(struct cla *p,FILE *fp);
void read_a_subject(struct subject *p,FILE *fp);
void serach_failed_student();
void serach_best_student();
void serach_personal_detail(char *pp);
void tongji_fenshu(int sname);
float work_out_average(struct cla *p,int n);
void work_out_standard(int sname);
/*全班结构体*/
struct cla{
   char xuehao[20];
   char name[20];
   float escore;
   float cscore;
   float mscore;
   float lscore;
   float pscore;
   float average;
}cla11[N];
/*学分结构体*/
struct subject{
int bianhao;
char sub[20];
float score;
}score11[5];

/*唐诗欣赏*/
void tang_poem()
{FILE *fp,*fpl,*fpb,*fpc,*fpd,*fpl1,*fpl2;
 int i=0,j=0;
head:fp=fopen("d:\\唐诗欣赏.txt","r");while(!feof(fp))
  putchar(fgetc(fp));
printf("请选择选项:");
scanf("%d",&i);
 
        switch(i)
{
 c1: case 1:fpl=fopen("d:\\李白.txt","r");while(!feof(fpl))
putchar(fgetc(fpl));printf("请选择选项:");
scanf("%d",&j);
 switch(j)
{case 1:fpl1=fopen("d:\\李白1.txt","r");while(!feof(fpl1))
  putchar(fgetc(fpl1));getchar();printf("是否返回李白菜单(y/n):");if(getchar()=='y') goto c1;else goto head;
 case 2:fpl2=fopen("d:\\李白2.txt","r");while(!feof(fpl2))
  putchar(fgetc(fpl2));getchar();printf("是否返回李白菜单(y/n):");if(getchar()=='y') goto c1;else goto head;
 case 3:goto head;
 default:printf("对不起,你的选项超出了范围,请再选\n");break;
}
 case 2:fpb=fopen("d:\\白居易.txt","r");while(!feof(fpb))
  putchar(fgetc(fpb));getchar();printf("是否返回唐诗欣赏(y/n):");if(getchar()=='y') goto head;else break;
 case 3:fpc=fopen("d:\\崔颢.txt","r");while(!feof(fpc))
  putchar(fgetc(fpc));getchar();printf("是否返回唐诗欣赏(y/n):");if(getchar()=='y') goto head;else break;
 case 4:fpd=fopen("d:\\杜牧.txt","r");while(!feof(fpd))
  putchar(fgetc(fpd));getchar();printf("是否返回唐诗欣赏(y/n):");if(getchar()=='y') goto head;else break;
 case 5:break;
default:printf("对不起,你的选项超出了范围,请再选\n");break;
}
}

 

 

/*查询不及格学生函数*/
void serach_failed_student()
{struct cla *p=cla11;
 int v=0,i;
  
  printf("学号           姓名      英语   C语言  数学   线代   物理\n");
  for(i=0; i<N; i++,p++)
      {if(p->escore<60||p->cscore<60||p->mscore<60||p->lscore<60||p->pscore<60)
        {
       printf("%-15s",p->xuehao);
    printf("%-10s",p->name);
    v++;

         if(p->escore<60)
    printf("%-7.1f",p->escore);else printf("及格   ");
         if(p->cscore<60)printf("%-7.1f",p->cscore);else printf("及格   ");
         if(p->mscore<60)printf("%-7.1f",p->mscore);else printf("及格   ");
  if(p->lscore<60)printf("%-7.1f",p->lscore);else printf("及格   ");
  if(p->pscore<60){printf("%-7.1f",p->average);printf("\n");}
        else {printf("及格   ");printf("\n");}
        }
      }
  if(v==0)printf("there is no student fail in the exam\n");
  else printf("(%d student failed in the exam\n",v);
}
/*查询个人成绩函数*/
void serach_personal_detail(char *pp)
{
 int i = 0,v=0;


 struct cla *p=cla11;
   //printf("学号           姓名      英语   C语言  数学   线代   物理   平均分\n");

   while(i<N)
  {
   
   if(strcmp(p->name,pp)==0||strcmp(p->xuehao,pp)==0)
    {printf("学号           姓名      英语   C语言  数学   线代   物理   平均分\n");
  printf("%-15s",p->xuehao);
     printf("%-10s",p->name);
     printf("%-7.1f",p->escore);
     printf("%-7.1f",p->cscore);
     printf("%-7.1f",p->mscore);
     printf("%-7.1f",p->lscore);
     printf("%-7.1f",p->pscore);
     printf("%-7.1f",p->average);printf("\n");v++;
     }p++;i++;
   }if(v==0)printf("                   =============不存在此学生==============\n");
   
}
/*查询全班宏观成绩函数*/
void hong_guan()
{struct cla *p1=cla11;
 struct subject *p2=score11;
 /*char *pe,*pc,*pm,*pl,*pp;
 pe="escore";
 pc="cscore";
 pm="mscore";
 pl="lscore";
 pp="pscore";*/

 

   printf("编号   课程名    平均分     标准差     优秀   良好   中等   及格   不及格\n");
   printf("1      英语      5.5     ");work_out_standard(1);tongji_fenshu(1);printf("\n");
   printf("2      C语言     3.0     ");work_out_standard(2);tongji_fenshu(2);printf("\n");
   printf("3      数学      5.5     ");work_out_standard(3);tongji_fenshu(3);printf("\n");
   printf("4      线代      2.0     ");work_out_standard(4);tongji_fenshu(4);printf("\n");
   printf("5      物理      5.0     ");work_out_standard(5);tongji_fenshu(5);printf("\n");
}
/*查询优秀学生函数*/
void serach_best_student()
{struct cla *p=cla11;
 int i;
   printf("   学号     姓名        英语   C语言  数学   线代   物理   平均分\n");
   for(i=0;i<4;i++,p++)
    {printf("%-12s",p->xuehao);
     printf("%-12s",p->name);
     printf("%-7.1f",p->escore);
     printf("%-7.1f",p->cscore);
     printf("%-7.1f",p->mscore);
     printf("%-7.1f",p->lscore);
     printf("%-7.1f",p->pscore);
     printf("%-7.1f",p->average);printf("\n");
     }
   for(;i<N;i++,p++)
    {if(p->average>=91||(p->average>=87&&(p->escore==100||p->cscore==100||p->mscore==100||p->lscore==100||p->pscore==100))) 
    {printf("%-12s",p->xuehao);
     printf("%-12s",p->name);
     printf("%-7.1f",p->escore);
     printf("%-7.1f",p->cscore);
     printf("%-7.1f",p->mscore);
     printf("%-7.1f",p->lscore);
     printf("%-7.1f",p->pscore);
     printf("%-7.1f",p->average);printf("\n");
     }
    }
}


/*计算学科标准差函数*/
void work_out_standard(int sname)
{struct cla *p=cla11;
 float x=0,s=0;
 int i=0;
 
  while(i<N)
{
  switch(sname)
  {
  case 1:x=x+p->escore;break;
  case 2:x=x+p->cscore;break;
  case 3:x=x+p->msco re;break;
  case 4:x=x+p->lscore;break;
  case 5:x=x+p->pscore;break;
  default:printf("no this subject11:\n");break;
  }

   p++;i++;
}
  x=x/N;
 i=0;p=cla11;
 while(i<N)
  {
  switch(sname)
  {
  case 1:s=s+(p->escore-x)*(p->escore-x);break;
  case 2:s=s+(p->cscore-x)*(p->cscore-x);break;
  case 3:s=s+(p->mscore-x)*(p->mscore-x);break;
  case 4:s=s+(p->lscore-x)*(p->lscore-x);break;
  case 5:s=s+(p->pscore-x)*(p->pscore-x);break;
  default:printf("no this subject12:\n");break;
  }

 
  p++;i++;}
  printf("%7.1f",sqrt(s/N));
}


/*统计分数段人数函数*/
void tongji_fenshu(int sname)
{struct cla *p=cla11;
 int i=0;
 int best=0,better=0,good=0,justgood=0,fail=0;
  
 
  while(i<N)
  {
   switch(sname)
  {
   case 1:{if(p->escore>=90)best++;
    else if(p->escore>=80) better++;
    else if(p->escore>=70) good++;
    else if(p->escore>=60) justgood++;
    else fail++;}break;
  case 2:{if(p->cscore>=90)best++;
    else if(p->cscore>=80) better++;
    else if(p->cscore>=70) good++;
    else if(p->cscore>=60) justgood++;
    else fail++;}break;
  case 3:{if(p->mscore>=90)best++;
    else if(p->mscore>=80) better++;
    else if(p->mscore>=70) good++;
    else if(p->mscore>=60) justgood++;
    else fail++;}break;
  case 4:{if(p->lscore>=90)best++;
    else if(p->lscore>=80) better++;
    else if(p->lscore>=70) good++;
    else if(p->lscore>=60) justgood++;
    else fail++;}break;
  case 5:{ if(p->pscore>=90) best++;
   else if(p->pscore>=80) better++;
   else if(p->pscore>=70) good++;
   else if(p->pscore>=60) justgood++;
   else fail++;} break;
  default:printf("no this subject:\n");break;
  }
  
 p++;i++;
  }
  printf("%8d  ",best);
  printf("%6d  ",better);
  printf("%6d  ",good);
  printf("%6d  ",justgood);
  printf("%6d  ",fail);
 // printf("end! ");
  printf("\n");
}
 
/*求平均分函数*/
float work_out_average(struct cla *p,int n)
{return (p->escore+p->cscore+p->mscore+p->lscore+p->pscore)/n;}

 

/*交换函数*/
/*void change_position(struct cla *p1,struct cla *p2)
{struct cla mid;
 

  strcpy(mid.xuehao,p1->xuehao);
  strcpy(mid.name,p1->name);
  mid.average=p1->average;
  mid.cscore=p1->cscore;
  mid.escore=p1->escore;
  mid.lscore=p1->lscore;
  mid.mscore=p1->mscore;
  mid.pscore=p1->pscore;
 
 
  strcpy(p1->xuehao,p2->xuehao);
  strcpy(p1->name,p2->name);
  p1->average=p2->average;
  p1->cscore=p2->cscore;
  p1->escore=p2->escore;
  p1->lscore=p2->lscore;
  p1->mscore=p2->mscore;
  p1->pscore=p2->pscore;

  strcpy(p2->xuehao,mid.xuehao);
  strcpy(p2->name,mid.name);
  p2->average=mid.average;
  p2->cscore=mid.cscore;
  p2->escore=mid.escore;
  p2->lscore=mid.lscore;
  p2->mscore=mid.mscore;
  p2->pscore=mid.pscore;
}*/

 


/*按平均分全班排名函数*/
void ordered_by_average(struct cla *p,int n)
{int i=0,j=0,flag;
 struct cla mid;
 for(i=0;i<n-1;i++)
   {flag=i;
 for(j=i+1;j<n;j++)
  if(p[flag].average<p[j].average)flag=j;
        {mid=p[i];
                p[i]=p[flag];
                p[flag]=mid;}
 }
}
/*打印班级结构体数组函数*/
void print_cal11_list(struct cla *p,int n)
{int i=0;
struct cla *mid;

 printf("  学号        姓名        英语   C语言    数学   线代     物理   平均分  名次\n");
 while(i<n)
 {mid=p;
  printf("%-10s   ",p->xuehao);
  printf("%-10s   ",p->name);
  printf("%-5.1f   ",p->escore);
  printf("%-5.1f   ",p->cscore);
  printf("%-5.1f   ",p->mscore);
  printf("%-5.1f   ",p->lscore);
  printf("%-5.1f   ",p->pscore);
  printf("%-5.1f   ",p->average);
  if(mid->average==(mid+1)->average)printf("%-3d",i);
  else printf("%-3d",i+1);printf("\n");
  i++;p++;
 }
}
/*打印学科结构体数组函数*/
void print_score11_list(struct subject *p,int n)
{int i=0;
  printf("          编号    学科              学分\n");
 while(i<n)
 {printf("          %-5d",p->bianhao);printf("   ");
  printf("          %-15s",p->sub);printf("   ");
  printf("          %-5.1f",p->score);printf("\n");
  i++;p++;
 }
}


/*读入班级数据函数*/
void read_a_person(struct cla *p,FILE *fp)
{ fscanf(fp,"%s%s%f%f%f%f%f",p->xuehao,p->name,&p->escore,&p->cscore,&p->mscore,&p->lscore,&p->pscore);}
/*读入学分数据函数*/
void read_a_subject(struct subject *p,FILE *fp)
{ fscanf(fp,"%d%s%f",&p->bianhao,p->sub,&p->score);}

 


/*主函数*/
void main()
{FILE *fp1,*fp2,*fp3,*fp4;
 
 char c;
 struct cla *pperson=cla11;
 struct subject *psubject=score11;

 
 
 
 fp1=fopen("d:\\jz03227.txt","r");
 while(!feof(fp1))
 { read_a_person(pperson,fp1);
 pperson->average=work_out_average(pperson,5);
         pperson++;
         }
 
 
 fp2=fopen("d:\\jz032.txt","r");
 while(!feof(fp2))
       {read_a_subject(psubject,fp2);psubject++;
        }

 

 
   pperson=cla11;

  loo:

   fp3=fopen("d:\\menu.txt","r");
   while(!feof(fp3))
  putchar(fgetc(fp3));
  printf("请选择选项:");
  scanf("%c",&c);
  getchar();
 
     switch(c)
   {
       case 'a':{ordered_by_average(cla11,N);print_cal11_list(cla11,N);printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}}
       case 'b':hong_guan();printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
       case 'c':{char no[20];printf("请输入姓名or学号:");gets(no);serach_personal_detail(no);printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
    }
       case 'd':serach_failed_student();printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
       case 'e':{ordered_by_average(cla11,N);serach_best_student();printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}}
       case 'f':print_score11_list(score11,5);printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
       case 'g':fp4=fopen("d:\\系 统的说明.txt","r");while(!feof(fp4))putchar(fgetc(fp4));printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
       case 'h':tang_poem();getchar();printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
    case 'i':break;
   
   


    default:printf("对不起,你的选项超出了范围,请再选\n");printf("是否返回主菜单(y/n):");if(getchar()=='y') {getchar();goto loo;}else {getchar();break;}
   }
}

视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058