双链表课程设计学生信息管理系统.docx

上传人:b****5 文档编号:8319429 上传时间:2023-01-30 格式:DOCX 页数:25 大小:19.77KB
下载 相关 举报
双链表课程设计学生信息管理系统.docx_第1页
第1页 / 共25页
双链表课程设计学生信息管理系统.docx_第2页
第2页 / 共25页
双链表课程设计学生信息管理系统.docx_第3页
第3页 / 共25页
双链表课程设计学生信息管理系统.docx_第4页
第4页 / 共25页
双链表课程设计学生信息管理系统.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

双链表课程设计学生信息管理系统.docx

《双链表课程设计学生信息管理系统.docx》由会员分享,可在线阅读,更多相关《双链表课程设计学生信息管理系统.docx(25页珍藏版)》请在冰豆网上搜索。

双链表课程设计学生信息管理系统.docx

双链表课程设计学生信息管理系统

#include

#include

#include

#include

#defineLENsizeof(EB)//头文件声明

typedefstructeducation_background{

charname[8];//姓名[字符串格式]

charnum[8];//学号[字符串格式]

charID[18];//身份证号[字符串格式]

charsex[4];//性别[字符格式]

charbirth[10];

charNP[10];//nativeplace籍贯

structeducation_background*prior;//前节点

structeducation_background*next;//后节点

}EB;//链表内容描述

voidmenu()

{

system("color2f");

printf("\t\t╭──────────────────╮\n");

printf("\t\t│╭────────────────╮│\n");

printf("\t\t││││\n");

printf("\t\t││\t欢迎进入学籍信息管理系统││\n");

printf("\t\t││││\n");

printf("\t\t││\t0\t初始化信息││\n");

printf("\t\t││\t1\t插入学生信息││\n");

printf("\t\t││\t2\t查找学生信息││\n");

printf("\t\t││\t3\t修改学生信息││\n");

printf("\t\t││\t4\t删除学生信息││\n");

printf("\t\t││\t5\t显示学生信息││\n");

printf("\t\t││\t6\t学生信息排序││\n");

printf("\t\t││\t7\t退出系统││\n");

printf("\t\t││请选择[1]\\[2]\\[3]\\[4]\\[5]\\[6]\\[7]││\n");

printf("\t\t│╰─────────────────╯│\n");

printf("\t\t╰───────────────────╯");

}//菜单说明

EB*info_Lead()

