C语言学生管理系统(链表)

更新时间:2024-05-03 08:58:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

学生管理系统

#define_CRT_SECURE_NO_WARNINGS #include #include #include

voidAppendNode(longlong studentID,char studentName[10],char studentSex[4],int score[4]);//添加数据 voidDisplayNode(structlink*head);//显示数据

voidInsertNode(longlong studentID,char studentName[10],char studentSex[4],int score[4]);//插入一条数据;按总分的从大到小排序 voidInsertNodeNumber(longlong studentID,char studentName[10],char studentSex[4],int score[4]);//按学号的从小到大排序

voidNumberSorting(int flag);//按从大到小对数据进行排序;1、对总分进行排序,2、对学号进行排序 voidDeleteNodeID();//输入学号删除 voidDeleteNodeName();//输入学号删除

voidDeleteMemory(structlink*head);//删除聊表所占用的内存; voidSave();//保存数据 voidOpen();//打开数据

voidFindID();//按学号查找学生 voidFindName();//按姓名查找学生;

voidMenu();

typedefstructstudent {

longlongstudentID; charstudentName[10]; charstudentSex[4]; intscore[4];

}STU; structlink { };

structlink*head=NULL;//保存输入的学生信息数据 structlink*head1=NULL;//保存排序后的学生信息数据 intmain() {

longlongstudentID; charstudentName[10]; charstudentSex[4];

intscore[4];//定义要输入学生信息的变量; charc; STUstudent; structlink*next;

intmenu;//保存要进行的选项; Open(); while(1) {

system(\); Menu();

printf(\请输入要进行的操作:\); scanf(\,&menu); switch(menu) {

case0:exit(0);

break;

case1:

printf(\请输入Y或y来添加数据\\n\); scanf(\,&c); while(c=='y'||c=='Y') {

printf(\请输入学生学号:\); scanf(\,&studentID); printf(\请输入学生姓名:\); scanf(\,&studentName); printf(\请输入学生性别:\);

}

scanf(\,&studentSex); inti=0;

printf(\请分别输入学生四门课的成绩:\); for(i=0;i<4;i++) { }

AppendNode(studentID,studentName,studentSex,score); printf(\请输入Y或y来添加数据\\n\); scanf(\,&c);

scanf(\,&score[i]);

DisplayNode(head); break;

case2:

FindID(); break;

case3:

FindName(); break;

case4:

DeleteNodeID(); break;

}

}

case5:

DeleteNodeName();

case6:

NumberSorting(1); DeleteMemory(head1); head1=NULL; break;

case7:

NumberSorting(2); DeleteMemory(head1); head1=NULL; break;

default: }

printf(\输入有误!请重新输入\);

Save();

DeleteMemory(head); DeleteMemory(head1); system(\);

voidAppendNode(longlongstudentID,charstudentName[10],charstudentSe

x[4],intscore[4]) {

structlink*p=NULL,*pr=head;

p=(structlink*)malloc(sizeof(structlink)); if(p==NULL) { }

if(head==NULL) { } else{ }

p->student.studentID=studentID;

strcpy(p->student.studentName,studentName);

while(pr->next!=NULL) { }

pr->next=p;

pr=pr->next; head=p;

printf(\申请内存失败\); return;

}

strcpy(p->student.studentSex,studentSex); p->student.score[0]=score[0]; p->student.score[1]=score[1]; p->student.score[2]=score[2]; p->student.score[3]=score[3]; p->next=NULL; return;

voidNumberSorting(intflag) {

structlink*p=head; structlink*p1=head1; intsum=0;

if(p==NULL) { }

while(p!=NULL) {

switch(flag) {

printf(\没有数据,无法排序\); return;

case1:

InsertNode(p->student.studentID,p->student.studentName,p->stude

nt.studentSex,p->student.score);

break;

case2:

InsertNodeNumber(p->student.studentID,p->student.studentName,p-

>student.studentSex,p->student.score); }

voidDisplayNode(structlink*head) {

structlink*p=head; if(p==NULL)

}

DisplayNode(head1);

break;

default: }

p=p->next;

printf(\程序异常,请重试!\); break;

}

{ }

printf(\,p->student.studentID); printf(\,p->student.studentName); printf(\,p->student.studentSex); { }

printf(\);

DisplayNode(p->next);

inti=0;

for(i=0;i<4;i++) { }

printf(\,p->student.score[i]); return;

voidDeleteMemory(structlink*head) {

structlink*p=head,*pr=NULL; while(p!=NULL) {

pr=p;

}

}

p=p->next; free(pr);

voidInsertNodeNumber(longlongstudentID,charstudentName[10],charstudentSex[4],intscore[4]) {

structlink*pr=head1,*p=head1,*temp=NULL; p=(structlink*)malloc(sizeof(structlink)); if(p==NULL) { }

p->next=NULL;

p->student.studentID=studentID;

strcpy(p->student.studentName,studentName); strcpy(p->student.studentSex,studentSex); p->student.score[0]=score[0]; p->student.score[1]=score[1]; p->student.score[2]=score[2];

printf(\内存申请失败\); return;

p->student.score[3]=score[3]; if(head1==NULL) { } else {

while(pr->student.studentIDnext!=NULL) { }

if(pr->student.studentID>=studentID) {

if(pr==head1) { } else {

pr=temp; p->next=head1; head1=p; temp=pr; pr=pr->next; head1=p;

}

}

}

}

p->next=pr->next; pr->next=p;

else { }

pr->next=p;

return;

