发布网友 发布时间:2022-04-20 09:04
共4个回答
热心网友 时间:2023-07-04 02:24
我找的一个代码!试一下:
c语言学生成绩管理系统
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 学号 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};
typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;
void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}
void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:输入错误!\n");
}
void Nofind()
{
printf("\n=====>提示:没有找到该学生!\n");
}
void printc() /* 本函数用于输出中文 */
{
printf(" 学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\n");
}
void printe(Node *p)/* 本函数用于输出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}
Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位连表中符合要求的接点,并返回该指针 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按学号查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}
void Add(Link l) /* 增加学生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 将指针置于最末尾 */
while(1)
{
printf("请你输入学号(以'0'返回上一级菜单:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}
p=(Node *)malloc(sizeof(Node));
strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->data.name);
getchar();
printf("请你输入性别:");
scanf("%s",p->data.sex);
getchar();
printf("请你输入c语言成绩:");
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入数学成绩:");
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入英语成绩:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息输入已经完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;
}
}
void Qur(Link l) /* 查询学生 */
{
int sel;
char findmess[20];
Node *p;
if(!l->next)
{
printf("\n=====>提示:没有资料可以查询!\n");
return;
}
printf("\n=====>1按学号查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 学号 */
{
printf("请你输入要查找的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("请你输入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();
}
void Del(Link l) /* 删除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}
void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以修改!\n");
return;
}
printf("请你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("请你输入新学号(原来是%s):",p->data.num);
scanf("%s",p->data.num);
printf("请你输入新姓名(原来是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("请你输入新性别(原来是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
Nofind();
}
void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;
if(!p)
{
printf("\n=====>提示:没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}
void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:没有资料可以统计!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;
r=r->next;
}
printf("------------------------------统计结果--------------------------------\n");
printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);
printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}
void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;
ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表 */
ll->next=NULL;
if(l->next==NULL)
{
printf("\n=====>提示:没有资料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息 */
s->data=p->data;
s->next=NULL;
rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已经完成!\n");
}
void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打开文件时发生错误!\n");
exit(1);
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}
void main()
{
Link l;/* 连表 */
FILE *fp; /* 文件指针 */
int sel;
char ch;
char jian;
int count=0;
Node *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501 黄欢(32号)\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;
fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已经打开,正在导入记录......\n");
while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中 */
{
p->next=NULL;
r->next=p;
r=p; /* 将该接点挂入连中 */
count++;
}
}
fclose(fp); /* 关闭文件 */
printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);
while(1)
{
menu();
printf("请你选择操作:");
scanf("%d",&sel);
if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已经退出系统,再见!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加学生 */
case 2:Del(l);break;/* 删除学生 */
case 3:Qur(l);break;/* 查询学生 */
case 4:Modify(l);break;/* 修改学生 */
case 5:Save(l);break;/* 保存学生 */
case 9:printf("\t\t\t==========帮助信息==========\n");break;
default: Wrong();getchar();break;
}
}
}
/* */
/*
学生成绩管理程序
编制一个统计学生考试分数的管理程序。
设学生成绩已以一个学生一个记录的形式存储在文件中,
每位学生记录包含的信息有:姓名,学号和各门功课的成绩。
程序具有以下几项功能:求出各门课程的总分,平均分,按姓名,
按学号寻找其记录并显示,浏览全部学生成绩和按总分由高到低显示学生信息等。
*/
#include <stdio.h>
#define SWN 3 /* 课程数 */
#define NAMELEN 20 /* 姓名最大字符数 */
#define CODELEN 10 /* 学号最大字符数 */
#define FNAMELEN 80 /* 文件名最大字符数 */
#define BUFLEN 80 /* 缓冲区最大字符数 */
/* 课程名称表 */
char schoolwork[SWN][NAMELEN+1] = {"Chinese","Mathematic","English"};
struct record
{
char name[NAMELEN+1]; /* 姓名 */
char code[CODELEN+1]; /* 学号 */
int marks[SWN]; /* 各课程成绩 */
int total; /* 总分 */
}stu;
struct node
{
char name[NAMELEN+1]; /* 姓名 */
char code[CODELEN+1]; /* 学号 */
int marks[SWN]; /* 各课程成绩 */
int total; /* 总分 */
struct node *next; /* 后续表元指针 */
}*head; /* 链表首指针 */
int total[SWN]; /* 各课程总分 */
FILE *stfpt; /* 文件指针 */
char stuf[FNAMELEN]; /* 文件名 */
/* 从指定文件读入一个记录 */
int readrecord(FILE *fpt,struct record *rpt)
{
char buf[BUFLEN];
int i;
if(fscanf(fpt,"%s",buf)!=1)
return 0; /* 文件结束 */
strncpy(rpt->name,buf,NAMELEN);
fscanf(fpt,"%s",buf);
strncpy(rpt->code,buf,CODELEN);
for(i=0;i<SWN;i++)
fscanf(fpt,"%d",&rpt->marks[i]);
for(rpt->total=0,i=0;i<SWN;i++)
rpt->total+=rpt->marks[i];
return 1;
}
/* 对指定文件写入一个记录 */
writerecord(FILE *fpt,struct record *rpt)
{
int i;
fprintf(fpt,"%s\n",rpt->name);
fprintf(fpt,"%s\n",rpt->code);
for(i=0;i<SWN;i++)
fprintf(fpt,"%d\n",rpt->marks[i]);
return ;
}
/* 显示学生记录 */
displaystu(struct record *rpt)
{
int i;
printf("\nName : %s\n",rpt->name);
printf("Code : %s\n",rpt->code);
printf("Marks :\n");
for(i=0;i<SWN;i++)
printf(" %-15s : %4d\n",schoolwork[i],rpt->marks[i]);
printf("Total : %4d\n",rpt->total);
}
/* 计算各单科总分 */
int totalmark(char *fname)
{
FILE *fp;
struct record s;
int count,i;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
for(i=0;i<SWN;i++)
total[i]=0;
count=0;
while(readrecord(fp,&s)!=0)
{
for(i=0;i<SWN;i++)
total[i]+=s.marks[i];
count++;
}
fclose(fp);
return count; /* 返回记录数 */
}
/* 列表显示学生信息 */
void liststu(char *fname)
{
FILE *fp;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return ;
}
while(readrecord(fp,&s)!=0)
{
displaystu(&s);
printf("\n Press ENTER to continue...\n");
while(getchar()!='\n');
}
fclose(fp);
return;
}
/* 构造链表 */
struct node *makelist(char *fname)
{
FILE *fp;
struct record s;
struct node *p,*u,*v,*h;
int i;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return NULL;
}
h=NULL;
p=(struct node *)malloc(sizeof(struct node));
while(readrecord(fp,(struct record *)p)!=0)
{
v=h;
while(v&&p->total<=v->total)
{
u=v;
v=v->next;
}
if(v==h)
h=p;
else
u->next=p;
p->next=v;
p=(struct node *)malloc(sizeof(struct node));
}
free(p);
fclose(fp);
return h;
}
/* 顺序显示链表各表元 */
void displaylist(struct node *h)
{
while(h!=NULL)
{
displaystu((struct record *)h);
printf("\n Press ENTER to continue...\n");
while(getchar()!='\n');
h=h->next;
}
return;
}
/* 按学生姓名查找学生记录 */
int retrievebyn(char *fname, char *key)
{
FILE *fp;
int c;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
c=0;
while(readrecord(fp,&s)!=0)
{
if(strcmp(s.name,key)==0)
{
displaystu(&s);
c++;
}
}
fclose(fp);
if(c==0)
printf("The student %s is not in the file %s.\n",key,fname);
return 1;
}
/* 按学生学号查找学生记录 */
int retrievebyc(char *fname, char *key)
{
FILE *fp;
int c;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
c=0;
while(readrecord(fp,&s)!=0)
{
if(strcmp(s.code,key)==0)
{
displaystu(&s);
c++;
break;
}
}
fclose(fp);
if(c==0)
printf("The student %s is not in the file %s.\n",key,fname);
return 1;
}
main()
{
int i,j,n;
char c;
char buf[BUFLEN];
FILE *fp;
struct record s;
clrscr();
printf("Please input the students marks record file's name: ");
scanf("%s",stuf);
if((fp=fopen(stuf,"r"))==NULL)
{
printf("The file %s doesn't exit, do you want to creat it? (Y/N) ",stuf);
getchar();
c=getchar();
if(c=='Y'||c=='y')
{
fp=fopen(stuf,"w");
printf("Please input the record number you want to write to the file: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Input the student's name: ");
scanf("%s",&s.name);
printf("Input the student's code: ");
scanf("%s",&s.code);
for(j=0;j<SWN;j++)
{
printf("Input the %s mark: ",schoolwork[j]);
scanf("%d",&s.marks[j]);
}
writerecord(fp,&s);
}
fclose(fp);
}
}
fclose(fp);
getchar();
/*clrscr();*/
puts("Now you can input a command to manage the records.");
puts("m : mean of the marks.");
puts("t : total of the marks.");
puts("n : search record by student's name.");
puts("c : search record by student's code.");
puts("l : list all the records.");
puts("s : sort and list the records by the total.");
puts("q : quit!");
while(1)
{
puts("Please input command:");
scanf(" %c",&c); /* 输入选择命令 */
if(c=='q'||c=='Q')
{
puts("\n Thank you for your using.");
break; /* q,结束程序运行 */
}
switch(c)
{
case 'm': /* 计算平均分 */
case 'M':
if((n=totalmark(stuf))==0)
{
puts("Error!");
break;
}
printf("\n");
for(i=0;i<SWN;i++)
printf("%-15s's average is: %.2f.\n",schoolwork[i],(float)total[i]/n);
break;
case 't': /* 计算总分 */
case 'T':
if((n=totalmark(stuf))==0)
{
puts("Error!");
break;
}
printf("\n");
for(i=0;i<SWN;i++)
printf("%-15s's total mark is: %d.\n",schoolwork[i],total[i]);
break;
case 'n': /* 按学生的姓名寻找记录 */
case 'N':
printf("Please input the student's name you want to search: ");
scanf("%s",buf);
retrievebyn(stuf,buf);
break;
case 'c': /* 按学生的学号寻找记录 */
case 'C':
printf("Please input the student's code you want to search: ");
scanf("%s",buf);
retrievebyc(stuf,buf);
break;
case 'l': /* 列出所有学生记录 */
case 'L':
liststu(stuf);
break;
case 's': /* 按总分从高到低排列显示 */
case 'S':
if((head=makelist(stuf))!=NULL)
displaylist(head);
break;
default: break;
}
}
}
热心网友 时间:2023-07-04 02:25
[cpp] view plaincopyprint?
<span style="font-size:16px;">#include "stdio.h"
#include"string"
/*定义学生结构体*/
struct Student
{
char ID[20];
char Name[20];
float Mark1;
float Mark2;
float Mark3;
float Average;
};
/*声明学生数组及学生数量*/
struct Student students[1000];
int num=0;
/*求平均值*/
float Avg(struct Student stu)
{
return (stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通过学号返回数组下标*/
int Student_SearchByIndex(char id[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].ID,id)==0)
{
return i;
}
}
return -1;
}
/*通过姓名返回数组下标*/
int Student_SearchByName(char name[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].Name,name)==0)
{
return i;
}
}
return -1;
}
/*显示单条学生记录*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[index].ID,students[index].Name,
students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入学生信息*/
void Student_Insert()
{
while(1)
{
printf("请输入学号:");
scanf("%s",&students[num].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[num].Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark3);
getchar();
students[num].Average=Avg(students[num]);
num++;
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*修改学生信息*/
void Student_Modify()
{
//float mark1,mark2,mark3;
while(1)
{
char id[20];
int index;
printf("请输入要修改的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要修改的学生信息为:\n");
Student_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入学号:");
scanf("%s",&students[index].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[index].Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark3);
getchar();
students[index].Average=Avg(students[index]);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*删除学生信息*/
void Student_Delete()
{
int i;
while(1)
{
char id[20];
int index;
printf("请输入要删除的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要删除的学生信息为:\n");
Student_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
students[i]=students[i+1];//把后边的对象都向前移动
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按姓名查询*/
void Student_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的学生的姓名:");
scanf("%s",&name);
getchar();
index=Student_SearchByName(name);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要查询的学生信息为:\n");
Student_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按平均值排序*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;i<num;i++)
{
for (j=1;j<num-i;j++)
{
if (students[j-1].Average<students[j].Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/*显示学生信息*/
void Student_Display()
{
int i;
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*将学生信息从文件读出*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students[i],sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!\n");
}
for (i=0;i<num;i++)
{
if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1)
{
printf("写入文件错误!\n");
}
}
fclose(fp);
}
/*主程序*/
void main()
{
int choice;
IO_ReadInfo();
while(1)
{
/*主菜单*/
printf("\n------ 学生成绩管理系统------\n");
printf("1. 增加学生记录\n");
printf("2. 修改学生记录\n");
printf("3. 删除学生记录\n");
printf("4. 按姓名查询学生记录\n");
printf("5. 按平均成绩排序\n");
printf("6. 退出\n");
printf("请选择(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
Student_Insert();
break;
case 2:
Student_Modify();
break;
case 3:
Student_Delete();
break;
case 4:
Student_Select();
break;
case 5:
Student_SortByAverage();
Student_Display();
break;
case 6:
exit(0);
break;
}
IO_WriteInfo();
}
}
</span>
热心网友 时间:2023-07-04 02:25
太有才了
热心网友 时间:2023-07-04 02:26
粗略看了下,上面的差不多了。