{intlen=0;

EB*head,*p1,*p2;

FILE*fp;head=NULL;

fp=fopen("file.dat","r");

if(fp==NULL)

{printf("不能打开文件按任意键退出!

");

getchar();

exit

(1);

}

p1=p2=(EB*)malloc(LEN);

fscanf(fp,"%s\n%s\n%s\n%s\n%s\n%s",p1->name,p1->num,p1->ID,p1->sex,p1->birth,p1->NP);

while(!

feof(fp))

{len++;

if(len==1){head=p1;head->prior=NULL;}

else{

p2->next=p1;

p1->prior=p2;

}

p2=p1;

p1=(EB*)malloc(LEN);

fscanf(fp,"%s\n%s\n%s\n%s\n%s\n%s",p1->name,p1->num,p1->ID,p1->sex,p1->birth,p1->NP);

}

p2->next=NULL;

free(p1);

fclose(fp);

returnhead;

}

//导入信息函数

voidinfoprint(EB*p)

{

printf("\t│%-8s",p->name);

printf("│%-8s",p->num);

printf("│%-18s",p->ID);

printf("│%-4s",p->sex);

printf("│%-10s",p->birth);

printf("│%-10s\n",p->NP);

}//打印学生信息函数

voidINPUT(EB*p)

{

printf("输入姓名:

");

scanf("%s",p->name);

printf("输入学号:

");

scanf("%s",p->num);

printf("输入身份证号:

");

scanf("%s",p->ID);

printf("输入性别:

");

scanf("%s",p->sex);

printf("输入生日:

");

scanf("%s",p->birth);

printf("输入籍贯:

");

scanf("%s",p->NP);printf("\n");

}//输入学生信息函数

voiddisplay(EB*head)

{intn=0;

EB*p=head;

if(p==NULL)

{

printf("文件中没有信息按任意键返回!

");

getchar();

exit(0);

}

else

{printf("\n\t\t\t\t打印结果如下\n");

printf("\n-----------------------------------------------------------------------------");

printf("\n记录│姓名\t│学号│身份证号│性别│生日│籍贯\n");

printf("-----------------------------------------------------------------------------\n");

do{

n++;

printf("data%d",n);

infoprint(p);

printf("-----------------------------------------------------------------------------\n");

p=p->next;

}while(p!

=NULL);

}

}//显示所有学生信息函数

voidsave(EB*head)

{EB*p=head;

FILE*fp;

fp=fopen("file.dat","w");

if(fp==NULL)

{

printf("不能打开文件按任意键退出!

");

getchar();

exit

(1);

}

else

while(p!

=NULL)

{

fprintf(fp,"%s\n",p->name);

fprintf(fp,"%s\n",p->num);

fprintf(fp,"%s\n",p->ID);

fprintf(fp,"%s\n",p->sex);

fprintf(fp,"%s\n",p->birth);

fprintf(fp,"%s\n",p->NP);

p=p->next;

}

fclose(fp);

printf("\t\t\t成功保存\n");

}//文件保存函数

EB*creat_dlist(int*len)

{intm=1,n;

EB*head,*p1,*p2;

*len=0;

head=NULL;

printf("\n\t\t输入初始信息\n");

printf("\t\t你想输入多少信息\n\t\t数量:

");

scanf("%d",&n);

p1=p2=(EB*)malloc(LEN);

printf("数据1\n");

INPUT(p1);

do

{

(*len)++;

if((*len)==1){head=p1;head->prior=NULL;}

else{

p2->next=p1;

p1->prior=p2;

}

p2=p1;

p1=(EB*)malloc(LEN);

if(m==n)

break;

printf("数据%d\n",++m);

INPUT(p1);

}while(*len

p2->next=NULL;

free(p1);

returnhead;

}//双向链表创建函数

voidcopy(EB*p,EB*q){

strcpy(p->name,q->name);

strcpy(p->num,q->num);

strcpy(p->ID,q->ID);

strcpy(p->sex,q->sex);

strcpy(p->birth,q->birth);

strcpy(p->NP,q->NP);

}//复制学生信息函数且P中的数据被覆盖

voidexchange(EB*p,EB*q){

charu[10],v[20],w[20],x[10],y[10],z[30];

strcpy(u,p->name);

strcpy(v,p->num);

strcpy(w,p->ID);

strcpy(x,p->sex);

strcpy(y,p->birth);

strcpy(z,p->NP);

copy(p,q);

strcpy(q->name,u);

strcpy(q->num,v);

strcpy(q->ID,w);

strcpy(p->sex,x);

strcpy(p->birth,y);

strcpy(q->NP,z);

}//交换学生信息函数

EB*insert(EB*head,EB*q,intn,int*len)/*p表示头结点q(前后指针没有初始化)表示需要插入的数据n表示插入的位置len表示链表的长度*/

{inti;

EB*p=head;

q->prior=q->next=NULL;

if(n==0){

q->next=p;

p->prior=q;

(*len)++;

returnq;

}

else

if(n==*len){

p=head;

for(i=0;i

p=p->next;

p->next=q;

q->prior=p;

(*len)++;

returnhead;

}

else

if(n>=1||n<=*len-1){

p=head;

for(i=0;i

p=p->next;

q->prior=p;

q->next=p->next;

(p->next)->prior=q;

p->next=q;

(*len)++;

returnhead;

}

elseprintf("你的要求不能实现请检查!

");

exit(0);}//插入学生信息函数

voidmodify(EB*p)//修改操作

{charc;

printf("修改姓名?

\tY\\yorN\\n\t你的选择:

");

getchar();c=getchar();system("cls");

if(c=='Y'||c=='y')

{

printf("姓名(MF):

");

scanf("%s",p->name);

}system("cls");

printf("修改学号?

\tY\\yorN\\n\t你的选择:

");

getchar();c=getchar();system("cls");

if(c=='Y'||c=='y')

{

printf("学号(MF):

");

scanf("%s",p->num);

}system("cls");

printf("修改身份证号?

\tY\\yorN\\n\t你的选择:

");

getchar();c=getchar();system("cls");

if(c=='Y'||c=='y')

{

printf("身份证号(MF):

");

scanf("%s",p->ID);

}system("cls");

printf("修改性别?

\tY\\yorN\\n\t你的选择:

");

getchar();c=getchar();system("cls");

if(c=='Y'||c=='y')

{

printf("性别(MF):

");

scanf("%s",p->sex);system("cls");

}

printf("修改生日?

\tY\\yorN\\n\t你的选择:

");

getchar();c=getchar();system("cls");

if(c=='Y'||c=='y')

{

printf("生日(MF):

");

scanf("%s",p->birth);system("cls");

}

printf("修改籍贯?

\tY\\yorN\\n\t你的选择:

");

getchar();c=getchar();system("cls");

if(c=='Y'||c=='y')

{

printf("籍贯(MF):

");

scanf("%s",p->NP);

}getchar();

}//修改学生信息函数

EB*namesort(EB*head)

{intm=0,n=0;charc;

EB*p1,*p2,*q1,*q2,*headq;

p2=p1=head;

if(p1->next==NULL)

{

returnhead;

printf("\n不需要排序按任意键退出");

getchar();

exit(0);

}

printf("排序方式\tU\\uorD\\d\t");

c=getchar();getchar();

if(c=='U'||c=='u')

m=-1;

else

if(c=='D'||c=='d')

m=1;

else

{

printf("\n输入有误按任意键退出!

");

getchar();

exit(0);

}

q1=q2=(EB*)malloc(LEN);

while(p1!

=NULL)

{copy(q1,p2);

n++;

if(n==1)headq=q1;

else{

q2->next=q1;

q1->prior=q2;

}

if(strcmp(q1->name,q2->name)==m)

exchange(q1,q2);

q2=q1;

p1=p1->next;

p2->next=NULL;

free(p2);

p2=p1;

q1=(EB*)malloc(LEN);

}

q2->next=NULL;

returnheadq;

}//姓名排序

EB*student_numbersort(EB*head)

{intm=0,n=0;charc;

EB*p1,*p2,*q1,*q2,*headq;

p2=p1=head;

if(p1->next==NULL)

{

printf("\n不需要排序按任意键退出!

");

getchar();

exit(0);

}

printf("wayofsort\tU\\uorD\\d\t");

getchar();c=getchar();

if(c=='U'||c=='u')

m=-1;

else

if(c=='D'||c=='d')

m=1;

else

{

printf("\n输入有误按任意键退出!

");

getchar();

exit(0);

}

q1=q2=(EB*)malloc(LEN);

while(p1!

=NULL)

{copy(q1,p2);

n++;

if(n==1)headq=q1;

else{

q2->next=q1;

q1->prior=q2;

}

if(strcmp(q1->name,q2->name)==m)

exchange(q1,q2);

q2=q1;

p1=p1->next;

p2->next=NULL;

free(p2);

p2=p1;

q1=(EB*)malloc(LEN);

}

q2->next=NULL;

returnheadq;

}//学号排序

EB*sort(EB*head)

{

charc;

EB*p;system("cls");

printf("\t\t\t╭────────╮");

printf("\n\t\t\t│1\t根据姓名排序│\n");

printf("\t\t\t│2\t根据学号排序│\n");

printf("\t\t\t│\t请选择[1\\2]│\n");

printf("\t\t\t╰─────────╯");

printf("\n\t\t\t你的选择\t:

");

c=getchar();getchar();

switch(c)

{

case'1':

p=namesort(head);

returnp;

break;

case'2':

p=student_numbersort(head);

returnp;

break;

default:

printf("输入有误按任意键返回!

");

returnhead;

getchar();

break;

}

}//排序总函数

EB*IDsearch(EB*head,char*s)

{

EB*p=head;

intf=1;

if(p==NULL)

{

printf("\n文件中没有信息按任意键退出!

\n");

getchar();

exit(0);

}

while(p!

=NULL)

{

if(strcmp(p->ID,s)==0)

{

infoprint(p);

f=-1;

returnp;

}

else

p=p->next;

}

if(f)

{

printf("nofound");

returnNULL;

}exit(0);

}//身份证查找函数

EB*birthsearch(EB*head,char*s){

charc,r[30];

EB*p,*q;p=head;

if(p==NULL)

{

printf("\n文件中没有信息按任意键退出!

\n");

getchar();

exit(0);

}

else

printf("所有生日是[%s]的学生如下:

\n",s);

while(p!

=NULL)

{

if(strcmp(p->birth,s)==0)

{

printf("姓名\t\t:

%s\n",p->name);

printf("身份证号\t\t:

%s\n\n\n",p->ID);

}

p=p->next;

}

printf("是否想精确查找?

\tY\\yorN\\n\t你的选择:

");//进一步身份证精确查找

getchar();c=getchar();printf("\n");

switch(c)

{

case'Y':

case'y':

printf("输入你想查询学生身份证号:

\n");

scanf("%s",r);

system("cls");

getchar();

q=IDsearch(head,r);

returnq;

break;

case'N':

case'n':

returnNULL;

break;

default:

returnNULL;

printf("输入错误按任意键退出!

");

getchar();exit(0);

}

}//出生年月查找函数分函数

EB*namesearch(EB*head,char*s){

charc,r[30];

EB*p,*q;p=head;

if(p==NULL)

{

printf("\n文件中没有信息按任意键退出!

\n");

getchar();

exit(0);

}

else

printf("所有姓名是[%s]的学生如下:

\n",s);

while(p!

=NULL)

{

if(strcmp(p->name,s)==0)

{

printf("\n\t\t身份证号\t\t:

%s\n",p->ID);

printf("\t\t籍贯\t\t:

%s",p->NP);

}

p=p->next;

}

printf("\n\n是否想精确查找?

\tY\\yorN\\n\t你的选择:

");//进一步身份证精确查找

getchar();c=getchar();printf("\n");

switch(c)

{

case'Y':

case'y':

printf("输入你想查询学生身份证号:

\n");

scanf("%s",r);

system("cls");

getchar();

q=IDsearch(head,r);

returnq;

break;

case'N':

case'n':

returnNULL;

break;

default:

returnNULL;

printf("错误输入按任意键退出!

");

getchar();exit(0);

}

}//姓名查找函数分函数

EB*sexsearch(EB*head,char*s){

charc,r[30];

EB*p,*q;p=head;

if(p==NULL)

{

printf("\

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

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1