学生信息管理系统(简单版)源代码
简单的学生管理,运用链表、指针等
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#define NUll 0
#define LEN sizeof(struct student)
struct student
{
int number;
char name[10];
float score;
struct student *next;
};
/*函数说明*/
struct student * creat(); /*创建链表*/
void print(struct student *head); /*输出学生信息*/
struct student *add(struct student *head); /*添加学生信息*/
struct student * sort(struct student *head); /*对学生信息进行排序*/
struct student * insert(struct student *head); /*插入学生信息*/
struct student * del_num(struct student *head); /*删除学生信息*/
void search(struct student *head); /*查找学生信息*/
struct student * change(struct student *head); /*修改学生信息*/
int n;
int main()
{
int num,x;
char a[5];
struct student *head0,*head,*head1;
head=NUll;
A :
printf(" 学生信息系统 \n");
printf("1.建立链表\n");
printf("2.添加学生\n");
printf("3.插入学生\n");
printf("4.删除学生\n");
printf("5.查找学生\n");
printf("6.修改学生\n");
printf("7.数据浏览\n");
printf("0.退出程序\n");
printf("请选择操作(输入0—7):");
scanf("%d",&num);
switch(num)
{
case 1:
head=creat();
break;
case 2:
head=add(head);
head=sort(head);
print(head);
break;
case 3:
head1=insert(head);
head1=sort(head1);
print(head1);
break;
case 4:
head1=del_num(head);
print(head1);
break;
case 5:
search(head);
break;
case 6:
head1=change(head);
print(head1);
break;
case 7:
print(head);
break;
case 0:
return 0;
default :
printf("输入错误的数字!!请再输一次!\07\n");
}
goto A;
scanf("%d",&x);
return 0;
}
//创建链表
struct student * creat()
{
struct student *head,*p1,*p2;
n=0;
head=(struct student*)malloc(LEN);
if(head!=NULL)
{
printf("空链表已建立!\n");
}
else
{
printf("没有足够的内存空间!\07\n");
}
head->number=0;
strcpy(head->name,"");
head->score=0;
return head;
}
//输出学生信息
void print(struct student *head)
{
struct student *p;
if(head==NULL)
{
printf("未建立链表!!\n");
return;
}
p=head->next;
printf("\n所有学生信息的显示为:\n");
do
{
printf("学号:%d\t姓名:%s\t分数:%.2f\n",p->number,p->name,p->score);
p=p->next;
}while(p!=NUll);
}
//添加学生信息
struct student *add(struct student *head)
{
struct student *p1,*p2;
if(head==NULL)
{
printf("未建立链表!!\n");
retu
rn NULL;
}
p1=head;
while(1)
{
p2=(struct student *)malloc(LEN);
if(p2==NULL)
{
printf("没有足够的空间!\07\n");
return 0;
}
print
简单的学生管理,运用链表、指针等
f("学号(输入0结束):");
scanf("%d",&p2->number);
if(p2->number==0)
{
break;
}
printf("姓名:");
scanf("%s",&p2->name);
printf("分数:");
scanf("%f",&p2->score);
n=n+1;
//p2->next=NULL;
p1->next=p2;
p1=p2;
}
p1->next=NULL;
return head;
}
//对学生信息进行排序
struct student * sort(struct student *head)
{
int t1;
float t2;
struct student *p1,*p2;
if(head==NULL)
{
printf("未建立链表!!\n");
return NULL;
}
p1=head;
p2=head->next;
for(int i=1;i<n;i++)
{
p1=head->next;
p2=p1->next;
do
{
if((p1->number)<(p2->number))
{
t1=p1->number;
t2=p1->score;
p1->number=p2->number;
p1->score=p2->score;
p2->number=t1;
p2->score=t2;
}
p2=p1;
p1=p1->next;
}while(p1!=NULL);
}
printf("自动排序……");
return head;
}
//插入学生信息
struct student * insert(struct student *head)
{
struct student *p1,*p2,*stu;
if(head==NULL)
{
printf("未建立链表!!\n");
return NULL;
}
while(1)
{
p1=head->next;
p2=p1;
stu=(struct student *)malloc(LEN);
if(stu==NULL)
{
printf("没有足够的空间!\07\n");
return 0;
}
printf("\n学号(输入0结束):");
scanf("%d",&stu->number);
if(stu->number==0)
{
break;
}
printf("姓名:");
scanf("%s",&stu->name);
printf("分数:");
scanf("%f",&stu->score);
n=n+1;
if(stu->number<p1->number)
{
stu->next=p1;
head->next=stu;
}
else
{
while((stu->number)>(p1->number)&&p1!=NULL)
{
p2=p1;
p1=p1->next;
}
if((stu->number)<=(p1->number))
{
p2->next=stu;
stu->next=p1;
}
else
{
p1=stu;
stu->next=NULL;
}
}
}
return head;
}
//删除学生信息
struct student * del_num(struct student *head)
{
struct student *p1,*p2;
if(head==NULL)
{
printf("未建立
…… 此处隐藏:2706字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [教育文库]夜场KTV服务员的岗位职责及工作流程[1]
- [教育文库]企划、网络、市场绩效考核方案
- [教育文库]学党史、知党情、强党性--“党的基本理
- [教育文库]2016年高考物理大一轮总复习(江苏专版
- [教育文库]干部廉洁自律自查自纠的报告
- [教育文库]2010年北京大学心理学系拟录取硕士研究
- [教育文库]资金时间价值练习题及答案
- [教育文库]保护环境的心得体会
- [教育文库]英语角内容:英语趣味小知识
- [教育文库]档案收集与管理工作通知
- [教育文库]劳动规章制度范本范本
- [教育文库]高考物理一轮复习课后限时作业1运动的
- [教育文库]机械工艺夹具毕业设计195推动架设计说
- [教育文库]通用技术教学比赛说课稿2
- [教育文库]2018年四年级英语下册 Module 7 Unit 2
- [教育文库]第2章 宽带IP网络的体系结构
- [教育文库]九年级化学第五单元课题3《根据化学方
- [教育文库]小学英语六年级情态动词用法归纳
- [教育文库]甲级单位编制窑井盖项目可行性报告(立
- [教育文库]2016-2021年中国城市规划行业全景调研
- 高考英语听力十大场景词汇总结
- 全省领导班子思想政治建设座谈会会议精
- 人教版新课标高一英语提优竞赛试题 下
- 江西省2014年生物中考试题
- 长沙镇食品药品安全事故应急预案
- 《金刚石、石墨和C60》片段教学设计
- 福州教育学院(王旭东)
- 基于EDA音乐播放器的设计
- 9、古诗两首《夜书所见》《九月九日忆
- 小学语文课外阅读有效策略探讨
- 贵州文化产业发展成支柱产业的问卷调查
- 膀胱类癌的诊治体会(附3例报告)
- 发动机积碳产生的原因
- Configuring Code Composer Studio for
- 学生良好的心理素质如何培养点滴谈
- 46 电沉积法制备锂离子电池用硅-锂薄膜
- 美舍雅阁公司管理中各部门职责
- 去壳剥皮的小妙招
- 六自由度运动平台的仿真研究
- Pride and Prejudice(傲慢与偏见)




