用C语言编一个学生成绩管理系统。

要求:要能查成绩、删除成绩、修改成绩和增加学生记录。最好能截图!~ 谢谢了!~

以下是我做过的成品
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define N 100 //最大学生数量
#define LEN sizeof(struct student)
FILE *fp;
int n=0; //学生数量
struct student
{
int num;
char name[20];
int x_num;
int class_num;
float score1;
float score2;
float score3;
float total;
float average;
}stu[N]; //学生信息结构体

/*1.学生信息存入文件*/
void creat()
{
int i,j;
struct student t;
printf("输入学生的数量。(不超过%d)\n",N);
scanf("%d",&n);
if(n>N) exit(0);
printf("依次输入学生信息:学号 姓名 学院代号 班级号 高数成绩 英语成绩 C语言成绩\n");
for(i=0;i<n;i++)
{
scanf("%d %s %d %d %f %f %f",&stu[i].num,stu[i].name,&stu[i].x_num,&stu[i].class_num,&stu[i].score1,&stu[i].score2,&stu[i].score3);
stu[i].total=stu[i].score1+stu[i].score2+stu[i].score3;
stu[i].average=stu[i].total/3;
}
for(j=0;j<n-1;j++)
for(i=j;i<n-j-1;i++)
{
if(stu[i].num > stu[i+1].num)
{
t=stu[i];
stu[i]=stu[i+1];
stu[i+1]=t;
}
}
if((fp=fopen("student_number","wb"))==NULL) //保存学生数量n
{
printf("can't open file!\n");
exit(0);
}
fwrite(&n,sizeof(int),1,fp);
if((fp=fopen("student","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fwrite(&stu[i],LEN,1,fp);
fclose(fp);
}
/*2.增加一个学生信息*/
void add()
{
int i,j;
char ch;
struct student t;
if((fp=fopen("student_number","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fread(&n,sizeof(n),1,fp);
if((fp=fopen("student","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fread(&stu[i],LEN,1,fp);
printf("依次输入学生信息:学号 姓名 学院代号 班级号 高数成绩 英语成绩 C语言成绩\n");
scanf("%d %s %d %d %f %f %f",&t.num,t.name,&t.x_num,&t.class_num,&t.score1,&t.score2,&t.score3);
t.total=t.score1+t.score2+t.score3;
t.average=t.total/3;
if(t.num>stu[n-1].num)
{
n=n+1;
stu[n-1]=t;
}
else
for(i=0;i<n;i++)
{
printf("aw\n");
if(t.num<stu[i].num)
{
n=n+1;
for(j=n-2;j>i-1;j--) stu[j+1]=stu[j];
stu[i]=t;
break;
}
}
if((fp=fopen("student_number","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fwrite(&n,sizeof(n),1,fp);
if((fp=fopen("student","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fwrite(&stu[i],LEN,1,fp);
fclose(fp);
begin:
printf("@是否继续“添加”操作(y/n)?\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y') add();
else if(ch=='n'||ch=='N') ;
else { printf("输入有误!\n"); goto begin;}
}
/*3.删除学生信息*/
void del()
{
int i,numb,mark=0;
char ch;
printf("输入要删除学生的学号:\n");
scanf("%d",&numb);
if((fp=fopen("student_number","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fread(&n,sizeof(n),1,fp);
if((fp=fopen("student","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
{
fread(&stu[i],LEN,1,fp);
if(stu[i].num==numb)
{
i--;
n--;
mark=1;
}
}
if(mark==0) printf("没有该生信息\n");
if((fp=fopen("student_number","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fwrite(&n,sizeof(n),1,fp);
if((fp=fopen("student","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fwrite(&stu[i],LEN,1,fp);
fclose(fp);
begin:
printf("@是否继续“删除”操作(y/n)?\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y') del();
else if(ch=='n'||ch=='N') ;
else { printf("输入有误!\n"); goto begin;}
}
/*4.修改学生信息*/
void change()
{
int i,numb,mark=0;
float score1,score2,score3,totall,average;
char ch;
printf("输入要修改学生的学号 高数成绩 英语成绩 C语言成绩:\n");
scanf("%d %f %f %f",&numb,&score1,&score2,&score3);
if((fp=fopen("student_number","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fread(&n,sizeof(n),1,fp);
if((fp=fopen("student","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
{
fread(&stu[i],LEN,1,fp);
if(stu[i].num==numb)
{
totall=score1+score2+score3;
average=totall/3;
stu[i].score1=score1;
stu[i].score2=score2;
stu[i].score3=score3;
stu[i].total=totall;
stu[i].average=average;
mark=1;
}
}
if(mark==0) printf("没有该生信息\n");
if((fp=fopen("student_number","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fwrite(&n,sizeof(n),1,fp);
if((fp=fopen("student","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fwrite(&stu[i],LEN,1,fp);
fclose(fp);
begin:
printf("@是否继续“修改”操作(y/n)?\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y') del();
else if(ch=='n'||ch=='N') ;
else { printf("输入有误!\n"); goto begin;}
}
/*5.查询操作*/
//(1)按学号查询,输入一个学号,输出对应的学生信息。
void num_search()
{
int i,num,mark=0;
printf("输入学号:\n");
scanf("%d",&num);
for(i=0;i<n;i++)
if(stu[i].num==num)
{
printf("学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[i].num,stu[i].name,stu[i].x_num,stu[i].class_num,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
mark=1;
}
if(mark==0) printf("没有找到相关信息。\n");
}
//(2)按全名查询。
void name_search()
{
int i,mark=0;
char name[20];
printf("输入姓名:\n");
scanf("%s",name);
for(i=0;i<n;i++)
if(strcmp(stu[i].name,name)==0)
{
printf("学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[i].num,stu[i].name,stu[i].x_num,stu[i].class_num,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
mark=1;
}
if(mark==0) printf("没有找到相关信息。\n");
}
//(3)按姓氏查询。
void firstname_search()
{
int i,mark=0;
char name[20];
printf("输入姓氏:\n");
scanf("%s",name);
for(i=0;i<n;i++)
if(stu[i].name[0]==name[0] && stu[i].name[1]==name[1])
{
printf("学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[i].num,stu[i].name,stu[i].x_num,stu[i].class_num,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
mark=1;
}
if(mark==0) printf("没有找到相关信息。\n");
}
//(4)按学院查询,输入学院名称,输出该学院的全部学生的信息。
void x_search()
{
int i,x_num,mark=0;
printf("输入学院代号:\n");
scanf("%d",&x_num);
for(i=0;i<n;i++)
if(stu[i].x_num==x_num)
{
printf("学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[i].num,stu[i].name,stu[i].x_num,stu[i].class_num,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
mark=1;
}
if(mark==0) printf("没有找到相关信息。\n");
}
//(5)按班级查询,输入班级名称,输出该班级的全部学生的信息。
void classnum_search()
{
int i,class_num,mark=0;
printf("输入学院代号:\n");
scanf("%d",&class_num);
for(i=0;i<n;i++)
if(stu[i].class_num==class_num)
{
printf("学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[i].num,stu[i].name,stu[i].x_num,stu[i].class_num,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
mark=1;
}
if(mark==0) printf("没有找到相关信息。\n");
}
//查询模块
void search()
{
char ch;
int i;
if((fp=fopen("student_number","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fread(&n,sizeof(n),1,fp);
if((fp=fopen("student","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fread(&stu[i],LEN,1,fp);
fclose(fp);
printf("选择要进行查询的关键字代号:1、学号查询。2、按全名查询。3、按姓氏查询。4、学院查询。5、班级查询。\n");
fflush(stdin);
ch=getchar();
switch(ch)
{
case '1': num_search(); break;
case '2': name_search(); break;
case '3': firstname_search(); break;
case '4': x_search(); break;
case '5': classnum_search(); break;
default :printf("输入代号有误。\n");
}
begin:
printf("@是否继续“查询”操作(y/n)?\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y') search();
else if(ch=='n'||ch=='N') ;
else { printf("输入有误!\n"); goto begin;}
}
/*6.统计*/
//(1)按总分对学生信息进行排序(由高到低),输出排序后的信息,并将排序后的学生信息存放到一个新的二进制文件中。
void totall_score()
{
int i,j;
struct student t;
for(j=0;j<n-1;j++)
for(i=0;i<n-j-1;i++)
if(stu[i].total<stu[i+1].total)
{
t=stu[i];
stu[i]=stu[i+1];
stu[i+1]=t;
}
if((fp=fopen("student_number","wb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fwrite(&n,sizeof(n),1,fp);
if((fp=fopen("student_totalscore","wb"))==NULL) //按总分排序并保存至新的文件夹中。
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
{
printf("学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[i].num,stu[i].name,stu[i].x_num,stu[i].class_num,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
fwrite(&stu[i],LEN,1,fp);
}
fclose(fp);
}
//(2)按平均分统计各个分数段的学生人数(不及格,60-69,70-79,80-89,90-100)。
void each_score()
{
int e,d,c,b,a,i;
a=b=c=d=e=0;
for(i=0;i<n;i++)
{
if(stu[i].average<60) e++;
else if(stu[i].average<70) d++;
else if(stu[i].average<80) c++;
else if(stu[i].average<90) b++;
else a++;
}
printf("不及格人数为%d\n 60-69人数为%d\n 70-79人数为%d\n 80-89人数为%d\n 90-100人数为%d\n",e,d,c,b,a);
}
//(3)分别找出3门课程成绩最高的学生,并输出他们的信息。
void high_stu()
{
int max1,max2,max3,i;
max1=max2=max3=0;
for(i=0;i<n;i++)
{
if(stu[max1].score1<stu[i].score1) max1=i;
if(stu[max2].score2<stu[i].score2) max2=i;
if(stu[max3].score3<stu[i].score3) max3=i;
}
printf("高数最高成绩学生信息:\n学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[max1].num,stu[max1].name,stu[max1].x_num,stu[max1].class_num,stu[max1].score1,stu[max1].score2,stu[max1].score3,stu[max1].total,stu[max1].average);
printf("英语最高成绩学生信息:\n学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f总分:%0.2f 平均分:%0.2f\n",stu[max2].num,stu[max2].name,stu[max2].x_num,stu[max2].class_num,stu[max2].score1,stu[max2].score2,stu[max2].score3,stu[max2].total,stu[max2].average);
printf("c语言最高成绩学生信息:\n学号:%d 姓名:%s 学院代号:%d 班级号:%d 高数成绩:%0.2f 英语成绩:%0.2f c语言成绩:%0.2f 总分:%0.2f 平均分:%0.2f\n",stu[max3].num,stu[max3].name,stu[max3].x_num,stu[max3].class_num,stu[max3].score1,stu[max3].score2,stu[max3].score3,stu[max3].total,stu[max3].average);
}
//(4)分别统计出3门课程的不及格率,并输出。
void filled()
{
int i;
float f1,f2,f3,sf1,sf2,sf3;
f1=f2=f3=0;
for(i=0;i<n;i++)
{
if(stu[i].score1<60) f1++;
if(stu[i].score2<60) f2++;
if(stu[i].score3<60) f3++;
}
sf1=f1/n;
sf2=f2/n;
sf3=f3/n;
printf("高数不及格率为%0.2f\n",sf1);
printf("英语不及格率为%0.2f\n",sf2);
printf("c语言不及格率为%0.2f\n",sf3);
}
//统计模块
void stat()
{
char ch;
int i;
if((fp=fopen("student_number","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
fread(&n,sizeof(n),1,fp);
if((fp=fopen("student","rb"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
for(i=0;i<n;i++)
fread(&stu[i],LEN,1,fp);
printf("选择要进行的统计操作代号:\n1、按总分由高到低。\n2、按平均分统计各个分数段的学生人数(不及格,60-69,70-79,80-89,90-100)。\n3、找出3门课程成绩最高的学生。\n4、统计出3门课程的不及格率。\n");
fflush(stdin);
ch=getchar();
switch(ch)
{
case '1': totall_score(); break;
case '2': each_score(); break;
case '3': high_stu(); break;
case '4': filled(); break;
default :printf("输入代号有误。\n");
}
begin:
printf("@是否继续“统计”操作(y/n)?\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y') stat();
else if(ch=='n'||ch=='N') ;
else { printf("输入有误!\n"); goto begin;}
}
/*主选项*/
void action()
{
char ch;
printf("输入想要进行操作的代码:\n1、输入学生信息;\n2、增加学生信息;\n3、删除学生信息;\n4、修改学生信息;\n5、按不同条件对学生信息进行查询操作;\n6、按不同条件对学生成绩进行统计工作。\n");
fflush(stdin);
ch=getchar();
switch(ch)
{
case '1':creat();break; //输入学生信息
case '2':add();break; //增加学生信息
case '3':del();break; //删除学生信息
case '4':change();break; //修改学生信息
case '5':search();break; //按不同条件对学生信息进行查询操作
case '6':stat();break; //按不同条件对学生成绩进行统计工作
default:printf("输入代号有误。\n");
}
begin:
printf("#是否继续进行“管理”操作?(y/n)\n");
fflush(stdin);
ch=getchar();
if(ch=='y'||ch=='Y') action();
else if(ch=='n'||ch=='N') ;
else { printf("输入有误!\n"); goto begin;}
}
//主函数
void main()
{
printf("~~~~~~学生成绩管理系统~~~~~~\n\n");
action();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-23
#include<iostream>
#include<cstring>
#include<malloc.h>
using namespace std;

struct lx
{
long num;
char name[20];
struct lx *link;
};

struct lx *addlist(struct lx *head,long x);//添加节点;
void listclear(struct lx *head);
struct lx *createlist(void );
void listprintf(struct lx *p);

int main(int argc,char **argv)
{
long x;
struct lx *p = createlist();
listprintf(p);
cout<<"输入学号"<<endl;
cin>> x;
struct lx *head = addlist(p,x);
listprintf(head);
listclear(head);
//listprintf(temp);
return 0;
}
struct lx *createlist(void )
{
struct lx *head ;
struct lx *tail ;
struct lx *p;
char buf[20];
head = NULL;

p = (struct lx *)malloc(sizeof (struct lx));

// cout<< "内存分配失败!!!!"<< endl;

cout<< "请输入学号:";
cin>> p->num;

cout<< "请输入姓名:";
cin>> p->name;
//cout<<buf<<endl;
//strcpy(p->name, buf);
while(1)
{

if(head == NULL)
{
head = p;
tail = p;
}

else
{
tail->link = p;
tail = p;
}

p = (struct lx*)malloc(sizeof(struct lx));

// cout<<"内存分配失败!!!!!"<< endl;

cout<< "请输入学号:";
cin>> p->num;
if(p->num == 0)
break;
cout<< "请输入姓名:";
cin>> p->name;
//strcpy(p->name,buf);
}
tail->link = NULL;

return head;
}

void listprintf(struct lx *p)
{
struct lx* q = p;
while(q!= NULL)
{

cout<< q->num<<endl;
cout<< q->name<<endl;
q = q->link;
}

}
struct lx *addlist(struct lx *head,long x)//添加节点
{
struct lx *p = head;
struct lx *q,*temp,*temp1;
q = NULL;

if(p->link == NULL )
{
if((p->num ) > x )
{
q=(struct lx *)malloc(sizeof(struct lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num = x;
q->link = p;
p = q;
}

else
{
q=(struct lx *)malloc(sizeof(struct lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num = x;
temp1 = p->link;
p->link = q;
q->link = temp1;
temp1->link = NULL;
}

}
else if(((p->num) > x)&&((p->link)->link == NULL))
{
q=(struct lx *)malloc(sizeof(struct lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num = x;
p->link = q;
q->link = p;
q->link = NULL;
}
else
{
while(1)
{
if((p->num < x)&&((p->link)->num > x))
break;
p = p->link;
}

q=(struct lx *)malloc(sizeof(struct lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num = x;
temp = p->link;
p->link = q;

q->link = temp;
}
return p;
}

void listclear(str
相似回答