⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delet.c

📁 设计一个学生成绩管理系统
💻 C
字号:
#include"jinhe.h"
void delet()
{ extern char filename[15];
  struct student stu[M],temp;
  FILE *fp;
  int i,k,flag=0;
  float temp1;
  clrscr();
  gotoxy(5,2);
  printf("****************Computer technology and science 2 ban****************");
  gotoxy(10,3);
  printf("--Input the student's message you want delete--");
  gotoxy(5,4);
  printf("|-------------------------------------------------------------------|");
  gotoxy(5,5);
  printf("|--NUMBER--|-----NAME------|-SEX-|-ENGLI-|-COMPE-|-MATH-|-CPR-|-AVE-|");
  gotoxy(5,6);
  printf("|----------|---------------|-----|-------|-------|------|-----|-----|");
  gotoxy(5,7);printf("|");
  gotoxy(16,7);printf("|");
  gotoxy(32,7);printf("|");
  gotoxy(38,7);printf("|");
  gotoxy(46,7);printf("|");
  gotoxy(54,7);printf("|");
  gotoxy(61,7);printf("|");
  gotoxy(67,7);printf("|");
  gotoxy(73,7);printf("|");
  gotoxy(6,7);scanf("%ld",&temp.no);
  gotoxy(17,7);scanf("%s",&temp.name);
  gotoxy(33,7);scanf("%s",&temp.sex);
  gotoxy(39,7);scanf("%f",&temp1); temp.english=temp1;
  gotoxy(47,7);scanf("%f",&temp1); temp.computer=temp1;
  gotoxy(55,7);scanf("%f",&temp1); temp.maths=temp1;
  gotoxy(62,7);scanf("%f",&temp1); temp.c_programe=temp1;
  temp.average=(temp.english+temp.computer+temp.c_programe+temp.maths)/4;
  gotoxy(68,7);printf("%.1lf",temp.average);
  gotoxy(5,8);printf("|----------|---------------|-----|-------|-------|------|-----|-----|");
  if((fp=fopen(filename,"rb"))==NULL)
  { clrscr();
    gotoxy(15,15);
    printf("Cannot open file.Please press any key return.");
    getch();
    return;
  }
  for(i=0;;i++)
  { fread(&stu[i],LEN,1,fp);
    if(flag==1) break;
    if(stu[i].no==0)
    { clrscr();
      gotoxy(5,15);
      printf("Cannot find the student to delete.");break;
    }
    if(temp.no==stu[i].no)
    { for(k=i+1;;i=k,k++)
      { fread(&stu[k],LEN,1,fp);
	stu[i].no=stu[k].no;
	if(stu[k].no==0) { stu[i].no=0;flag=1;break;}
	strcpy(stu[i].name,stu[k].name);
	strcpy(stu[i].sex,stu[k].sex);
	stu[i].english=stu[k].english;
	stu[i].computer=stu[k].computer;
	stu[i].maths=stu[k].maths;
	stu[i].c_programe=stu[k].c_programe;
	stu[i].average=stu[k].average;
      }
      clrscr();
      gotoxy(5,15);
      printf("Success to delete the student!");
    }
  }
  fclose(fp);
  if((fp=fopen(filename,"wb"))==NULL)
  { clrscr();
    gotoxy(15,15);
    printf("Cannot open file. Press any key return.");
    getch();
    return;
  }
  for(i=0;;i++)
   { if(fwrite(&stu[i],LEN,1,fp)!=1)
     { clrscr();
       gotoxy(15,15);
       printf("file write error.Press any key return.");
       getch();
       return;}
     if(stu[i].no==0) break;
   }
  fclose(fp);
  getch();
}


⌨️ 快捷键说明

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