学生信息管理系统C语言基于链表文件文档格式.docx
《学生信息管理系统C语言基于链表文件文档格式.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统C语言基于链表文件文档格式.docx(20页珍藏版)》请在冰点文库上搜索。
structstudent*FindstudentID(structstudent*head,intfindID);
structstudent*FindstudentName(structstudent*head,charfindname[]);
structstudent*InformationInput(structstudent*head);
voidQueryInformation(structstudent*head);
structstudent*EditInformation(structstudent*head);
structstudent*Insert(structstudent*head,structstudent*p);
voidSave(structstudent*head);
structstudent*Read(structstudent*head);
structstudent*Delete(structstudent*head,intfindID);
structstudent*Add(structstudent*head);
voidHelp();
/************************显示主菜单***************************/
voidDispMainMenu()
printf("
*********************************学生信息管理系统******************************\n"
);
\n"
\t\t\t\t1--信息录入\n"
\t\t\t\t2--信息修改\n"
\t\t\t\t3--信息查询\n"
\t\t\t\t4--保存数据到文件\n"
\t\t\t\t5--打开数据文件\n"
\t\t\t\t6--文件追加\n"
\t\t\t\t7--帮助\n"
\t\t\t\t0--退出\n"
友情提示:
初次使用请先阅读帮助\n"
*******************************************************************************\n"
请选择(0-7):
"
/*显示主菜单*/
}
/*************************************帮助**************************************************/
voidHelp()
\n\t\t\t欢迎进入帮助系统!
\n\n"
\t1.请按照主菜单提示选择所需执行功能的数字代号!
\t2.所有文件请按照规范输入\n"
\t3.刚开始执行程序时若需要文本文件里的数据,请先进行读取文件信息!
\t4.修改信息以后,请切记需要保存!
/***********************显示所有学生信息**********************/
voidDisplayInformation(structstudent*head)
structstudent*p;
*******************************************************************************"
\n学号\t姓名\t年龄\t性别\t电话\t\t地址\t出生年月\temail\n"
p=(structstudent*)malloc(LEN);
p=head;
if(head!
=NULL)
while(p!
{
printf("
%-d\t%-s\t%-d\t"
p->
ID,p->
Name,p->
age);
%-c\t%-s\t%-s\t"
xb,p->
telephone,p->
address);
%-d%d%d"
birthday.year,p->
birthday.month,p->
birthday.day);
\t%-s\n"
email);
p=p->
next;
}
else
printf("
无数据\n"
/**************************查找指定学号的学生信息******************************/
structstudent*FindstudentID(structstudent*head,intfindID)
if(p->
ID==findID)
break;
returnp;
/***************************查找指定姓名的学生信息**********************/
structstudent*FindstudentName(structstudent*head,charfindname[])
if(strcmp(p->
Name,findname)==0)
else
/********************学生信息录入**********************************/
structstudent*InformationInput(structstudent*head)
{
intnumber,i;
\n请输入本次录入的学生人数:
scanf("
%d"
&
number);
for(i=0;
i<
number;
i++)/*输入number个学生的信息*/
{
请输入第%d个学生的学号(八个字符以内):
i+1);
scanf("
p->
ID);
\t\t\t姓名:
\t"
%s"
Name);
\t\t\t年龄:
\t\t\t性别(男M、女W):
xb);
\t\t\t电话(八位):
telephone);
\t\t\t地址:
\t\t\t出生年月:
%d%d%d"
birthday.year,&
birthday.month,&
\t\t\temail:
head=Insert(head,p);
p=(structstudent*)malloc(LEN);
}
\n您的输入信息是:
DisplayInformation(head);
return(head);
/**************************学生信息查询*************************/
voidQueryInformation(structstudent*head)
charselect;
intfindID;
charfindname[8];
*********************请选择查询方式*************************\n"
\t1--按学号查询;
\t2--按姓名查询\n"
************************************************************\n"
请选择(1-2):
/*显示菜单信息*/
select=getche();
getch();
switch(select)
case'
1'
:
\n按学号查询\n请输入学生的学号:
scanf("
findID);
if((p=FindstudentID(head,findID))!
=NULL)/*找到指定学号的学生*/
{
printf("
\n查找结果如下:
%d\t%s\t%d\t"
%c\t%s\t%s\t"
%d%d%d"
\t%s\n"
}
else/*没有找到*/
您输入的学号不存在!
2'
\n按姓名查询\n请输入学生的姓名:
findname);
if((p=FindstudentName(head,findname))!
=NULL)/*找到指定姓名的学生*/
\n学号\t姓名\t年龄\t性别\t电话\t地址\t出生年月\temail\n"
}
您输入的姓名不存在!
default:
选择错误!
/*********************************修改学生信息***********************/
structstudent*EditInformation(structstudent*head)
\n请输入学生的学号:
if((p=FindstudentID(head,findID))!
*********************请修改方式*************************\n"
\t1--修改信息;
\t2--删除信息\n"
select=getche();
getch();
switch(select)
case'
/*修改信息*/
您选择的是修改信息!
姓名:
%s\n"
原信息:
学号:
%d\t年龄:
%d\t性别:
%c\n"
age,p->
\t电话:
%s\t地址:
%s\temail:
address,p->
请输入新信息\n"
学号\t"
scanf("
姓名:
年龄:
性别(男M、女W):
电话:
地址:
出生年月:
email:
break;
/*删除信息*/
您选择的是删除信息!
head=Delete(head,findID);
else/*没有找到学号匹配的记录*/
您输入的学号不存在!
return(head);
/**************************有序插入***************************************/
structstudent*Insert(structstudent*head,structstudent*p)
structstudent*p0,*p1;
if(head==NULL)
head=p;
p->
next=NULL;
return(head);
if(p->
ID<
head->
ID)
next=head;
p1=head;
while((p->
ID>
p1->
ID)&
&
(p1->
next!
=NULL))
p0=p1;
p1=p1->
next=p1;
p0->
next=p;
if(p->
ID==p1->
;
p1->
p->
/*******************************保存数据到文件**************************/
voidSave(structstudent*head)
FILE*fp;
if((fp=fopen(DAT_FILENAME,"
w+"
))!
=NULL)/*以W+的方式打开文件*/
fprintf(fp,"
%d\t"
%s\t"
%c\t"
%d%d%d\t"
p=p->
/*将链表的内容写入文件*/
fclose(fp);
cannotopenfile\n"
/***************************打开数据文件************************/
structstudent*Read(structstudent*head)
r"
/*读取文件中的内容到链表中*/
while(fscanf(fp,"
ID)!
=EOF)
fscanf(fp,"
head=Insert(head,p);
p=(structstudent*)malloc(LEN);
returnhead;
/**************************文件内容追加************************/
structstudent*Add(structstudent*head)
head=Read(head);
head=InformationInput(head);
/**************************删除信息****************************/
structstudent*Delete(structstudent*head,intfindID)
structstudent*pre,*p;
if(head->
p=head;
head=head->
pre=head;
p=pre->
=NULL&
ID!
=findID)
pre=p;
pre->
next=p->
free(p);