voidInsertNode(longlongstudentID,charstudentName[10],charstudentSex[4],intscore[4]) {

structlink*pr=head1,*p=head1,*temp=NULL; intsum,sum1;

p=(structlink*)malloc(sizeof(structlink)); if(p==NULL) {

printf(\内存申请失败\);

}

return;

p->next=NULL;

p->student.studentID=studentID;

strcpy(p->student.studentName,studentName); strcpy(p->student.studentSex,studentSex); p->student.score[0]=score[0]; p->student.score[1]=score[1]; p->student.score[2]=score[2]; p->student.score[3]=score[3];

sum=p->student.score[0]+p->student.score[1]+p->student.score[2]

+p->student.score[3];

sum1=pr->student.score[0]+pr->student.score[1]+pr->student.scorif(head1==NULL) { } else {

head1=p;

e[2]+pr->student.score[3];

while(sum1>sum&&pr->next!=NULL)

{

temp=pr; pr=pr->next;

sum1=pr->student.score[0]+pr->student.score[1]+pr->student.scor

e[2]+pr->student.score[3];

}

if(sum1<=sum) { } else

if(pr==head1) { } else { }

pr=temp;

p->next=pr->next; pr->next=p; p->next=head1; head1=p;

}

}

{ }

pr->next=p;

return;

voidDeleteNodeID()//输入学号删除 {

structlink*p=head,*pr=head; longlongstudentID=0; if(head==NULL){ }

printf(\请输入你要删除的学生的学号\); scanf(\,studentID);

while(studentID!=p->student.studentID&&p->next!=NULL) {

pr=p;

printf(\对不起,没有数据可以删除\); return;

}

}

p=p->next;

if(studentID==p->student.studentID) { } else { } return;

printf(\你要查找的这个数据未找到\); if(p==head){ } else { } free(p);

pr->next=p->next; head=p->next;

voidDeleteNodeName()//输入姓名删除 {

structlink*p=head,*pr=head;

charstudentName[10]=\; if(head==NULL){ }

printf(\请输入你要删除的学生的姓名:\); scanf(\,studentName);

while(0!=strcmp(studentName,p->student.studentName)&&p->next!=N

printf(\对不起,没有数据可以删除\); return;

ULL)

{ }

if(0==strcmp(studentName,p->student.studentName)) {

if(p==head){ } else { }

pr->next=p->next; head=p->next; pr=p; p=p->next;

}

}

free(p);

else { } return;

printf(\你要查找的这个数据未找到\);

voidSave()//保存链表中的数据 {

fprintf(fp,\,p->student.studentID,p->FILE*fp;

structlink*p=head;

if((fp=fopen(\,\))==NULL) { }

while(p!=NULL) {

printf(\打开文件失败\); return;

student.studentName,p->student.studentSex,

}

}

p->student.score[0], p->student.score[1], p->student.score[2], p->student.score[3]);

p=p->next;

fclose(fp); return;

voidOpen()//将文件中获得的数据写入到链表中 {

longlongstudentID; charstudentName[10]; charstudentSex[4]; intscore[4]; FILE*fp; charc;

if((fp=fopen(\,\))==NULL) { }

printf(\文件打开失败\); return;

}

while((c=fgetc(fp))!=EOF) { }

fclose(fp);

fscanf(fp,\,&studentID); fscanf(fp,\,studentName); fscanf(fp,\,studentSex); fscanf(fp,\,&score[0]); fscanf(fp,\,&score[1]); fscanf(fp,\,&score[2]); fscanf(fp,\,&score[3]);

AppendNode(studentID,studentName,studentSex,score);

voidFindID() {

structlink*p=head; longlongstudentID=0; if(head==NULL) { }

printf(\没有数据查找\); return;

printf(\请输入你要查找的学生的学号:\); scanf(\,&studentID);

while(studentID!=p->student.studentID&&p->next!=NULL) { }

if(studentID==studentID) { } else{ }

printf(\没有你要查找的数据\); printf(\,p->student.studentID); printf(\,p->student.studentName); printf(\,p->student.studentSex); { }

inti=0;

for(i=0;i<4;i++) { }

printf(\,p->student.score[i]);

p=p->next;

}

return;

voidFindName() {

structlink*p=head; charstudentName[10]=\; if(head==NULL) { }

printf(\请输入你要查找的学生的姓名:\); scanf(\,studentName);

while(0!=strcmp(studentName,p->student.studentName)&&p->next!=N

printf(\没有数据查找\); return;

ULL)

{ }

if(0==strcmp(studentName,p->student.studentName)) {

printf(\,p->student.studentID); printf(\,p->student.studentName); p=p->next;

}

}

printf(\,p->student.studentSex); { }

inti=0;

for(i=0;i<4;i++) { }

printf(\,p->student.score[i]);

else{ } return;

printf(\没有你要查找的数据\);

voidMenu() {

system(\);//清平操作;

printf(\);//输入回车,形成格式;

printf(\学生管理系统..............|\\n\);//

printf(\退出。 |\\n\);//“/t”水平制表,相当于一个tab键;

printf(\添加学生成绩信息! |\\n\);

}

printf(\查找学生(按学号)信息! |\\n\); printf(\查找学生(按姓名)信息! |\\n\); printf(\删除学生成绩(按学号)信息! |\\n\); printf(\删除学生成绩(按姓名)信息! |\\n\); printf(\按总分排序! |\\n\); printf(\按学号排序! |\\n\); printf(\学生管理系统..............|\\n\);//

本文来源:https://www.bwwdw.com/article/j9jg.html

Top