学生管理.c.txt

来自「一个简单的turbo c的学生管理的源程序」· 文本 代码 · 共 869 行 · 第 1/2 页

TXT
869 行
字号
 window(1,1,80,25);
 }
 void Wind( int x1,int y1,int x2,int y2,int FR,int IS,int BC,int TC,int BG)
 { int i;
 int c[2][6]={{0xda,0xc4,0xbf,0xb3,0xc0,0xd9},
          {0xc9,0xcd,0xbb,0xba,0xc8,0xbc}};
 textcolor(TC);
 textbackground(BC);
 window(x1,y1,x2,y2);
 clrscr();
 if(FR)
 { window(1,1,80,25);
 gotoxy(x1,y1);
 putch(c[FR-1][0]);
 for(i=x1+1;i<x2;i++)
 putch(c[FR-1][1]);
 putch(c[FR-1][2]);
 for(i=y1+1;i<y2;i++)
 { gotoxy(x1,i);
 putch(c[FR-1][3]);
 gotoxy(x2,i);
 putch(c[FR-1][3]);}
 gotoxy(x1,y2);
 putch(c[FR-1][4]);
 for(i=x1+1;i<x2;i++)
 putch(c[FR-1][1]);
 putch(c[FR-1][5]); }
 if(IS)
 textcolor(BG);
 textbackground(0);
 for(i=y1+1;i<y2+1;i++)
 { gotoxy(x2+1,i); }
 for(i=x1+1;i<x2+2;i++)
 { gotoxy(i,y2+1); }
 window(x1+1,y1+1,x2-1,y2-1);
 }
 void Quit()
 { textbackground(0);
 textcolor(7);
 window(1,1,80,25);
 clrscr();
 exit(0);}
void into()
  { char filename[15];
  int a,i,sum;  int j,x1,y1,x2,y2;
   FILE *fp;  void *buf;
   window(1,5,80,25);
 /*  buf=(void *)malloc(2*80*25);
   gettext(1,5,80,20,buf);   */
   Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
   cprintf("输入人数:");
    scanf("%d",&a);
   for(i=0;i<a&&Key!=ESC;i++)
   { Wind(1,2,80,23,2,0,1,15,1);
     textbackground(BLUE);
      cprintf("输入姓名:");
     scanf("%s",stu[i].name);gotoxy(2,2);
     cprintf("学生信息");gotoxy(2,3);
     cprintf("学号:");scanf("%d",&stu[i].num);gotoxy(2,4);
     cprintf("班级:");scanf("%s",&stu[i].class);gotoxy(2,5);
     cprintf("性别:");scanf("%s",stu[i].sex);gotoxy(2,6);
     cprintf("出生日期:");gotoxy(15,6);
     cprintf("年:");scanf("%d",&stu[i].birth.year);gotoxy(23,6);
     cprintf("月:");scanf("%d",&stu[i].birth.month);gotoxy(31,6);
     cprintf("日:");scanf("%d",&stu[i].birth.date);gotoxy(2,7);
     cprintf("政治面貌:");scanf("%s",stu[i].pol);gotoxy(2,8);
     cprintf("家庭住址:");scanf("%s",stu[i].addr);
     getchar();clrscr();}
     for(i=0;i<a&&Key!=ESC&&Key!=ALT_X;i++)
    { Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
    cprintf("姓名:%s",stu[i].name);gotoxy(2,2);
    cprintf("输入期末成绩:\n");
    printf("高等数学  英语  C语言  大学物理  马哲");gotoxy(2,4);
    scanf("%d%d%d%d%d",&stu[i].score.score1[0],&stu[i].score.score1[1],
    &stu[i].score.score1[2],&stu[i].score.score1[3],&stu[i].score.score1[4]);
    printf("\nif you want to stop; please enter ESC");
      getchar();clrscr();}
   fp=fopen("a:\\stu.new","a+");
 for(i=0;i<a;i++)
 fwrite(&stu[i],sizeof(struct student),1,fp);
  fclose(fp);
   return; }
 void insert()                               /*插入学号*/
  { FILE *fp;
  int i,h,e,j,t, numb;
   Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
   cprintf("输入插入的学号:");
 scanf("%d",&numb);
 if((fp=fopen("a:\\stu.new","r"))==NULL)
 {cprintf("文件打不开!");
 exit(0);}
 for(i=0,j=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
   if(stu[i].num<numb)   j++;
 fclose(fp);
 h=j;
 fp=fopen("a:\\stu.new","r");
 for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++) ;
 e=i;
  /*move datas*/
     for(j=e-1;j>=h;j--)
    { stu[j+1]=stu[j]; }
    fclose(fp);
 fp=fopen("a:\\stu.new","w+");
   gotoxy(2,2);
   cprintf("输入姓名:");
   scanf("%s",stu[h].name);gotoxy(2,3);
   cprintf("学生信息:");gotoxy(2,4);
   cprintf("班级:");scanf("%s",&stu[h].class);gotoxy(2,5);
   cprintf("性别:");scanf("%s",stu[h].sex);gotoxy(2,6);
   cprintf("出生日期:");gotoxy(15,6);
   cprintf("年:");scanf("%d",&stu[h].birth.year);gotoxy(23,6);
   cprintf("月:");scanf("%d",&stu[h].birth.month);gotoxy(31,6);
   cprintf("日:");scanf("%d",&stu[h].birth.date);gotoxy(2,7);
   cprintf("政治面貌:");scanf("%s",stu[h].pol);gotoxy(2,8);
   cprintf("家庭住址:");scanf("%s",stu[h].addr);
   getchar();clrscr();
    cprintf("姓名:%s\n",stu[h].name);
     Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
    cprintf("输入期末成绩 :");gotoxy(2,2);
    printf("高等数学  英语  C语言  大学物理  马哲");gotoxy(2,3);
    scanf("%d%d%d%d%d",&stu[h].score.score1[0],&stu[h].score.score1[1],
    &stu[h].score.score1[2],&stu[h].score.score1[3],&stu[h].score.score1[4]);
     for(i=0;i<=e;i++)
      fwrite(&stu[i],sizeof(struct student),1,fp);
     fclose(fp);  getchar();clrscr(); return;  }
