📄 skt.txt
字号:
if(in==1)
{
printf("请输入你要删除的学生姓名: ");
getchar();
gets(tempname);
for(i=0;i<count;i++)
if(strcmp(tempname,p_student[i].name)==0)
{
printf("你要删除的姓名为%s的学生成绩表\n",tempname);
printf("——————————————————————————\n");
printf("\n学号: %d\n",p_student[i].ID);
printf("\n姓名: %s\n",p_student[i].name);
printf("\n班级: %s\n",p_student[i].clas);
printf("\n语文: %.2f\n",p_student[i].sorc[0]);
printf("\n数学: %.2f\n",p_student[i].sorc[1]);
printf("\n英语: %.2f\n",p_student[i].sorc[2]);
printf("——————————————————————————\n");
n++;
}
else
{
if(fwrite(&p_student[i],sizeof(struct studentsorc),1,sorcfile)!=1)
{
fclose(sorcfile); //写入失败关闭文件
printf("\t\t\t删除失败,返回.......!");
getch();
system("cls");
return ;
}
}
if(n==0)
{
printf("找不到该学生,返回...!");
getch();
system("cls");
return ;
}
else
{
printf("删除成功...!");
fclose(sorcfile);
getch();
system("cls");
return ;
}
}
else if(in==2)
{
printf("请输入你要删除的学生学号: ");
scanf("%d",&stuID);
for(i=0;i<count;i++)
if(stuID==p_student[i].ID)
{
printf("你要删除的学号为%d的学生成绩表\n",stuID);
printf("——————————————————————————\n");
printf("\n学号: %d\n",p_student[i].ID);
printf("\n姓名: %s\n",p_student[i].name);
printf("\n班级: %s\n",p_student[i].clas);
printf("\n语文: %.2f\n",p_student[i].sorc[0]);
printf("\n数学: %.2f\n",p_student[i].sorc[1]);
printf("\n英语: %.2f\n",p_student[i].sorc[2]);
printf("——————————————————————————\n");
n++;
}
else
{
if(fwrite(&p_student[i],sizeof(struct studentsorc),1,sorcfile)!=1)
{
fclose(sorcfile); //写入失败关闭文件
printf("\t\t\t删除失败,返回.......!");
getch();
system("cls");
return ;
}
}
if(n==0)
{
printf("找不到该学生,返回...!");
getch();
system("cls");
return ;
}
else
{
printf("删除成功...!");
fclose(sorcfile);
getch();
system("cls");
return ;
}
}
else
{
printf("输入有误,返回...!");
fclose(sorcfile);
getch();
system("cls");
return ;
}
}
/*********************查询学生个人信息****************************/
void seasorc1(struct studentsorc *p_student)
{
int tempID,stuID,i,j,count,n=0;
char tempname[20];
float sum=0,aver;
count=sorcdatfile(p_student);
if(!count)
{
printf("读取数据失败,请确认数据是否存在或文件是否损害");
getch();
system("cls");
return ;
}
printf("请选择要操作的类形:\n");
printf("1.按姓名查找 2.按学号查找\n");
scanf("%d",&tempID);
if(tempID==1) //按姓名查询
{
printf("请输入该学生的姓名: ");
getchar();
gets(tempname);
for(i=0;i<count;i++)
if(strcmp(tempname,p_student[i].name)==0)
{
sum=0;
for(j=0;j<3;j++)
sum+=p_student[i].sorc[j]; //计算总分
aver=sum/3.0; //计算平均分
printf("%s的学生成绩表\n",tempname);
printf("——————————————————————————\n");
printf("\n学号: %d\n",p_student[i].ID);
printf("\n姓名: %s\n",p_student[i].name);
printf("\n班级: %s\n",p_student[i].clas);
printf("\n语文: %.2f\n",p_student[i].sorc[0]);
printf("\n数学: %.2f\n",p_student[i].sorc[1]);
printf("\n英语: %.2f\n",p_student[i].sorc[2]);
printf("\n总分: %.2f\n",sum);
printf("\n平均分: %.2f\n",aver);
printf("——————————————————————————\n");
n++;
}
if(n==0)
{
printf("找不到该学生的信息,返回.......!");
getch();
system("cls");
return ;
}
else
{
printf("查询完毕,按任意键返回!");
getch();
system("cls");
return ;
}
}
else if(tempID==2) //按学号查询
{
printf("请输入该学生的学号: ");
scanf("%d",&stuID);
for(i=0;i<count;i++)
if(stuID==p_student[i].ID)
{
sum=0;
for(j=0;j<3;j++)
sum+=p_student[i].sorc[j]; //计算总分
aver=sum/3.0; //计算平均分
printf("学号为%d的学生成绩表\n",stuID);
printf("——————————————————————————\n");
printf("\n学号: %d\n",p_student[i].ID);
printf("\n姓名: %s\n",p_student[i].name);
printf("\n班级: %s\n",p_student[i].clas);
printf("\n语文: %.2f\n",p_student[i].sorc[0]);
printf("\n数学: %.2f\n",p_student[i].sorc[1]);
printf("\n英语: %.2f\n",p_student[i].sorc[2]);
printf("\n总分: %.2f\n",sum);
printf("\n平均分: %.2f\n",aver);
printf("——————————————————————————\n");
n++;
}
if(n==0)
{
printf("找不到该学生的信息,返回.......!");
getch();
system("cls");
return ;
}
else
{
printf("查询完毕,按任意键返回!");
getch();
system("cls");
return ;
}
}
else
{
printf("没有此选择,返回.......!");
getch();
system("cls");
return ;
}
}
////////////////////////查询班级信息///////////////////////////////////////////
void seasorc2(struct studentsorc *p_student)
{
int i,j,count,max,n=0;
float sum,s1,s2,s3,aver,summax,avermax;
char tempclass[CLAS];
s1=s2=s3=summax=0;
count=sorcdatfile(p_student);
if(!count)
{
printf("读取数据失败,请确认数据是否存在或文件是否损害");
getch();
system("cls");
return ;
}
printf("请输入班级: ");
getchar();
gets(tempclass);
for(i=0;i<count;i++)
if(strcmp(tempclass,p_student[i].clas)==0)
{
sum=0;
for(j=0;j<3;j++)
sum+=p_student[i].sorc[j]; //计算总分
aver=sum/3.0; //计算平均分
if(sum>summax)
{
max=i;
summax=sum;
avermax=aver;
}
printf("——————————————————————————\n");
printf("\n学号: %d\n",p_student[i].ID);
printf("\n姓名: %s\n",p_student[i].name);
printf("\n班级: %s\n",p_student[i].clas);
printf("\n语文: %.2f\n",p_student[i].sorc[0]);
printf("\n数学: %.2f\n",p_student[i].sorc[1]);
printf("\n英语: %.2f\n",p_student[i].sorc[2]);
printf("\n总分: %.2f\n",sum);
printf("\n平均分: %.2f\n",aver);
printf("——————————————————————————\n");
n++;
s1+=p_student[i].sorc[0];
s2+=p_student[i].sorc[1];
s3+=p_student[i].sorc[2];
}
if(n==0)
{
printf("找不到该班级,返回.......!");
getch();
system("cls");
return ;
}
else
{
printf("该班语文平均分为:%.2f\n",s1/n);
printf("该班数学平均分为:%.2f\n",s2/n);
printf("该班英语平均分为:%.2f\n",s3/n);
printf("——————————————————————————\n");
printf("该班总分最高的学生为:\n");
printf("\n学号: %d\n",p_student[max].ID);
printf("\n姓名: %s\n",p_student[max].name);
printf("\n班级: %s\n",p_student[max].clas);
printf("\n语文: %.2f\n",p_student[max].sorc[0]);
printf("\n数学: %.2f\n",p_student[max].sorc[1]);
printf("\n英语: %.2f\n",p_student[max].sorc[2]);
printf("\n总分: %.2f\n",summax);
printf("\n平均分: %.2f\n",avermax);
printf("查询完毕,按任意键返回!");
getch();
system("cls");
return ;
}
}
/******************************浏览所有学生的信息*********************************/
void allabout(struct studentsorc *p_student)
{
FILE *sorcfile1;
FILE *sorcfile2;
int i,j,k,count,in;
float s1,s2,s3,s[STUDENTMAX]={0},t,sum,aver;
struct studentsorc temp;
s1=s2=s3=0;
count=sorcdatfile(p_student);
if(!count)
{
printf("读取数据失败,请确认数据是否存在或文件是否损害");
getch();
system("cls");
return ;
}
printf("请选择你操作的选项: 1. 按学号由小到大输出 2.按总分由高到低输出");
scanf("%d",&in);
if(in==1)
{
if((sorcfile1=fopen(filename1,"wb"))==NULL)
{
printf("不能找开文件,请确认磁盘已满或文件是否存在!");
getch();
return ;
}
for(i=0;i<count;i++)
{
k=i;
for(j=i+1;j<count;j++)
if(p_student[j].ID<p_student[k].ID)
k=j;
temp=p_student[i];
p_student[i]=p_student[k];
p_student[k]=temp;
}
printf("\n\t\t\t学生成绩表\n");
for(i=0;i<count;i++)
{
sum=0; //重新初始化,计算下一次
for(j=0;j<3;j++)
sum+=p_student[i].sorc[j]; //计算总分
aver=sum/3.0; //计算平均分
s1+=p_student[i].sorc[0];
s2+=p_student[i].sorc[1];
s3+=p_student[i].sorc[2];
fwrite(&p_student[i],sizeof(struct studentsorc),1,sorcfile1);//写入文件
printf("——————————————————————————————————\n");
printf("学号: %d\n",p_student[i].ID);
printf("姓名: %s\n",p_student[i].name);
printf("班级: %s\n",p_student[i].clas);
printf("语文成绩: %.2f\n",p_student[i].sorc[0]);
printf("数学成绩: %.2f\n",p_student[i].sorc[1]);
printf("英语成绩: %.2f\n",p_student[i].sorc[2]);
printf("总分成绩: %.2f\n",sum);
printf("平均分成绩: %.2f\n",aver);
printf("————————————————————————————————\n");
printf("请按任意键继续浏览.......!");
getch();
}
printf("————————————————————————————————\n");
printf("语文平均分为:%.2f\n",s1/count);
printf("数学平均分为:%.2f\n",s2/count);
printf("英语平均分为:%.2f\n",s3/count);
printf("浏览完毕,请返回.......!");
fclose(sorcfile1);
getch();
system("cls");
return ;
}
else if(in==2)
{
if((sorcfile2=fopen(filename2,"wb"))==NULL)
{
printf("不能找开文件,请确认磁盘已满或文件是否存在!");
getch();
return ;
}
for(i=0;i<count;i++)
for(j=0;j<3;j++)
s[i]+=p_student[i].sorc[j]; //计算总分
for(i=0;i<count;i++)
{
k=i;
for(j=i+1;j<count;j++)
if(s[j]>s[k])
k=j;
t=s[i];s[i]=s[k];s[k]=t;
temp=p_student[i];
p_student[i]=p_student[k];
p_student[k]=temp;
}
for(i=0;i<count;i++)
{
sum=0; //重新初始化,计算下一次
for(j=0;j<3;j++)
sum+=p_student[i].sorc[j]; //计算总分
aver=sum/3.0; //计算平均分
s1+=p_student[i].sorc[0];
s2+=p_student[i].sorc[1];
s3+=p_student[i].sorc[2];
fwrite(&p_student[i],sizeof(struct studentsorc),1,sorcfile2);//写入文件
printf("——————————————————————————————————\n");
printf("学号: %d\n",p_student[i].ID);
printf("姓名: %s\n",p_student[i].name);
printf("班级: %s\n",p_student[i].clas);
printf("语文成绩: %.2f\n",p_student[i].sorc[0]);
printf("数学成绩: %.2f\n",p_student[i].sorc[1]);
printf("英语成绩: %.2f\n",p_student[i].sorc[2]);
printf("总分成绩: %.2f\n",sum);
printf("平均分成绩: %.2f\n",aver);
printf("————————————————————————————————\n");
printf("请按任意键继续浏览.......!");
getch();
}
printf("————————————————————————————————\n");
printf("语文平均分为:%.2f\n",s1/count);
printf("数学平均分为:%.2f\n",s2/count);
printf("英语平均分为:%.2f\n",s3/count);
printf("浏览完毕,请返回.......!");
fclose(sorcfile2);
getch();
system("cls");
return ;
}
else
{
printf("输入有误,返回...!");
getch();
system("cls");
return ;
}
}
/**********************成绩数据文件***************************/
int sorcdatfile(struct studentsorc *p_student)
{
int count=0;
system("cls");
if((sorcfile=fopen(filename,"rb"))==NULL)
{
printf("不能找开文件,请确认磁盘已满或文件是否存在!");
getch();
return 0;
}
rewind(sorcfile); //指向文件头读取数据
while(!feof(sorcfile))
{
fread(&p_student[count],sizeof(struct studentsorc),1,sorcfile);
count++;
}
fclose(sorcfile);
return count-1; //返回读到的结构块数
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -