急求学生成绩管理系统C++课程设计源代码

2025-04-05 13:08:03
推荐回答(1个)
回答1:

#include
#include
struct student
{
int num;
char name[20];
char sex;
float score[2];
}stu[100];
struct student1
{
int num;
char name[20];
char sex;
float score[2];
struct student1 *next;
};
int main()
{

void browse();
void input();
void search();
void tongji();
void del();
int flag=1,n;
while(flag)
{
printf("1----------学生录入\n");
printf("2----------学生浏览\n");
printf("3----------学生查询\n");
printf("4----------学生删除\n");
printf("5----------成绩统计\n");
printf("0----------退出系统\n");

printf("请选择(0----5)\n");
scanf("%d",&n);

switch(n)
{
case 1:input();break;
case 2:browse();break;
case 3:search();break;
case 4:del();break;
case 5:tongji();break;
case 0:flag=0;break;
}
}
return 0;
}
void input()
{
FILE *fp;
char filename[10];
char c,b;
int k;
printf("录入系统\n");
int flag1=1,i=0;
printf("请输入学生学号,姓名,性别,英语成绩,c语言成绩\n");
while(flag1)
{
scanf("%d %s %c %f %f",&stu[i].num,stu[i].name,&stu[i].sex,&stu[i].score[0],&stu[i].score[1]);
i++;
scanf("%c",&b);
printf("continue?Y/N");
scanf("%c",&c);
if(c=='n'||c=='N')
flag1=0;
if(c=='y'||c=='Y')
flag1=1;
}
printf("请输入文件名\n");
scanf("%s",filename);
fp=fopen(filename,"ab+");
if(fp==NULL)
exit(0);
else
{
for(k=0;k fwrite(&stu[k],sizeof(struct student),1,fp);
fclose(fp) ;
}
}

void browse()
{
FILE *fp;
char filename[10];
printf("请输入文件名");
scanf("%s",filename);
fp=fopen(filename,"rb");
struct student s1,temp[100];
int i=0;
while(fread(&s1,sizeof(struct student),1,fp)==1)
temp[i++]=s1;
int k;
for(k=0;k printf("学号%d 姓名%s 性别%c 英语成绩%f c语言成绩%f\n",temp[k].num,temp[k].name,temp[k].sex,temp[k].score[0],temp[k].score[1]);
fclose(fp);
}
void search()
{
printf("学生成绩查询\n");
int k,number;
FILE *fp;
char filename[10];
printf("请输入文件名:");
scanf("%s",filename);
printf("请输入查询学生学号:\n");
scanf("%d",&number);
fp=fopen(filename,"rb");
struct student s1,temp[100];
int i=0;
while(fread(&s1,sizeof(struct student),1,fp)==1)
temp[i++]=s1;
for(k=0;k if(temp[k].num==number)
printf("学号%d 姓名%s 性别%c 英语成绩%f c语言成绩%f\n",temp[k].num,temp[k].name,temp[k].sex,temp[k].score[0],temp[k].score[1]);
fclose(fp);
}
void del()
{
FILE *fp;
int number;
char filename[10];
printf("请输入文件名");
scanf("%s",filename);
printf("请输入删除学生学号:\n");
scanf("%d",&number);
fp=fopen(filename,"rb");
if(fp==NULL)
{
printf("该文件不存在");
exit(0);
}
struct student1 *head,*p,*q;
p=(struct student1 *)malloc(sizeof(struct student1));
head=(struct student1 *)malloc(sizeof(struct student1));
q=head;
// head=NULL;
while(fread(p,sizeof(struct student),1,fp)==1)
{
q->next=p;
q=p;
p=(struct student1 *)malloc(sizeof(struct student1));

}
q->next=NULL;
q=head;
p=q->next;
// p=NULL;

while(p!=NULL)
{
if(p->num==number)
{
q->next=p->next;
free(p);break;
}
else
{
q=p;
p=p->next;
}

}
fclose(fp);
printf("请输入文件名:\n");

scanf("%s",filename);
fp=fopen(filename,"wb");
if(fp==NULL)
exit(0);
else
{
p=head->next;
while(p!=NULL)
{
fwrite(p,sizeof(struct student),1,fp);
p=p->next;
}
fclose(fp);
}
}

void tongji()
{
FILE *fp;
char filename[10];
int n,i=0;
printf("请输入文件名:");
scanf("%s",filename);
fp=fopen(filename,"rb");
struct student s1,temp[100];
while(fread(&s1,sizeof(struct student),1,fp)==1)
temp[i++]=s1;
int k;
for(n=0;n<=100;n++)
for(k=0;k {
if(temp[k].score[1]==n)
printf("学号%d 姓名%s 性别%c 英语成绩%f c语言成绩%f\n",temp[k].num,temp[k].name,temp[k].sex,temp[k].score[0],temp[k].score[1]);
}
}
撸主参考下!!好的话要给我分哦