void fromname()                              /*按名字查询*/
{  FILE *fp;
int i,n,flag=0,t;
char str[10],key;
  Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
 if((fp=fopen("a:\\stu.new","r"))==NULL)
 {printf("file can't open");  getch();
 exit(0);}
 for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++);
 n=i;
 while(1)
 { Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
 cprintf("输入姓名:");
   scanf("%s",str);
   for(i=0;i<n;i++)
  { if(strcmp(str,stu[i].name)==0)
    {gotoxy(2,2);cprintf("学生的信息:");gotoxy(2,3);
   cprintf("学号:%d",stu[i].num);gotoxy(2,4);
   cprintf("班级:%s",stu[i].class);gotoxy(2,5);
   cprintf("性别:%s",stu[i].sex);gotoxy(2,6);
   cprintf("出生日期:"); gotoxy(15,6);
   cprintf("年:%d",stu[i].birth.year);gotoxy(23,6);
   cprintf("月:%d",stu[i].birth.month);gotoxy(31,6);
   cprintf("日:%d",stu[i].birth.date);gotoxy(2,7);
   cprintf("政治面貌:%s",stu[i].pol);gotoxy(2,8);
   cprintf("家庭住址:%s",stu[i].addr);gotoxy(2,9);
   cprintf("期末成绩:");gotoxy(12,9);
   cprintf("高等数学:%d",stu[i].score.score1[0]);gotoxy(25,9);
   cprintf("英语:%d",stu[i].score.score1[1]);gotoxy(35,9);
   cprintf("C语言:%d",stu[i].score.score1[2]);gotoxy(45,9);
   cprintf("大学物理:",stu[i].score.score1[3]);gotoxy(58,9);
   cprintf("马哲:%d",stu[i].score.score1[4]);gotoxy(68,9);
   cprintf("平均分:%d",(stu[i].score.score1[0]+stu[i].score.score1[1]+
    stu[i].score.score1[2]+stu[i].score.score1[3]+stu[i].score.score1[4])/5);
       flag++; }
     }
    if(flag==0)
     { gotoxy(2,10);
       textattr(0x3e);
       cprintf(" 找不到!");
    }
       gotoxy(2,15);
       textattr(0x3e);
       cprintf("继续吗?(Y/N):");
      if((getch()=='n')||(getch()=='N'))
       { window(1,1,80,25);clrscr();break;}
    clrscr();     }
   fclose(fp);
    return;}
  void fromnum()                 /*按学号查询*/
   {  FILE *fp;
   int i,n,num,flag=0,t;
   char key;
   Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
 if((fp=fopen("a:\\stu.new","r"))==NULL)
 {printf("file can't open");  getch();
 exit(0);}
 for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++);
 n=i;
 while(1)
 {  Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
 cprintf("输入学号:");
 scanf("%d",&num);
 for(i=0;i<n;i++)
 { if(num==stu[i].num)
   {gotoxy(2,2);cprintf("姓名:%s",stu[i].name);gotoxy(2,3);
   cprintf("学号:%d",stu[i].num);gotoxy(2,4);
   cprintf("班级:%s",stu[i].class);gotoxy(2,5);
   cprintf("性别:%s",stu[i].sex);gotoxy(2,6);
   cprintf("出生日期");gotoxy(15,6);
   cprintf("年:%d",stu[i].birth.year);gotoxy(23,6);
   cprintf("月:%d",stu[i].birth.month);gotoxy(31,6);
   cprintf("日:%d",stu[i].birth.date);gotoxy(2,7);
   cprintf("政治面貌:%s",stu[i].pol);gotoxy(2,8);
   cprintf("家庭住址:%s",stu[i].addr);gotoxy(2,9);
   cprintf("期末成绩:");gotoxy(12,9);
   cprintf("高等数学:%d",stu[i].score.score1[0]);gotoxy(25,9);
   cprintf("英语:%d",stu[i].score.score1[1]);gotoxy(35,9);
   cprintf("C语言:%d",stu[i].score.score1[2]);gotoxy(45,9);
   cprintf("大学物理:%d",stu[i].score.score1[3]);gotoxy(58,9);
   cprintf("马哲:%d",stu[i].score.score1[4]);gotoxy(68,9);
   cprintf("平均分:%d",(stu[i].score.score1[0]+stu[i].score.score1[1]+
    stu[i].score.score1[2]+stu[i].score.score1[3]+stu[i].score.score1[4])/5);
   flag++; }
     }
     if(flag==0)
     { gotoxy(2,7);
       textattr(0x3e);
       cprintf(" 找不到!");
    }
       gotoxy(2,12);
       textattr(0x3e);
       cprintf("继续吗?(Y/N):");
       if((getch()=='n')||(getch()=='N'))
    {window(1,1,80,25);clrscr();  break;}
         clrscr();}
    fclose(fp);
    return;}

 void out()
  { FILE *fp;  char key;
  int i,j,n;  void *buffer;
    buffer=(void *)malloc(2*80*25);
    gettext(1,1,80,25,buffer);
   Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
  if((fp=fopen("a:\\stu.new","r"))==NULL)
 { gotoxy(2,1);
  cprintf("can't open!");
  exit(0);}

  for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0&&Key!=ESC;i++)
 { gotoxy(2,1);
   cprintf("假如想中断,按键B");gotoxy(2,2);
   cprintf("姓名:%s",stu[i].name);gotoxy(2,3);
   cprintf("学生信息:");gotoxy(2,4);
   cprintf("学号:%d",stu[i].num);gotoxy(2,5);
   cprintf("班级:%s",stu[i].class);gotoxy(2,6);
   cprintf("性别:%s",stu[i].sex);gotoxy(2,7);
   cprintf("出生日期");gotoxy(15,7);
   cprintf("年:%d",stu[i].birth.year);gotoxy(23,7);
   cprintf("月:%d",stu[i].birth.month);gotoxy(31,7);
   cprintf("日:%d",stu[i].birth.date);gotoxy(2,8);
   cprintf("政治面貌:%s",stu[i].pol);gotoxy(2,9);
   cprintf("家庭住址:%s",stu[i].addr);gotoxy(2,10);
   cprintf("输出期末成绩:");gotoxy(2,11);
   cprintf("高等数学:%d",stu[i].score.score1[0]);gotoxy(15,11);
   cprintf("英语:%d",stu[i].score.score1[1]);gotoxy(25,11);
   cprintf("C语言:%d",stu[i].score.score1[2]);gotoxy(35,11);
   cprintf("大学物理:%d",stu[i].score.score1[3]);gotoxy(48,11);
   cprintf("马哲:%d",stu[i].score.score1[4]);gotoxy(58,11);
   cprintf("平均分:%d",(stu[i].score.score1[0]+stu[i].score.score1[1]+
    stu[i].score.score1[2]+stu[i].score.score1[3]+stu[i].score.score1[4])/5);
    cprintf("按任意键继续!");
   key=getch();
   if(key=='B'||key=='b')
   { clrscr(); puttext(1,1,80,25,buffer);  free(buffer);getch(); return; }
   Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE); }
   fclose(fp);   return;}
   void sort()                                           /* 排序 */
   { FILE *fp;  void *buffer;
   int i,j,n,sum1[ALL],p[ALL];
    char key;
    buffer=(void *)malloc(2*80*25);
    gettext(1,1,80,25,buffer);
    Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
      gotoxy(2,1);
      cprintf("由分数排名:");
      gotoxy(30,1);
      cprintf("按任意键开始!");
      getch();
if((fp=fopen("a:\\stu.new","r"))==NULL)
  { gotoxy(2,5);
      cprintf("没有记录!");  getch();
       exit(0);}
 for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
{sum1[i]=stu[i].score.score1[0]+stu[i].score.score1[1]+stu[i].score.score1[2]+
       stu[i].score.score1[3]+stu[i].score.score1[4];
    stu[i].score.ave1=sum1[i]/5;
    p[i]=stu[i].score.ave1;
   n=i; fclose(fp);
  /*sort average*/
   for(i=0;i<n;i++)
   for(j=i+1;j<n;j++)
 if(p[i]<p[j])      /*平均分比较*/
 { MID=stu[i];
   stu[i]=stu[j];
   stu[j]=MID;}
  fp=fopen("a:\\stu.new","a+");
  for(i=0;i<n;i++)
  fwrite(&stu[i],sizeof(struct student),1,fp);
  fclose(fp);
  /*put out*/
   gotoxy(2,2);
   cprintf("结果是:");
   fp=fopen("a:\\stu.new","r");
  for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0&&Key!=ESC;i++)
  { gotoxy(2,3);
  cprintf("想中断,按键 B");
   gotoxy(2,4);
   cprintf("第%d名是:",i+1);gotoxy(2,5);
   cprintf("%s",stu[i].name);gotoxy(2,6);
   cprintf("期末成绩:");gotoxy(2,7);
   cprintf("高等数学:%d",stu[i].score.score1[0]);gotoxy(15,7);
   cprintf("英语:%d",stu[i].score.score1[1]);gotoxy(25,7);
   cprintf("C语言:%d",stu[i].score.score1[2]);gotoxy(35,7);
   cprintf("大学物理:%d",stu[i].score.score1[3]);gotoxy(48,7);
   cprintf("马哲:%d",stu[i].score.score1[4]);gotoxy(58,7);
   cprintf("平均分:%d",(stu[i].score.score1[0]+stu[i].score.score1[1]+
    stu[i].score.score1[2]+stu[i].score.score1[3]+stu[i].score.score1[4])/5);
   printf("按任意键继续");
   key=getch();
   if(key=='B'||key=='b')
   { clrscr(); puttext(1,1,80,25,buffer);  free(buffer);getch(); return;}
   Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE); }
   fclose(fp);   return;}
}
 void  quit()
 { char *log[]={"想退出?,YES OR NO?", "按键Y/N"};
 char key;
 Wind(30,10,60,20,2,0,1,15,1);
   textbackground(BLUE);
 do{textcolor(WHITE);
      gotoxy(1,3);cprintf("%s",log[0]);
      textcolor(WHITE);
      gotoxy(4,5);cprintf("%s",log[1]);
      gotoxy(21,5);
      key=getch();
      if(key=='y'||key=='Y')
      {window(1,1,80,25);clrscr();exit(0);}
      else if(key=='n'||key=='N') break;}
 while(1);
window(1,1,80,25);
}
void delete()          /*删除档案*/
 { FILE *fp; void *buf;
  int i,j,logic,del,n;
  char  ch,name[10];
  window(1,1,80,25);
  buf=(void *)malloc(80*2*25);
  gettext(1,1,80,25,buf);
  Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
  if((fp=fopen("a:\\stu.new","r"))==NULL)
 { gotoxy(2,1);                   /*将文本从存储区考备到屏幕*/
  cprintf("can't open!"); getch();puttext(1,1,80,25,buf);free(buf);return;}
  for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0&&Key!=ESC;i++);
  n=i; fclose(fp); gotoxy(2,1);
  cprintf("输入你想删除学生的姓名:");
  scanf("%s",name);  getch();
  for(i=0,logic=1;i<n&&logic;i++)
    {if(strcmp(name,stu[i].name)==0)
     { del=i; logic=0;}
    }
 if(!logic)
 n--;
 else { gotoxy(2,4);cprintf("不能找到,按键返回!");
 getch();puttext(1,1,80,25,buf);free(buf);return;}

 fp=fopen("a:\\stu.new","w");
 for(i=0;i<del;i++)
 fwrite(&stu[i],sizeof(struct student),1,fp);
 for(i=del+1;i<n;i++)
 fwrite(&stu[i],sizeof(struct student),1,fp);
 fclose(fp);
 gotoxy(2,5);
 cprintf("删除成功!");
 getch(); puttext(1,1,80,25,buf);free(buf);   return;  }
  void pass()                                        /*及格统计*/
  {  FILE *fp;
   int i,n,sum1[ALL],m1=0;
   char key;
    Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
 if((fp=fopen("a:\\stu.new","r"))==NULL)
 { gotoxy(2,1);
 cprintf("file can't open");  getch();
 exit(0);}
 for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++);
 n=i;  fclose(fp);
  for(i=0;i<n;i++)
  { if((stu[i].score.score1[0]>=60)&&(stu[i].score.score1[1]>=60)
  &&(stu[i].score.score1[2]>=60)&&(stu[i].score.score1[3]>=60)
  &&(stu[i].score.score1[4]>=60))  m1++; }
  gotoxy(2,6);
  cprintf("及格人数是(期末):%d",m1);
   getch();
  clrscr();
  return;}                            /*优秀统计*/
  void best()
  {   FILE *fp;
   int i,n,sum1[ALL];
   int t1=0;
   char key;
    Wind(1,2,80,23,2,0,1,15,1);
   textbackground(BLUE);
 if((fp=fopen("a:\\stu.new","r"))==NULL)
 { gotoxy(2,1);
 cprintf("file can't open");  getch();
 exit(0);}
 for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++);
 n=i;  fclose(fp);
for(i=0;i<n;i++)
{sum1[i]=stu[i].score.score1[0]+stu[i].score.score1[1]+stu[i].score.score1[2]+
       stu[i].score.score1[3]+stu[i].score.score1[4];
    stu[i].score.ave1=sum1[i]/5; }
     for(i=0;i<n;i++)
  { if((stu[i].score.score1[0]>=60)&&(stu[i].score.score1[1]>=60)
  &&(stu[i].score.score1[2]>=60)&&(stu[i].score.score1[3]>=60)
  &&(stu[i].score.score1[4]>=60)&&(stu[i].score.ave1>=80))  t1++;}
   gotoxy(2,6);
  cprintf("优秀人数是(期末):%d",t1);
  getch();
  clrscr();
  return;}
 
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?