我X
这个问题很多人跟啊
我贴代码给你参考
或许对你的课程设计有帮助
#include <stdio.h>
struct stud
{long num;
char name[20];
float math;
float eng;
float computer;
float total;
};
struct chuli
{long num;
char name[20];
float math;
float eng;
float computer;
float total;
struct chuli *next;
};
/*-------------------------------------------------------*/
main()
{char choise,cho;
char file[50];
int searc;
FILE *fp;
long numb;
struct stud student;
struct stud *s;
int cas;
sys: shuaping(24);
printf("/n *** 成绩管理系统 ***"
;
printf("/n"
;
printf("/n 1. 成绩输入"
;
printf("/n 2. 成绩修改"
;
printf("/n 3. 成绩查询"
;
printf("/n 4. 成绩统计"
;
printf("/n 5. 成绩打印"
;
printf("/n 6. 成绩删除"
;
printf("/n 7. 系统说明"
;
printf("/n 0. 退出系统"
;
shuaping(6);
printf(" 输入数字选择: "
;
choise='$';
while(choise!='0'&&choise!='1'&&choise!='2'&&choise!='3'&&choise!='4'&&choise!='5'&&choise!='6'&&choise!='7')
scanf("%s",&choise);
if(choise=='1') goto sys1;
else if(choise=='2') goto sys2;
else if(choise=='3') goto sys3;
else if(choise=='4') goto sys4;
else if(choise=='5') goto sys5;
else if(choise=='6') goto sys6;
else if(choise=='7') goto sys7;
else if(choise=='0') goto end;
sys1: shuaping(24);
printf(" * 成绩输入 *"
;
shuaping(12);
input();
goto sys;
sys2: shuaping(24);
printf(" * 成绩修改 *"
;
shuaping(12);
input1: printf("/n请输入要修改成绩的位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"rb+"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') goto sys;
}
shuaping(24);
printf("* 成绩修改 *"
;
shuaping(12);
printf("请输入学号: "
;
scanf("%ld",&numb);
s=&student;
cas=0;
while(!feof(fp))
{fread(s,sizeof(struct stud),1,fp);
if(student.num==numb){cas++; fclose(fp);change(file,numb); break;}
}
if (cas==0)
{printf("/n没有找到对应成绩"
;
printf("/n是否继续 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') goto sys;
}
goto sys;
sys3: shuaping(24);
printf(" * 成绩查询 *"
;
shuaping(12);
searc=search();
if(searc<0) goto sys;
else goto sys3;
sys4: shuaping(24);
printf(" * 成绩统计 *"
;
printf("/n/n 1. 统计总分"
;
printf("/n 2. 统计不及格人数"
;
printf("/n 3. 统计分数段人数及比例"
;
printf("/n 0. 退出"
;
shuaping(8);
printf(" 输入数字选择: "
;
choise='$';
while(choise!='1'&&choise!='2'&&choise!='3'&&choise!='0')
scanf("%c",&choise);
if(choise=='1') tjzongfen();
else if(choise=='2') tjbujige();
else if(choise=='3') fdtj();
else if(choise=='0') goto sys;
goto sys4;
sys5: shuaping(24);
printf(" * 成绩输出 *"
;
printf("/n/n 1. 输出排序成绩"
;
printf("/n 2. 成绩合并排序输出"
;
printf("/n 0. 退出"
;
shuaping(9);
printf(" 输入数字选择: "
;
choise='$';
while(choise!='1'&&choise!='2'&&choise!='0')
scanf("%c",&choise);
if(choise=='1') bjpx();
else if(choise=='2') cjhb();
else if(choise=='0') goto sys;
goto sys5;
sys6: shuaping(24);
printf(" * 成绩删除 *"
;
shuaping(12);
searc=det();
if(searc<0) goto sys;
else goto sys6;
sys7: shuoming();
printf("/n是否反回系统 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n')
scanf("%c",&cho);
if (cho=='y') goto sys;
if(cho=='n') goto end;
end: shuaping(24);
printf ("%c",7);
printf (" MM MM/n"
;
printf (" MMM MMM/n"
;
printf (" MMMM MMMM/n"
;
printf (" MMMMMMMMM/n"
;
printf (" MM MMM MM/n"
;
printf (" MM M MM/n"
;
printf (" MM MM/n"
;
printf(" MMMM MMMM"
;
printf(" (c)Copyright iamy 2002.6%c",7);
shuaping(4);
}
/*-------------------------------------------------------*/
shuaping (int src)
{int x;
for (x=0;x<=src;x++) printf("/n"
;
}
/*-------------------------------------------------------*/
input()
{
struct stud student;
struct stud *s;
struct stud *pd;
struct stud panduanc;
int pdan;
FILE *fp;
char file[50];
char cho;
s=&student;
pd=&panduanc;
input1: printf("请输入要保存成绩的位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"ab+"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(0);
}
input2: shuaping(24);
while (1)
{printf("/n输入成绩 (学号<0结束) : "
;
printf("/n学号: "
; scanf("%ld",&student.num);
if(student.num<0) {fclose(fp);return(0);}
pdan=-1;
rewind(fp);
while(!feof(fp))
{fread(pd,sizeof(struct stud),1,fp);
if (pd->num==s->num)
{shuaping(24);
printf("%c * 成绩已存在! *",7);
shuaping(4);
printf("/n/n 学号: %ld",panduanc.num);
printf("/n 姓名: %s",panduanc.name);
printf("/n 数学成绩: %6.2f",panduanc.math);
printf("/n 英语成绩: %6.2f",panduanc.eng);
printf("/n 计算机成绩: %6.2f",panduanc.computer);
printf("/n 总成绩: %6.2f",panduanc.total);
shuaping(2);
pdan=panduan();
if (pdan!=-1) {fclose(fp);fp=fopen(file,"ab+"
;break;}
}
}
if (pdan==0) goto input2;
if (pdan==1) {fclose(fp);change(file,s->num);fp=fopen(file,"ab+"
;goto input2;}
printf("/n姓名: "
; scanf("%s",student.name);
printf("/n数学成绩: "
; scanf("%f",&student.math);
printf("/n英语成绩: "
; scanf("%f",&student.eng);
printf("/n计算机成绩: "
; scanf("%f",&student.computer);
student.total=student.math+student.eng+student.computer;
fwrite(s,sizeof(struct stud),1,fp);
}
fclose(fp);
}
/*-------------------------------------------------------*/
int panduan()
{char y;
printf("是否修改? (y/n)"
;
y='$';
while(y!='y'&&y!='n')
scanf("%c",&y);
if (y=='y') return(1);
if (y=='n') return(0);
return(-1);
}
/*-------------------------------------------------------*/
search()
{struct stud student;
struct stud *s;
FILE *fp;
int cas;
char file[50];
char cho;
long numb;
s=&student;
input1: printf("请输入要查询成绩的位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"rb"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(-1);
}
input2: shuaping(24);
printf("* 成绩查询 *"
;
shuaping(12);
printf("请输入学号(学号<0结束): "
;
scanf("%ld",&numb);
if(numb<0) return(-1);
cas=0;
fclose(fp);
fp=fopen(file,"rb"
;
while(!feof(fp))
{fread(s,sizeof(struct stud),1,fp);
if(student.num==numb)
{printf("/n学号: %ld",student.num);
printf("/n姓名: %s",student.name);
printf("/n数学成绩: %6.2f",student.math);
printf("/n英语成绩: %6.2f",student.eng);
printf("/n计算机成绩: %6.2f",student.computer);
printf("/n总成绩: %6.2f",student.total);
cas++;
break;
}
}
if (cas>0)
{printf("/n/n是否对成绩进行修改 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
{fclose(fp);change(file,numb);fopen(file,"rb"
;}
else if(cho=='n') goto input2;
}
else {printf("/n没有找到对应成绩"
;
printf("/n是否继续 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(-1);
}
goto input2;
}
/*-------------------------------------------------------*/
change(char file[50],long numb)
{FILE *fp;
struct chuli *p,*fre;
struct chuli *head;
p=(struct chuli *)malloc(sizeof(struct chuli));
head=p;
fp=fopen(file,"rb"
;
shuaping(24);
printf(" * 成绩修改 *"
;
shuaping(2);
while(1)
{fread(p,sizeof(struct stud),1,fp);
if(feof(fp)) {p->next=NULL;break;}
p->next=(struct chuli *)malloc(sizeof(struct chuli));
p=p->next;
}
fclose(fp);
p=head;
while(p->next!=NULL)
{if (p->num==numb)
{printf("/n/n 学号: %ld",p->num);
printf("/n 姓名: %s",p->name);
printf("/n 数学成绩: %6.2f",p->math);
printf("/n 英语成绩: %6.2f",p->eng);
printf("/n 计算机成绩: %6.2f",p->computer);
printf("/n 总成绩: %6.2f",p->total);
shuaping(2);
printf("------输入新成绩------/n/n"
;
printf("/n姓名: "
; scanf("%s",p->name);
printf("/n数学成绩: "
; scanf("%f",&p->math);
printf("/n英语成绩: "
; scanf("%f",&p->eng);
printf("/n计算机成绩: "
; scanf("%f",&p->computer);
p->total=p->math+p->eng+p->computer;
break;
}
p=p->next;
}
fp=fopen(file,"wb"
;
p=head;
while(p->next!=NULL)
{fwrite(p,sizeof(struct stud),1,fp);
p=p->next;
}
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
fclose(fp);
}
/*-------------------------------------------------------*/
tjzongfen()
{FILE *fp;
char file[50];
char cho;
struct chuli *head;
struct chuli *p;
struct chuli *fre;
int n;
double stotal=0,seng=0,smath=0,scomputer=0;
input1: shuaping(24);
printf(" * 统计总分 *"
;
shuaping(12);
printf("请输要进行统计的文件位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"rb"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(0);
}
n=0;
shuaping(24);
printf("成绩处理中 ..."
;
head=(struct chuli *)malloc(sizeof(struct chuli));
p=head;
while(1)
{fread(p,sizeof(struct stud),1,fp);
if(feof(fp)) {p->next=NULL;break;}
p->next=(struct chuli *)malloc(sizeof(struct chuli));
p=p->next;
}
fclose(fp);
p=head;
while(p->next!=NULL)
{stotal=p->total+stotal;
seng=p->eng+seng;
smath=p->math+smath;
scomputer=p->computer+scomputer;
n++;
if (p->next==NULL) break;
p=p->next;
}
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
shuaping(24);
printf(" * 统计总分结果 *"
;
shuaping(2);
if (n==0) {printf(" * 空文件! *"
;goto input2;}
printf("人数: %d 总分 总平均分",n);
printf("/n/n数学 %6.2f %6.2f",smath,smath/n);
printf("/n英语 %6.2f %6.2f",seng,seng/n);
printf("/n计算机 %6.2f %6.2f",scomputer,scomputer/n);
printf("/n总分 %6.2f %6.2f",stotal,stotal/n);
smath=seng=scomputer=stotal=0;
input2: shuaping(3);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n')
{
return(0);
}
}
/*-------------------------------------------------------*/
tjbujige()
{FILE *fp;
char file[50];
char cho;
struct chuli *head;
struct chuli *p,*fre;
int e,m,c,n;
float e1,m1,c1;
input1: shuaping(24);
printf(" * 统计不及格 *"
;
shuaping(12);
printf("请输要进行统计的文件位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"rb"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(0);
}
shuaping(24);
printf("成绩处理中 ..."
;
p=(struct chuli *)malloc(sizeof(struct chuli));
head=p;
while(1)
{fread(p,sizeof(struct stud),1,fp);
if(feof(fp)) {p->next=NULL;break;}
p->next=(struct chuli *)malloc(sizeof(struct chuli));
p=p->next;
}
fclose(fp);
p=head;
m=c=e=0;
n=0;
while(p->next!=NULL)
{if(p->eng<60) e++;
if(p->math<60) m++;
if(p->computer<60) c++;
n++;
if (p->next==NULL) break;
p=p->next;
}
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
shuaping(24);
printf(" * 统计结果 *"
;
shuaping(8);
if (n==0) {printf(" * 空文件! *"
;goto input2;}
e1=(float)e/n*100;
m1=(float)m/n*100;
c1=(float)c/n*100;
printf("人数: %d 不及格人数 不及格率",n);
printf("/n/n数学 %d %.2f%",m,m1);
printf("/n英语 %d %.2f%",e,e1);
printf("/n计算机 %d %.2f%",c,c1);
input2: shuaping(3);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n')
{
return(0);
}
}
/*-------------------------------------------------------*/
fdtj()
{FILE *fp;
char file[50];
char cho;
struct stud *p;
int e,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9;
int m,m0,m1,m2,m3,m4,m5,m6,m7,m8,m9;
int c,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9;
int n,mi,ma;
input1: shuaping(24);
printf(" * 分段统计 *"
;
shuaping(12);
printf("请输如要进行统计的文件位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"rb"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(0);
}
e=e0=e1=e2=e3=e4=e5=e6=e7=e8=e9=0;
c=c0=c1=c2=c3=c4=c5=c6=c7=c8=c9=0;
m=m0=m1=m2=m3=m4=m5=m6=m7=m8=m9=0;
n=0;
shuaping(24);
printf("成绩处理中 ..."
;
p=(struct stud *)malloc(sizeof(struct stud));
while(1)
{fread(p,sizeof(struct stud),1,fp);
if (feof(fp)) break;
if(0<=p->eng&&p->eng<10) e0++;
else if(10<=p->eng&&p->eng<20) e1++;
else if(20<=p->eng&&p->eng<30) e2++;
else if(30<=p->eng&&p->eng<40) e3++;
else if(40<=p->eng&&p->eng<50) e4++;
else if(50<=p->eng&&p->eng<60) e5++;
else if(60<=p->eng&&p->eng<70) e6++;
else if(70<=p->eng&&p->eng<80) e7++;
else if(80<=p->eng&&p->eng<90) e8++;
else if(90<=p->eng&&p->eng<=100) e9++;
if(0<=p->math&&p->math<10) m0++;
else if(10<=p->math&&p->math<20) m1++;
else if(20<=p->math&&p->math<30) m2++;
else if(30<=p->math&&p->math<40) m3++;
else if(40<=p->math&&p->math<50) m4++;
else if(50<=p->math&&p->math<60) m5++;
else if(60<=p->math&&p->math<70) m6++;
else if(70<=p->math&&p->math<80) m7++;
else if(80<=p->math&&p->math<90) m8++;
else if(90<=p->math&&p->math<=100) m9++;
if(0<=p->computer&&p->computer<10) c0++;
else if(10<=p->computer&&p->computer<20) c1++;
else if(20<=p->computer&&p->computer<30) c2++;
else if(30<=p->computer&&p->computer<40) c3++;
else if(40<=p->computer&&p->computer<50) c4++;
else if(50<=p->computer&&p->computer<60) c5++;
else if(60<=p->computer&&p->computer<70) c6++;
else if(70<=p->computer&&p->computer<80) c7++;
else if(80<=p->computer&&p->computer<90) c8++;
else if(90<=p->computer&&p->computer<=100) c9++;
n++;
}
fclose(fp);
shuaping(24);
printf(" * 分段统计结果 *"
;
shuaping(0);
if (n==0) {shuaping(8);printf(" * 空文件! *"
;goto input2;}
printf("/n( 该分数段人数 - 该分数段人数在总人数中的比例/"%/" )"
;
shuaping(1);
printf(" 人数: %-5d 数学 英语 计算机",n);
printf("/n/n 90-100 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m9,(float)m9/n*100,e9,(float)e9/n*100,c9,(float)c9/n*100);
printf("/n 80-90 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m8,(float)m8/n*100,e8,(float)e8/n*100,c8,(float)c8/n*100);
printf("/n 70-80 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m7,(float)m7/n*100,e7,(float)e7/n*100,c7,(float)c7/n*100);
printf("/n 60-70 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m6,(float)m6/n*100,e6,(float)e6/n*100,c6,(float)c6/n*100);
printf("/n 50-60 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m5,(float)m5/n*100,e5,(float)e5/n*100,c5,(float)c5/n*100);
printf("/n 40-50 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m4,(float)m4/n*100,e4,(float)e4/n*100,c4,(float)c4/n*100);
printf("/n 30-40 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m3,(float)m3/n*100,e3,(float)e3/n*100,c3,(float)c3/n*100);
printf("/n 20-30 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m2,(float)m2/n*100,e2,(float)e2/n*100,c2,(float)c2/n*100);
printf("/n 10-20 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m1,(float)m1/n*100,e1,(float)e1/n*100,c1,(float)c1/n*100);
printf("/n 0-10 %5d - %6.2f %5d - %6.2f %5d - %6.2f",m0,(float)m0/n*100,e0,(float)e0/n*100,c0,(float)c0/n*100);
shuaping(1);
printf("请输入分数下限: "
;
scanf("%d",&mi);
printf("请输入分数上限: "
;
scanf("%d",&ma);
fp=fopen(file,"rb"
;
while(1)
{fread(p,sizeof(struct stud),1,fp);
if (feof(fp)) break;
if (mi<=p->eng&&p->eng<ma) e++;
if (mi<=p->math&&p->math<ma) m++;
if (mi<=p->computer&&p->computer<ma) c++;
}
printf("/n 人数: %-5d 数学 英语 计算机",n);
printf("/n/n% 3d-%-3d %5d - %6.2f %5d - %6.2f %5d - %6.2f",mi,ma,m,(float)m/n*100,e,(float)e/n*100,c,(float)c/n*100);
input2: shuaping(1);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n')
{scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n')
return(0);
}
/*-------------------------------------------------------*/
bjpx()
{FILE *fp;
FILE *f;
char fil[50];
struct chuli *head;
struct chuli *p,*fre;
char file[50];
char cho,choise;
int n,i;
int hang,page,mc;
long numt;
int scort;
char namet[20];
input1: shuaping(24);
printf(" * 成绩打印 *"
;
shuaping(12);
printf("请输如要进行打印成绩的位置: "
;
scanf("%s",file);
if ((fp=fopen(file,"rb"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
goto input1;
else if(cho=='n') return(0);
}
p=(struct chuli *)malloc(sizeof(struct chuli));
head=p;
n=0;
shuaping(24);
printf("成绩处理中 ..."
;
while(!feof(fp))
{fread(p,sizeof(struct stud),1,fp);
n++;
if (feof(fp)) {p->next=NULL;break;}
p->next=(struct chuli *)malloc(sizeof(struct chuli));
p=p->next;
}
fclose(fp);
for (i=1;i<n;i++)
{p=head;
while(p->next!=NULL)
{if(p->total<p->next->total)
{numt=p->num;p->num=p->next->num;p->next->num=numt;
strcpy(namet,p->name);strcpy(p->name,p->next->name);strcpy(p->next->name,namet);
scort=p->math;p->math=p->next->math;p->next->math=scort;
scort=p->eng;p->eng=p->next->eng;p->next->eng=scort;
scort=p->computer;p->computer=p->next->computer;p->next->computer=scort;
scort=p->total;p->total=p->next->total;p->next->total=scort;
}
p=p->next;
}
}
p=head;
hang=page=mc=1;
shuaping(24);
printf("/ ----------------- 第 %d 页 -----------------",page);
printf("/n名次 学号 姓名 数学 英语 计算机 总分/n"
;
while(1)
{
if(hang==21)
{printf("/n 是否下页 (y/n) "
;
cho='$';
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
{hang=0;page++;printf("/n ----------------- 第 %d 页 -----------------",page);printf("/n名次 学号 姓名 数学 英语 计算机 总分/n"
;}
else if(cho=='n')
{printf("/n是否将排序后成绩保存 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y') goto inputs;
if (cho=='n')
{p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);
}
}
}
printf("/n %-5d %-11ld%-12s%5.1f %5.1f %5.1f %5.1f",mc,p->num,p->name,p->math,p->eng,p->computer,p->total);
mc++;
hang++;
p=p->next;
if(p->next==NULL) break;
}
printf("/n * 输出完毕 *"
;
printf("/n是否将排序后成绩保存 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
{inputs: printf("/n请输入要保存成绩的位置: "
;
scanf("%s",fil);
if ((fp=fopen(fil,"rb"
)!=NULL)
{printf("/n%c * 文件已存在 *",7);
printf("/n/n是否替换 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y') goto save;
if (cho=='n')
{printf("/n/n是否继续 (y/n) "
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y') {fclose(fp);goto inputs;}
if (cho=='n')
{fclose(fp);
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);
}
}
}
save: ;
fclose(fp);
if ((fp=fopen(fil,"wb"
)==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
;
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
goto inputs;
else if(cho=='n')
{p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);
}
}
p=head;
while(p->next!=NULL)
{fwrite(p,sizeof(struct stud),1,fp);
p=p->next;
}
fclose(fp);
}
if(cho=='n')
{p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);
}
}
/*-------------------------------------------------------*/
cjhb()
{ FILE *fp,*f;
struct chuli *p,*head,*fre;
char cho,no;
int n,i,m;
char filn[30][50];
char file[50];
char fil[50];
char choise;
int hang,page,mc;
long numt;
int scort;
char namet[20];
shuaping(24);
printf("/ * 成绩合并 *"
;
shuaping(3);
printf("请输入要合并的文件个数 (少于9个): "
;
no='$';
scan: scanf("%c",&no);
if (no!='1'&&no!='2'&&no!='3'&&no!='4'&&no!='5'&&no!='6'&&no!='7'&&no!='8'&&no!='9')
{printf("%c",7);goto scan;}
if (no=='1') m=1;
else if(no=='2') m=2;
else if(no=='3') m=3;
else if(no=='4') m=4;
else if(no=='5') m=5;
else if(no=='6') m=6;
else if(no=='7') m=7;
else if(no=='8') m=8;
else if(no=='9') m=9;
for(i=1;i<=m;i++)
{rinput: printf("/n请输入第 %d 个文件的名称: ",i);
scanf("%s",filn
);
if((f=fopen(filn,"rb")==NULL)
{printf("%c * 文件打开错误! */n",7);
printf("/n是否继续 (y/n) "
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
{fclose(f);goto rinput;}
else if(cho=='n') {fclose(f);return(0);}
}
fclose(f);
}
shuaping(24);
printf("成绩处理中 ..."
p=(struct chuli *)malloc(sizeof(struct chuli));
head=p;
n=0;
for(i=1;i<=m;i++)
{fp=fopen(filn,"rb"
while(1)
{fread(p,sizeof(struct stud),1,fp);
if (feof(fp)) goto end;
n++;
p->next=(struct chuli *)malloc(sizeof(struct chuli));
p=p->next;
}
end: fclose(fp);
}
p->next=NULL;
for (i=1;i<n;i++)
{p=head;
while(p->next!=NULL)
{if(p->total<p->next->total)
{numt=p->num;p->num=p->next->num;p->next->num=numt;
strcpy(namet,p->name);strcpy(p->name,p->next->name);strcpy(p->next->name,namet);
scort=p->math;p->math=p->next->math;p->next->math=scort;
scort=p->eng;p->eng=p->next->eng;p->next->eng=scort;
scort=p->computer;p->computer=p->next->computer;p->next->computer=scort;
scort=p->total;p->total=p->next->total;p->next->total=scort;
}
p=p->next;
}
}
p=head;
hang=page=mc=1;
shuaping(24);
printf("/ ----------------- 第 %d 页 -----------------",page);
printf("/n名次 学号 姓名 数学 英语 计算机 总分/n"
while(1)
{
if(hang==21)
{printf("/n 是否下页 (y/n) "
cho='$';
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
{hang=0;page++;printf("/n ----------------- 第 %d 页 -----------------",page);printf("/n名次 学号 姓名 数学 英语 计算机 总分/n"}
else if(cho=='n')
{printf("/n是否将排序后成绩保存 (y/n) "
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y') goto inputs;
if (cho=='n')
{p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);
}
}
}
printf("/n %-5d %-11ld%-12s%5.1f %5.1f %5.1f %5.1f",mc,p->num,p->name,p->math,p->eng,p->computer,p->total);
mc++;
hang++;
p=p->next;
if(p->next==NULL) break;
}
printf("/n * 输出完毕 *"
printf("/n是否将排序后成绩保存 (y/n) "
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
{
inputs: printf("/n请输入要保存成绩的位置: "
scanf("%s",fil);
if ((fp=fopen(fil,"rb")!=NULL)
{printf("/n%c * 文件已存在 *",7);
printf("/n/n是否替换 (y/n) "
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y') goto save;
if (cho=='n')
{printf("/n/n是否继续 (y/n) "
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y') {fclose(fp);goto inputs;}
if (cho=='n')
{
fclose(fp);
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);}
}
}
save: ;
fclose(fp);
if ((fp=fopen(fil,"wb")==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
cho='$';
while(cho!='y'&&cho!='n') {scanf("%c",&cho);}
if (cho=='y')
goto inputs;
else if(cho=='n')
{p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
return(0);
}
}
p=head;
while(p->next!=NULL)
{fwrite(p,sizeof(struct stud),1,fp);
p=p->next;
}
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
fclose(fp);
}
}
/*-------------------------------------------------------*/
det()
{struct stud student;
struct stud *s;
FILE *fp;
int cas;
char file[50];
char cho;
long numb;
s=&student;
input1: printf("请输入要删除成绩的位置: "
scanf("%s",file);
if ((fp=fopen(file,"rb")==NULL)
{shuaping(24);
printf("%c * 文件打开错误! *",7);
shuaping(12);
printf("是否继续 (y/n)"
cho='$';
while(cho!='y'&&cho!='n') scanf("%c",&cho);
if (cho=='y')
goto input1;
else if(cho=='n')
{
return(-1);
}
}
input2: shuaping(24);
printf("* 成绩删除 *"
shuaping(12);
printf("请输入学号(学号<0结束): "
scanf("%ld",&numb);
if(numb<0) return(-1);
cas=0;
while(!feof(fp))
{fread(s,sizeof(struct stud),1,fp);
if(student.num==numb)
{printf("/n学号: %ld",student.num);
printf("/n姓名: %s",student.name);
printf("/n数学成绩: %6.2f",student.math);
printf("/n英语成绩: %6.2f",student.eng);
printf("/n计算机成绩: %6.2f",student.computer);
printf("/n总成绩: %6.2f",student.total);
cas++;
break;
}
}
if (cas>0)
{printf("/n/n%c确定删除该成绩 (y/n) ",7);
cho='$';
while(cho!='y'&&cho!='n') scanf("%c",&cho);
if (cho=='y')
{fclose(fp);
dscort(file,numb);
fopen(file,"rb"
}
else if(cho=='n') goto input2;
}
else {printf("/n没有找到对应成绩"
printf("/n是否继续 (y/n) "
cho='$';
while(cho!='y'&&cho!='n')
scanf("%c",&cho);
if (cho=='y')
goto input1;
else if(cho=='n') return(-1);
}
goto input2;
}
/*-------------------------------------------------------*/
dscort (char file[50],long numb)
{FILE *fp;
struct chuli *p;
struct chuli *head,*t;
struct chuli *fre;
p=(struct chuli *)malloc(sizeof(struct chuli));
head=p;
fp=fopen(file,"rb"
while(1)
{fread(p,sizeof(struct stud),1,fp);
if(feof(fp)) {p->next=NULL;break;}
p->next=(struct chuli *)malloc(sizeof(struct chuli));
p=p->next;
}
fclose(fp);
p=head;
while(p->next!=NULL)
{t=p->next;
if (t->num==numb)
{
p->next=t->next;
free(t);
break;
}
p=p->next;
}
fp=fopen(file,"wb"
p=head;
while(p->next!=NULL)
{fwrite(p,sizeof(struct stud),1,fp);
p=p->next;
}
fclose(fp);
p=head;
while(1)
{fre=p;
free(fre);
p=p->next;
if (p==NULL) break;
}
}
/*-------------------------------------------------------*/
shuoming()
{shuaping(24);
printf(" * 系统说明 *"
printf("/n============================================================================/n"
printf("/n 1. 文件管理: 使用本软件对文件进行管理时,可将本软件复制到包含被处理文件的"
printf("/n 路径下,这样在对文件处理时只需要输入文件名即可. 如果未将本软"
printf("/n 件复制到包含被处理文件的路径下,对文件进行处理时则应输入完整"
printf("/n 的文件路径."
printf("/n"
printf("/n 2. 成绩处理: 在对成绩的处理上,本软件不支持同一文件中的重复学号. 如果同一"
printf("/n 文件中存在重复学号现象,在对成绩进行处理时只对该学号的第一个"
printf("/n 成绩起作用."
printf("/n"
printf("/n 3. 文件保存: 考虑到软件运行的稳定性,最好在确定处理后的成绩无误后, 再对其"
printf("/n 进行保存. 对于数据,一定要做好备份工作."
printf("/n"
printf("/n 4. 编写说明: 为检验作者的C语言学习成果,同时为完成C语言课程设计,作者iamy于"
printf("/n 2002年6月, 将本软件编写完成于南通工学院.由于作者水平有限, 本"
printf("/n 软件尚存在一些不完善之处.DOS在95年的时候就离我们而去, 所以本"
printf("/n 软件在未编写的时候就过时了,但是希望它仍能发挥一定的作用.如果"
printf("/n 你没有支持汉语显示的UCDOS的话,从这里下载: "
printf("/n"
printf("/n http://www.m820126.y365.com/webforclass/download/ucdos.rar"
printf("/n/n============================================================================"
}
补充说明一点
里面有指针释放的BUG
我一直都没找到