学生管理系统链表版文档格式.docx

上传人:b****2 文档编号:5273802 上传时间:2023-05-04 格式:DOCX 页数:23 大小:19.26KB
下载 相关 举报
学生管理系统链表版文档格式.docx_第1页
第1页 / 共23页
学生管理系统链表版文档格式.docx_第2页
第2页 / 共23页
学生管理系统链表版文档格式.docx_第3页
第3页 / 共23页
学生管理系统链表版文档格式.docx_第4页
第4页 / 共23页
学生管理系统链表版文档格式.docx_第5页
第5页 / 共23页
学生管理系统链表版文档格式.docx_第6页
第6页 / 共23页
学生管理系统链表版文档格式.docx_第7页
第7页 / 共23页
学生管理系统链表版文档格式.docx_第8页
第8页 / 共23页
学生管理系统链表版文档格式.docx_第9页
第9页 / 共23页
学生管理系统链表版文档格式.docx_第10页
第10页 / 共23页
学生管理系统链表版文档格式.docx_第11页
第11页 / 共23页
学生管理系统链表版文档格式.docx_第12页
第12页 / 共23页
学生管理系统链表版文档格式.docx_第13页
第13页 / 共23页
学生管理系统链表版文档格式.docx_第14页
第14页 / 共23页
学生管理系统链表版文档格式.docx_第15页
第15页 / 共23页
学生管理系统链表版文档格式.docx_第16页
第16页 / 共23页
学生管理系统链表版文档格式.docx_第17页
第17页 / 共23页
学生管理系统链表版文档格式.docx_第18页
第18页 / 共23页
学生管理系统链表版文档格式.docx_第19页
第19页 / 共23页
学生管理系统链表版文档格式.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

学生管理系统链表版文档格式.docx

《学生管理系统链表版文档格式.docx》由会员分享,可在线阅读,更多相关《学生管理系统链表版文档格式.docx(23页珍藏版)》请在冰点文库上搜索。

学生管理系统链表版文档格式.docx

{

charnum[5];

charname[20];

intscore;

structstudent*next;

};

structstudent*createlist()//创建链表的头指针

structstudent*head;

head=(structstudent*)malloc(sizeof(structstudent));

head->

next=NULL;

returnhead;

intSCANF(structstudent*head,structstudent*newnode)/*输入学生信息子函数并在此做出异常输入情况的判断*/

intLENTH;

//LENTH为输入的学生学号的长度

structstudent*p;

p=head->

next;

printf("

请输入学生学号:

\n"

scanf("

%s"

newnode->

num);

while(p)//第一种情况,输入的学号在系统中已经存在

{

if(strcmp(p->

num,newnode->

num)==0)

{

printf("

您输入的学号在该系统中已经存在,请按任意键重新输入!

\n"

getch();

return1;

}

else

p=p->

}

LENTH=strlen(newnode->

//以下第二种情况,输入的学号位数不是4位

if(LENTH!

=4)

printf("

您输入的学生学号必须为4位请按任意键重新输入!

\n\n\n"

getch();

return1;

//返回值为真,方便下面的调用

请输入学生姓名:

name);

请输入学生成绩:

%d"

&

newnode->

score);

return0;

//返回值为假

voidInsert(structstudent*head,structstudent*newnode)/*将学生信息按照学号由高到低排序并插入到链表中*/

structstudent*pre=head;

//pre前一个节点node后一个把newnode插入

structstudent*node=pre->

while(node!

=NULL)

if(strcmp(node->

num,newnode->

num)<

0)//按学号由低到高插入

pre=node;

node=node->

break;

pre->

next=newnode;

//找到了结点的位置将结点插入到链表中

newnode->

next=node;

intADD(structstudent*head)/*添加学生信息*/

structstudent*p;

p=(structstudent*)malloc(sizeof(structstudent));

while(SCANF(head,p))//异常学号输入情况的处理

system("

cls"

structstudent*p1=head;

structstudent*p2=p1->

Insert(head,p);

如果需要继续输入请按y,返回主菜单请按其它任意键\n"

chari;

i=getch();

if(i=='

y'

{

system("

ADD(head);

}

voidDELETE(structstudent*head)/*删除学生信息*/

structstudent*p1,*p2;

/*p1为查找到要删除的结点指针,p2为其前驱指针*/

chars[256];

structstudent*p;

学生信息如下:

\n\n"

for(p=head->

p;

p=p->

next)/*辅助输出学生信息*/

|学号:

%8s|姓名:

%8s|成绩:

%6d|\n"

p->

num,p->

name,p->

请输入要删除的学号Pleaseenterthedeletednum:

\n"

如果要删除全部学生信息,请按0000\n"

scanf("

s);

p1=head->

p2=head;

if(strcmp(s,"

0000"

)!

=0)

while(p1!

if(strcmp(p1->

num,s))

p2=p1;

/*p2为其前驱指针*/

p1=p1->

if(p1!

=NULL)

p2->

next=p1->

您输入的学生删除成功@@@@\n请按任意键返回主菜单\n"

getch();

free((void*)p1);

if(p1==NULL)

\n没有该学生Thereisnonum%sstudentonthelist.\n"

请按任意键返回主菜单重新选择\n"

)==0)

head->

next=NULL;

printf("

全部学生信息删除成功@@@@\n"

printf("

getch();

voidMODIFY(structstudent*head)/*修改学生信息*/

charnum[256];

请输入要修改的学生的学号:

num);

structstudent*p2=p1->

while(p2)

if(strcmp(p2->

num,num)!

=0)

p1=p2;

p2=p2->

if(!

p2)

else

p2->

num,p2->

name,p2->

printf("

请重新输入该学生信息:

p2->

p2->

voidQUERY(structstudent*head)/*查询学生信息,三种方式查询*/

chars[5];

请选择查询方式:

1,按学号查找;

2,按姓名查找;

3.按成绩查找\n"

i=getch();

if(i=='

1'

请输入学生学号来查找.Pleaseenternumforsearching.\n"

您要查询的学生信息如此下:

for(p=head;

next)

if(strcmp(p->

num,s)==0)

|%4s|%4s|%3d|\n"

查询完毕,请按任意键返回@@@\n"

if(p==NULL)

intj=0;

if(i=='

2'

请输入姓名来查找.Pleaseenternameforsearching.\n"

name,s)==0)

j++;

if((p==NULL)&

&

(j==0))

\n没有该学生Thereisnoname%sstudentonthelist.\n"

if(p==NULL)

inty=0;

3'

{intSCORE;

请输入成绩来查找.Pleaseenterscoreforsearching.\n"

SCORE);

if(p->

score==SCORE)

y++;

if((p==NULL)&

(y==0))

\n没有对应该成绩的学生\n"

voidPRINT(structstudent*head)/*打印全部学生信息*/

floataverage=0.00000000;

intITOTAL=1;

学生信息如下\n"

\n*******************************STUDENTLIST************************************\n"

-------------------------------------------------------------------------------\n"

while(p)

|%d|学号:

%8s|姓名:

%8s|成绩:

%6d|\n"

ITOTAL++,p->

average=average+p->

score;

p=p->

**************************************END**************************************\n\n"

if(ITOTAL!

=1)

学生总人数为:

%d\n"

ITOTAL-1);

average=average/(ITOTAL-1);

学生平均成绩为:

%f\n"

average);

if(ITOTAL==1)

学生人数为0,不存在平均成绩\n"

请按数字键1系统将按成绩由高到低打印学生信息\n"

charI;

I=getch();

if(I=='

{

intn=ITOTAL-1;

//n为学生总人数

structstudentstu[256],stu1;

inti,j;

p1=head;

p2=p1->

intX=0;

for(i=0;

p2!

=NULL;

i++)

strcpy(stu[i].num,p2->

strcpy(stu[i].name,p2->

stu[i].score=p2->

X++;

p1=p2;

p2=p2->

for(j=0;

j<

X-1;

j++)

i<

X-1-j;

if(stu[i].score>

stu[i+1].score)

stu1=stu[i];

stu[i]=stu[i+1];

stu[i+1]=stu1;

for(i=n-1;

i>

=0;

i--)

printf("

学号姓名成绩\n"

%5s%5s%5d\n"

stu[i].num,stu[i].name,stu[i].score);

}

FILE*MyOpenFile(char*fname,chars[5])/*打开文件子函数并返回文件头指针*/

FILE*fp;

fp=fopen(fname,s);

if(fp==NULL)

cannotopenfile"

returnNULL;

returnfp;

voidSAVE(structstudent*head)/*保存学生信息*/

FILE*fp;

请选择存储方式:

1,文本文件格式;

2,二进制文件格式\n"

i=getch();

{

请输入你想存储的路径及文件名\n"

charfname[256];

scanf("

fname);

fp=MyOpenFile(fname,"

w"

structstudent*p;

p=head->

while(p!

=NULL)

{

fprintf(fp,"

%s%s%d\n"

/*把学生信息写入文本*/

p=p->

}

fclose(fp);

文本格式文件保存成功\n\n请按任意键返回主菜单\n"

{

fp=MyOpenFile(fname,"

wb"

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2