C语言之学生管理系统Word文档下载推荐.docx
《C语言之学生管理系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C语言之学生管理系统Word文档下载推荐.docx(14页珍藏版)》请在冰点文库上搜索。
//查询学生信息
voidquery_by_num();
//按学号查询学生信息
voidquery_by_name();
voidreadData();
//读取文件里学生的信息
voidwriteData();
//向文件写入学生信息
voidfreeAll();
//清空链表内容
voiddel();
//删除学生信息
voidchange();
//更改学生信息
voidsort();
//排序
voiddevise(structstudent*p);
//选择更改内容
intmain(void)
mainmenu();
return0;
}
//系统主菜单
voidmainmenu()
intchoice;
choice=-1;
readData();
printf("
\t\t\t----------------------------------------------------\n"
);
\t\t\t|欢迎使用通信工程专业学生信息管理系统|\n"
\t\t\t本程序需要在当前目录下建立student.txt才可正常运行\n"
do
{
printf("
\n\n\n"
\t\t\t--------------------------------------------\n"
\t\t\t通信工程专业学生信息管理系统|\n"
\t\t\t[1]----录入学生信息|\n"
\t\t\t[2]----浏览学生信息|\n"
\t\t\t[3]----查询学生信息|\n"
\t\t\t[4]----删除学生信息|\n"
\t\t\t[5]----修改学生信息|\n"
\t\t\t[6]----排序|\n"
\t\t\t[0]----退出系统|\n"
请输入您的选择"
scanf("
%d"
&
choice);
switch(choice)
{
case0:
writeData();
freeAll();
exit(0);
case1:
record();
break;
case2:
displayAll();
case3:
query();
case4:
del();
case5:
change();
case6:
sort();
default:
printf("
\n无效选项!
"
}
}while(choice!
=0);
}
//录入学生信息
voidrecord()
structstudent*p0;
p0=(structstudent*)malloc(LEN);
\t\t\t请输入学生的姓名:
scanf("
%s"
p0->
name);
\t\t\t请输入学生的学号:
%ld"
&
p0->
num);
\t\t\t请输入学生的性别:
sex);
\t\t\t请输入学生的年龄:
age);
\t\t\t请输入学生的地址:
address);
\t\t\t请输入学生的成绩:
%f"
score);
insert(p0);
\t\t\t该学生的信息为:
\n"
\t\t\t-------------------------------------------------------------------------------\n"
\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n"
display(p0);
voidinsert(structstudent*stu)
structstudent*p0,*p1,*p2;
p1=head;
p0=stu;
if(head==NULL)
head=p0;
p0->
next=NULL;
else
while((p0->
num>
p1->
num)&
&
(p1->
next!
=NULL))
p2=p1;
p1=p1->
next;
}
if(p0->
num<
=p1->
num)
if(head==p1)
head=p0;
else
p2->
next=p0;
p0->
next=p1;
p1->
TOTAL_NUM++;
voiddisplay(structstudent*p)
\t\t\t%s\t%ld\t\t%d\t%s\t%s\t\t%f\n"
p->
name,p->
num,p->
age,p->
sex,p->
address,p->
//浏览学生信息
voiddisplayAll()
structstudent*p;
printf("
\t\t\t学生总数:
%d\n"
TOTAL_NUM);
p=head;
if(head!
=NULL)
printf("
do
display(p);
p=p->
}
while(p!
=NULL);
voidquery()
--------------------\n"
|按学号查询请按1|\n"
|按姓名查询请按2|\n"
|取消请按0|\n"
+--------------------+\n"
scanf("
switch(choice)
return;
query_by_num();
query_by_name();
printf("
while(choice!
//按姓名查询学生信息
voidquery_by_name()
structstudent*p1;
请输入学生的姓名"
scanf("
name);
if(head==NULL)
{printf("
无学生记录\n"
return;
p1=head;
while(strcmp(name,p1->
name)&
next!
=NULL)
p1=p1->
if(!
strcmp(name,p1->
name))
display(p1);
没有该学生记录请核对"
//按学号查询学生信息
voidquery_by_num()
intnum;
请输入学生的学号"
无学生记录\n"
return;
while(num!
=p1->
num&
p1=p1->
if(num==p1->
{
display(p1);
\t\t\t没有该学生记录请核对"
//写入文件
voidwriteData()
FILE*fp;
//文件指针
fp=fopen("
1.txt"
"
w"
if(!
fp)
文件打开错误"
fprintf(fp,"
for(p=head;
p!
=NULL;
p=p->
next)
fprintf(fp,"
%s\t%ld\t%s\t%d\t%s\t%f\n"
sex,p->
fclose(fp);
}
voidfreeAll()
structstudent*p1,*p2;
p1=p2=head;
while(p1)
p2=p1->
free(p1);
p1=p2;
}//读取文件
voidreadData()
student.txt"
r"
if(!
文件打开错误"
fscanf(fp,"
TOTAL_NUM);
head=p1=p2=(structstudent*)malloc(LEN);
p1->
name,&
p1->
num,p1->
sex,&
age,p1->
address,&
while(!
feof(fp))
p1=(structstudent*)malloc(LEN);
fscanf(fp,"
sex,&
p2->
p2=p1;
p2->
fclose(fp);
//删除学生信息
voiddel()
请输入您要删除的学生的学号"
scanf("
p1=head;
while(num!
p2=p1;
p1=p1->
if(num==p1->
if(p1==head)
head=p1->
next=p1->
free(p1);
TOTAL_NUM--;
else
没有该学生记录请核对\n"
voidsort()//排序模块。
将学生记录按学号从小到大排列。
用起泡排序算法实现
{
inti;
structstudent*ptr,*s=head,*p;
intcount=0,count1;
while(s)//统计链表结点个数
count++;
s=s->
}
for(i=1;
i<
count;
i++)
ptr=head;
p=NULL;
count1=count-i;
//用来控制每轮起泡排序的终点即每次把学号最小的结点移到倒数第i个结点
while(ptr&
ptr->
next&
(count1--))
{
if(ptr->
score>
next->
score)
{
s=ptr->
ptr->
next=s->
if(p==NULL)//ptr处于队头时
head=s;
else
p->
next=s;
s->
next=ptr;
p=s;
}
else
ptr=ptr->
p=head;
p=p->
}
displayAll();
voidchange()
请输入您要修改的学生的学号"
scanf("
while(num!
if(num==p1->
devise(p1);
voiddevise(structstudent*p)
请选择您要修改的学生的信息内容\n"
+----------------------+\n"
|姓名请按1|\n"
|学号请按2|\n"
|性别请按3|\n"
|年龄请按4|\n"
|地址请按5|\n"
|爱好请按6|\n"
请输入新姓名"
请输入新学号"
p->
请输入新性别"
请输入新年龄"
请输入新地址"
请输入新成绩"
}