求大侠 帮忙做一个项目`` ~!学生数据管理系统
用C语言编写一个程序实现学员成绩管理,每个学员包括3门课的成绩.(语文,数学,英语) 从键盘输入学员信息,包括学号,姓名,3门课成绩,计算出学员的平均成绩,按照学员平均成绩由大到小排序.另外需要增加下面的管理功能.
插入功能:在排序后的学员成绩表中插入一个学员的信息,要求插入后仍然保持成绩表原有的排序.
删除功能:要求输入指定的学号,从学员信息表中删除该学员,删除后的成绩表保持原有排序.
查找功能:按学号查找出学员的资料.
(使用的知识点 数组 带参数的函数 字符串 结构)
请写出完整代码
[解决办法]
楼上的兄弟说话太刻薄了,偶看不过去了!
[解决办法]
以前讨论过的一个问题,代码归cuibo1123(月满C楼)所有,任何由本代码运行造成的后果本人概不负责,如果愿意的话也可以把本楼的得分给cuibo1123(月满C楼)。
参看原帖
http://community.csdn.net/Expert/topic/5660/5660209.xml?temp=.571438
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MY_QUIT 2
struct std
{
char ID[11],name[21];
float cj[3];
float num;
struct std *next;
};
int myfree(struct std *head);
int myquit(struct std *head);
int myexit(struct std *head);
struct std *addstd(struct std *head);
struct std *delstd(struct std *head);
int dirall(struct std *head);
struct std *reddat(char *filen,struct std *head);
int whidat(struct std *head);
int main(void)
{
int xx,zt=1;
struct std *HEAD=NULL;
HEAD=reddat(NULL,HEAD);
while(zt!=MY_QUIT)
{
system( "cls ");
xx=0;
puts( "[NUME]\n\n1:添加记录 \n2:删除记录 \n3:显示全部信息 \n4:读取数据库 \n5:写入数据库 \n0: 退出\n ");
printf( "请输入命令: ");
scanf( "%d ",&xx);
system( "cls ");
switch(xx)
{
case 0: zt=myquit(HEAD);break;
case 1: HEAD=addstd(HEAD);break;
case 2: HEAD=delstd(HEAD);break;
case 3: dirall(HEAD);getch();break;
case 4: myfree(HEAD);HEAD=reddat(NULL,HEAD);getch();break;
case 5: whidat(HEAD);getch();break;
default : printf( "您输入的命令不存在. ");getch();
}
/*if(zt==0){puts( "system error! ");getch();myexit(HEAD);}*/
}
getch();
return 0;
}
int myfree(struct std *head)
{
int i=0;
struct std *sp;
printf( "\n正在释放内存... ");
while(head-> ID[0]!=0 && head-> next!=NULL)
{
printf( "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%15d ",++i);
/*i++;
if(i==1052 || i==1053 || i==1054 || i==1055)
{
printf( "\n%d学号:%s 姓名:%s 分数:%.2f-%.2f-%.2f 平均分:%.2f ",i,head-> ID,head-> name,head-> cj[0],head-> cj[1],head-> cj[2],head-> num);
}*/
sp=head;
head=head-> next;
free(sp);
}
free(head);
puts( "\tOK ");
}
int myquit(struct std *head)
{
char ch;
puts( "您确定您已经对修改过的数据库进行了保存(Y/N)?\n\n为了您的数据安全,退出时程序不会帮助您保存数库. ");
fflush(stdin);
ch=getchar();
if(ch== 'n ' || ch== 'N ')return 1;
myfree(head);
return MY_QUIT;
}
int myexit(struct std *head)
{
char ch;
system( "cls ");
puts( "程序发生了错误即将退出,无法保存当前数据. ");
myfree(head);
exit(0);
return MY_QUIT;
}
struct std *addstd(struct std *head)
{
struct std *sp,*sq,*h=head;
char ch= 'y ';
int i;
while(ch== 'y ' || ch== 'Y ')
{
head=h;
i=1;
system( "cls ");
puts( "添加新学生\n\n\n ");
sp=(struct std *)malloc(sizeof(struct std));
printf( "学生ID: ");scanf( "%s ",sp-> ID);
printf( "姓 名: ");scanf( "%s ",sp-> name);
do
{
printf( "成 绩1: ");scanf( "%f ",sp-> cj);
printf( "成 绩2: ");scanf( "%f ",sp-> cj+1);
printf( "成 绩3: ");scanf( "%f ",sp-> cj+2);
if(sp-> cj[0]> =0 && sp-> cj[1]> =0 && sp-> cj[2]> =0) break;
puts( "请仔细核对成绩. ");
}while(1);
sp-> num = (sp-> cj[0]+sp-> cj[1]+sp-> cj[2])/3;
printf( "此学生平均成绩为:%f ",sp-> num);
if(head-> ID[0] == 0 || sp-> num > = head-> num)
{
sp-> next=head;h=sp;
}
else
{
while(sp-> num <= head-> num)
{
i++;
sq=head;
head=head-> next;
}
sp-> next=head;
sq-> next=sp;
}
printf( "\t目前排名:%d ",i);
puts( "\n\n按Y键继续添加... ");
ch=getch();
}
return h;
}
struct std *delstd(struct std *head)
{
struct std *sq,*h=head;
char ch= 'y ',sid[11];
int i=0;
while(ch== 'y ' || ch== 'Y ')
{
system( "cls ");
puts( "删除学生信息\n\n\n ");
printf( "请输入要删除学生的学号: ");
fflush(stdin);
gets(sid);
head=h;
sq=head;
while(head-> ID[0] != 0)
{
if(!strcmp(sid,head-> ID))
{
i=1;
printf( "\n确认删除 学生ID:%s 姓名:%s 的记录(Y/N)?\n ",head-> ID,head-> name);
ch=getch();
if(ch== 'y ' || ch== 'Y ')
{
if(sq == head) h=h-> next;
sq-> next=head-> next;
free(head);
puts( "记录被成功删除. ");
}
}
sq=head;
head=head-> next;
}
if(!i) puts( "没有符合条件的记录. ");
i=0;
puts( "\n\n按Y键继续删除其他记录... ");
ch=getch();
}
return h;
}
int dirall(struct std *head)
{
int i=0;
char ch= 'a ';
while(head-> ID[0]!= '\0 ')
{
i++;
if(ch!= 'q ')
{
printf( "名次:%5d\n学号:%-10s 姓名:%-20s\n分数:%.2f %.2f %.2f 平均分%.2f\n\n ",i,head-> ID,head-> name,head-> cj[0],head-> cj[1],head-> cj[2],head-> num);
puts( "-------------------------------------------------- ");
if(i%4==0)
{
puts( "按任意键显示下一页,按q键退出... ");
ch=getch();
printf( "\n\n\n\n\n-第%d页-\n-------\n ",i/4+1);
}
}
head=head-> next;
}
system( "cls ");
if(i==0){puts( "\n数据库中没有记录! ");}
else{printf( "\n数据库中共有记录%d条 %d页 ",i,i/4+1);}
return 1;
}
struct std *reddat(char *filen,struct std *head)
{
FILE *fp;
struct std *sp,*sq;
int zt=0;
printf( "开始读取数据库std.dat到程序\t ");
if((fp=fopen( "std.dat ", "r "))==NULL)
{
puts( "open datefile error! ");
getch();
myexit(head);
}
head=sp=(struct std *)malloc(sizeof(struct std));
while(!feof(fp))
{
sq=(struct std *)malloc(sizeof(struct std));
zt=fscanf(fp, "%s\t%s\t%f\t%f\t%f\t%f\n ",sq-> ID,sq-> name,sq-> cj,sq-> cj+1,sq-> cj+2,&sq-> num);
/*printf( "%d ",zt);*/
if(zt!=6 && zt!=1 || (int)(sp-> num*3 - sp-> cj[0] - sp-> cj[1] - sp-> cj[2]))
{
zt=-1;
break;
}
sp-> next=sq;
sp=sq;
}
fclose(fp);
if(zt==-1 || sp-> ID[0]!= '# ')
{
puts( "ERROR.\n数据库可能被其他程序编辑过,文件损坏,无法读取. ");
getch();
myexit(head);
}
sp-> ID[0]= '\0 ';
sp-> num=-100;
sp-> next=NULL;
sp=head;
head=head-> next;
printf( "OK.\n正在清理临时变量\t ");
free(sp);
printf( "OK.\n\n数据库读取完毕,没有发生任何异常. ");
return head;
}
int whidat(struct std *head)
{
FILE *fp,*fp1;
char ch;
printf( "开始备份数据库为stdb.dat\t ");
fp1=fopen( "stdb.dat ", "w ");
if((fp=fopen( "std.dat ", "r+ "))==fp1)
{
puts( "open datefile error! ");
getch();
myexit(head);
}
while(!feof(fp))
{
ch=fgetc(fp);
fputc(ch,fp1);
}
fclose(fp1);
printf( "OK.\n开始保存新的数据到数据库\t ");
fseek(fp,0L,SEEK_SET);
while(head-> ID[0]!= '\0 ')
{
fprintf(fp, "%s\t%s\t%f\t%f\t%f\t%f\n ",head-> ID,head-> name,head-> cj[0],head-> cj[1],head-> cj[2],head-> num);
head=head-> next;
}
fputc( '# ',fp);
fclose(fp);
printf( "OK.\n\n写入数据库操作执行完毕.没有发生任何异常. ");
return 1;
}
[解决办法]
www.shubulo.com
这里有电子版~
[解决办法]
/*自己写的学生管理程序,求分。*/
#include <stdio.h>
#define MAX 100
#define STU struct stu
STU /*结构体*/
{
int num;
char name[20];
float cn;
float ma;
float en;
float avg;
};
STU student[MAX]; //数组,存储学生信息
int i=0;
void sort(float score)//排序
{
int j;
STU k;
for(j=i-1;j> =0;j--)
if(score> student[j].avg)
{
k=student[j];
student[j]=student[j+1];
student[j+1]=k;
}
}
int serach(int a)//查找
{
int j;
for(j=0;j <=i;j++)
if(student[j].num==a)
return j;
return -1;
}
void in() //输入学生信息
{
int a=-1;
STU member;
printf( "请输入学生信息,学号: ");
scanf( "%d ",&member.num);
a=serach(member.num);
if(a!=-1)//检测是否有重复学号。
{
printf( "*******************已有相同学号,请重新输入:*******************\n ");
}
else
{
printf( "请输入学生信息,姓名: ");
scanf( "%s ",&member.name);
printf( "请输入学生成绩信息,语文: ");
scanf( "%f ",&member.cn);
printf( "请输入学生成绩信息,数学: ");
scanf( "%f ",&member.ma);
printf( "请输入学生成绩信息,英语: ");
scanf( "%f ",&member.en);
member.avg=(member.cn+member.ma+member.en)/3;
printf( "该学生平均成绩:%.2f\n ",member.avg);
printf( "*********************************************************\n ");
student[i]=member;
sort(member.avg);
i++;
}
}
void showall()//显示所有学生信息
{
int j;
printf( "学号姓名语文数学英语平均分\n ");
for(j=0;j <i;j++)
printf( "%d%s%.2f%.2f%.2f%.2f\n ",student[j].num,student[j].name,student[j].cn,
student[j].ma,student[j].en,student[j].avg);
}
void del()//删除
{
int b,j=-1;
printf( "请输入待查学号: ");
scanf( "%d ",&b);
j=serach(b);
if(j==-1)
printf( "*******************未找到该学号下的学生信息。*******************\n ");
else
{
printf( "*******************学号为%d的学生信息已被删除*******************\n ",student[j].num);
while(j <=i)
{
student[j]=student[j+1];
j++;
}
i--;
}
}
main()
{
int a=0,b,j;
printf( "请选择需要进行的操作:\n ");
while (a!=5)
{
printf( "1、新增2查询3、删除4、浏览所有5、退出\n ");
printf( "请选择所需操作,数字1--5: ");
scanf( "%d ",&a);
if(a==1)
in();
else if (a==2)
{
printf( "请输入待查学号: ");
scanf( "%d ",&b);
j=serach(b);
if(b!=-1)
{
printf( "*********************************************************\n ");
printf( "学号%d的学生信息如下:\n ",student[j].num);
printf( "学号姓名语文数学英语平均分\n ");
printf( "%d%s%.2f%.2f%.2f%.2f\n ",student[j].num,student[j].name,student[j].cn,
student[j].ma,student[j].en,student[j].avg);
printf( "*********************************************************\n ");
}
else
{
printf( "*******************未找到该学号下的学生信息。*******************\n ");
}
}
else if(a==3)
del();
else if (a==4)
showall();
else if(a==5)
printf( "退出\n ");
else
printf( "******************请重新输入正确的数字******************\n ");
}
}