学生信息管理系统c语言版(基于文件,链表)
/*基于文件储存的学生管理系统*/
/*
总结:
链表的排序采用了交换数据,而非交换节点,应该改进一下。
*/
#include
#include
#include
#include
/*定义接口*/
struct student{
long id;
char name[10];
char sex[4];
int age;
float score[3];
struct student* next;
};
int check(student *pp);
student* p=0;
student* pread=0;//头指针
int cou=0;//查找分数段内的学生人数
student* creat();
void insert();
student* edit();
student* del();
student* read();
void outsc();
void write();
float sumscore(student* pp);
void swap(student* pf,student* pb);
student* paixu(int n);
student* seek(float n,float m);
/*定义实现*/
int check(student *pp){
if(pp->score[0]>100||pp->score[0]<0){printf("错误。高数成绩区间是0~100\n");return 2;}
if(pp->score[1]>100||pp->score[1]<0){printf("错误。英语成绩区间是0~100\n");return 2;}
if(pp->score[2]>100||pp->score[2]<0){printf("错误。计算机成绩区间是0~100\n");return 2;}
student* pt;pt=p;
int ff=1;
while(pt!=pp&&ff&&pp!=p&&pt)
{
if(pp->id==pt->id){printf("错误。已有该学号");ff=0;return 2;}
pt=pt->next;
}
return 1;
}
student* create()
{
student *p1,*p2;
p=(student* )malloc(sizeof(student));
p1=p;p2=p;
int flag=1;//两个开关
int chk=1;
while(chk){
printf("请输入学生的学号,姓名,性别,年龄都用空格分开\n");
scanf("%d%s%s%d",&p1->id,p1->name,p1->sex,&p1->age);
printf("请输入他或她的高数,英语,计算机三科成绩,用空格分开\n");
cin>>(p1->score[0])>>(p1->score[1])>>(p1->score[2]);
if(check(p1)==2){cout<
else if(check(p1)==1)chk=0;
}
while(flag){
int opt;
printf("请输入你的选择\n1继续输入2停止? ");
scanf("%d",&opt);
if(opt==1){
p1=(student* )malloc(sizeof(student));
p2->next=p1;
p2=p1;
chk=1;
while(chk){
printf("请输入学生的学号,姓名,性别,年龄都用空格分开\n");
scanf("%d%s%s%d",&p1->id,p1->name,p1->sex,&p1->age);
printf("请输入他或她的高数,英语,计算机三科成绩,用空格分开\n");
cin>>(p1->score[0])>>(p1->score[1])>>(p1->score[2]);
if(check(p1)==2)printf("请您重新输入\n");
else if(check(p1)==1)chk=0;
}
}
else if(opt==2)flag=0;
p1->next=0;
}
return p;
}
void insert(){
int flag=1;
while(flag)
{printf("请输入你要做的事情\n1插入学生,2停止? ");
int opt=1;
scanf("%d",&opt);
if(opt==1)
{
student* ptem=(student* )malloc(sizeof(student));
int chk=1;
while(chk){
printf("请输入学生的学号,姓名,性别,年龄都用空格分开\n");
scanf("%d%s%s%d",&ptem->id,ptem->name,ptem->sex,&ptem->age);
printf("请输入他或她的高数,英语,计算机三科成绩,用空格分开\n");
cin>>(ptem->score[0])>>(ptem->score[1])>>(ptem->scor