C语言学生信息管理系统实验报告Word文件下载.docx
《C语言学生信息管理系统实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《C语言学生信息管理系统实验报告Word文件下载.docx(28页珍藏版)》请在冰豆网上搜索。
2.2.1、函数功能:
voidMenu_1();
//主菜单
voidMenu_2();
//二级菜单
voidswap(structstudent*phead,structstudent*pback);
//链表节点互换
voidSave(structstudent*head);
//写入磁盘
voidSearch(structstudent*head);
//查找学生信息
voidRead(structstudent*head);
//显示学生信息
voidSort(structstudent*head);
//链表节点排序
structstudent*Create();
//学生信息手动录入
structstudent*Readpoint();
//磁盘文件写入内存
structstudent*Modify(structstudent*head);
//链表结构体成员修改
structstudent*Add(structstudent*head);
//链表节点插入
structstudent*Delete(structstudent*head);
//链表节点删除
2.2.2、函数之间的调用关系:
通过switch语句进行指令选择:
case1:
学生信息录入
调用函数Create()、Save()、Menu_1()、Menu_2()
case2:
学生信息浏览
调用函数Readpoint()、Sort()、Read()、Save()、Menu_1()、Menu_2()
case3:
学生信息查找
调用函数Search()、Readpoint()、Menu_1()、Menu_2()
case4:
学生信息修改
调用函数Modify()、Readpoint()、Save()、Menu_1()、Menu_2()
case5:
学生信息增加
调用函数Add()、Readpoint()、Save()、Menu_1()、Menu_2()
case6:
学生信息删除
调用函数Delete()、Readpoint()Save()、Menu_1()、Menu_2()
case0:
返回主菜单
调用函数Menu_1()
第三章、代码(源代码)
/*
学生信息管理系统
*/
#include<
stdio.h>
stdlib.h>
string.h>
structstudent//定义结构体
{
intnum;
charname[24];
charsex[5];
intChinese;
intMath;
intEnglish;
structstudent*next;
};
//链表节点互换
//学生信息手动录入
//链表结构体成员修改
intmain(void)
Menu_1();
return0;
}
voidMenu_1()
printf("
\t\t\t\t学生信息管理系统\t\t\t\t\n"
);
\t\t\t1:
进入学生信息管理\n"
\t\t\t0:
退出学生信息管理\n"
请您输入指令:
"
scanf("
%d"
&
num);
switch(num)
{case1:
Menu_2();
break;
default:
printf("
-----------------------------------------您已退出学生信息管理系统-----------------------------------------------\n"
break;
}
/*------------------------------------------------------------------------------------------------------------------------------------*/
voidMenu_2()
{
structstudent*head;
intnum;
\t\t\t欢迎进入\n"
-----------------------------------------------------------------------------------------------------------------------\n"
学生信息录入\n"
\t\t\t2:
学生信息浏览\n"
\t\t\t3:
学生信息查找\n"
\t\t\t4:
学生信息修改\n"
\t\t\t5:
学生信息增加\n"
\t\t\t6:
学生信息删除\n"
返回主菜单\n"
------------------------------------------------------------------------------------------------------------------------\n"
scanf("
switch(num)
head=Create();
Save(head);
\n"
//手动录入学生数据
返回二级菜单\n"
{
case1:
Menu_1();
case2:
default:
{
printf("
输入无效,返回二级菜单!
Menu_2();
}
head=Readpoint();
//写入链表,返回头指针
Sort(head);
\t\t\t以学号升序排列\n"
Read(head);
//链表数据写入文件
Search(head);
//查找学生信息
返回主菜单\n"
返回二级菜单\n"
Modify(head);
//修改结构体成员并保存到文件
Add(head);
//增加学生信息并保存到文件
head=Delete(head);
//删除学生信息并保存到文件
default:
请重新输入\n"
Menu_2();
/*---------------------------------------------------------------------------------------------------------------------------------------*/
structstudent*Create()//学生信息手动录入
structstudent*head,*p,*q;
intn;
p=q=(structstudent*)malloc(sizeof(structstudent));
请输入学生的姓名、学号、性别、语文成绩、高等数学成绩、英语成绩:
%s"
q->
name);
%d%s%d%d%d"
q->
num,&
sex,&
Chinese,&
Math,&
English);
n=0;
head=NULL;
while(q->
num!
=0)
n=n+1;
if(n==1)
head=q;
else
p->
next=q;
p=q;
q=(structstudent*)malloc(sizeof(structstudent));
scanf("
num,q->
p->
next=NULL;
学生信息录入成功!
returnhead;
/*----------------------------------------------------------------------------------------------------------------------------------------*/
structstudent*Readpoint()//学生信息写入内存,便于操作
FILE*fp1;
if((fp1=fopen("
E:
test.txt"
"
rb"
))==NULL)
printf("
openfileerror!
exit(0);
fscanf(fp1,"
%s%d%s%d%d%d"
name,&
while(!
feof(fp1))
fscanf(fp1,"
fclose(fp1);
voidSwap(structstudent*phead,structstudent*pback)//链表元素数据交换
structstudent*temp=(structstudent*)malloc(sizeof(structstudent));
strcpy(temp->
name,phead->
temp->
num=phead->
num;
sex,phead->
sex);
Chinese=phead->
Chinese;
Math=phead->
Math;
English=phead->
English;
strcpy(phead->
name,pback->
phead->
num=pback->
sex,pback->
Chinese=pback->
Math=pback->
English=pback->
strcpy(pback->
name,temp->
pback->
num=temp->
sex,temp->
Chinese=temp->
Math=temp->
English=temp->
free(temp);
voidSort(structstudent*head)//学号排序
structstudent*phead=(structstudent*)malloc(sizeof(structstudent));
structstudent*pback=(structstudent*)malloc(sizeof(structstudent));
phead=head;
while(phead)
intNum=phead->
pback=phead->
next;
while(pback)
if(Num>
num)
{
Swap(phead,pback);
Num=phead->
}
pback=pback->
phead=phead->
voidRead(structstudent*head)//学生信息读取
structstudent*p;
p=head;
学生的姓名、学号、性别、语文成绩、高等数学成绩、英语成绩:
while(p!
=NULL)
%s\t%d\t%s\t%d\t%d\t\t%d\n"
p->
name,p->
num,p->
sex,p->
Chinese,p->
Math,p->
p=p->
-----------------------------------------------------------------------------------