- 21
- 0
- 约1.3万字
- 约 8页
- 2016-12-11 发布于贵州
- 举报
//学生信息管理系统
#includeiostream
#includemalloc.h
#includeiomanip
#define NULL 0
#define LEN sizeof(struct student)
//建立动态链表.cpp
using namespace std;
struct student{int num;char name[20];char sex[5];float math;float english;int order;struct student *next;
};
int n;
int male=0;
int famale=0;
struct student *creat(void)
{
struct student *head,*p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
cout下面开始创建链表:endl;
cout学号 姓名 性别 数学 英语 endl;
cinp1-nump1-namep1-sexp1-mathp1-english;
head=NULL;
while(p1-num!=0){if(strcmp(p1-sex,男)==0) male++;else famale++;n++;if(n==1)head=p1;else p2-next=p1;p2=p1;p1=(struct student*)malloc(LEN);cinp1-nump1-namep1-sexp1-mathp1-english;}p2-next=NULL;
if(head==NULL)
{cout创建失败,请重建:endl;head=creat();
}
return head;
}//输出链表的函数
void print(struct student *head)
{
cout此时链表的内容为:endl;
cout学号 姓名 性别 数学 英语 总分endl;
struct student *p;
p=head;
if(head!=NULL)
do
{cout setiosflags(ios_base::left)setw(3)p-numsetw(6)p-namesetw(5)p-sexsetw(5)p-mathsetw(4)p-englishsetw(5)p-math+p-englishresetiosflags(ios_base::left)endl;p=p-next;
}while(p!=NULL);
}
//链表结点的删除操作
struct student *del(struct student *head)
{if(n==0){cout无链表可删除endl;exit(0);}int num;
cout请输入要删除的序号:;
cinnum;
while(num!=0)
{
struct student *p1,*p2;p1=head;while(num!=p1-nump1-next!=NULL){p2=p1;p1=p1-next;}if(num==p1-num){if(p1==head){if(strcmp(p1-sex,男)==0) male--;else famale--;head=p1-next;}else{if(strcmp(p1-sex,男)==0) male--;else famale--;p2-next=p1-next;}coutnum号已被删除endl;n--;}else cout未找到此数据!endl;cout请输入要删除的序号;
cinnum;
}
if(n==0){cout此时链表已为空!endl;exit(0);}
return head;
}//插入结点
struct student *insert(struct student *head)
{
struct student *stu;
stu=(struct student*)malloc(LEN);
cout学号 姓名 性别 数学 英语 endl;
cinstu-numstu-namestu-sexstu-mathstu-english;
while(stu-num!=0)
{
if(strcmp(stu-sex,男)==0) male++;else famale++;
n++;
struct student *p0,*p1,*p2;
p1=head;
p0=stu;
if(head==NULL)
{
head=p0;
p0-next=NULL;
}
else
{
whi
您可能关注的文档
最近下载
- 《摄像与剪辑》课程思政教学案例(一等奖).docx VIP
- 妊娠期高血压饮食妊娠期高血压饮食.doc VIP
- 六年级数学下册 奥数知识点讲解第13课《速算与巧算综合练习1》试题附答案(人教版).doc VIP
- NCCN卵巢癌临床实践指南(2025.V3)解读PPT课件.pptx VIP
- 总经理年终工作总结报告PPT课件.pptx VIP
- 全册单词默写(专项训练)-2025-2026学年沪教牛津版英语七年级下册最新版 可打印.docx VIP
- 黑龙江 2023年统考专业课考试:心理学真题模拟汇编(共637题).doc VIP
- 血气分析仪故障处理.pptx VIP
- 2025中华护理学会团体标准——成人患者医用粘胶相关性皮肤损伤的预防及护理.pptx
- 血气分析仪故障处理流程.pptx VIP
原创力文档

文档评论(0)