用二叉树来实现学生健康情况管理系统.doc_第1页
用二叉树来实现学生健康情况管理系统.doc_第2页
用二叉树来实现学生健康情况管理系统.doc_第3页
用二叉树来实现学生健康情况管理系统.doc_第4页
用二叉树来实现学生健康情况管理系统.doc_第5页
免费预览已结束,剩余9页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【综设实验题目】 实现学生健康情况管理的几个操作功能(新建、插入、删除、从文件读取、写入文件和查询、屏幕输出等功能)。健康表中学生的信息有学号、姓名、出生日期、性别、身体状况等。实验内容1利用二叉树来实现2系统的菜单功能项如下:1-新建学生健康表2-向学生健康表插入学生信息3-在健康表删除学生信息4-从文件中读取健康表信息5-向文件写入学生健康表信息6-在健康表中查询学生信息(按学生学号来进行查找)7-在屏幕中输出全部学生信息8-退出【中文摘要】 这次实验主要用二叉树来实现简单的学生健康管理系统,为了方便查找,进一步使用排序二叉树来实现。系统的功能包括:向学生健康表插入学生信息,在健康表删除学生信息,从文件中读取健康表信息,向文件写入学生健康表信息,在健康表中查询学生信息(按学生学号来进行查找),在屏幕中输出全部学生信息等。健康表中学生的信息有学号、姓名、出生日期、性别、身体状况等。【关键词 】 排序二叉树 学生健康管理系统 学生信息【前言】本次实验是为了进一步熟悉和掌握VC环境下的编译、调试和执行的方法及步骤,熟悉二叉树存储的实现方式及其应用。【实验设计】 以排序二叉树为储存机制,可以方便的实现插入或删除学生信息。每个学生的信息储存在一个结构体Sstudent中,并且这个结构体带有输出学生信息的函数ouput()。然后以这个结构体作为二叉树节点的数据类型,这样就实现了学生信息的储存。在创建二叉树对象时将已存储在文件中的学生信息写入二叉树,在析构函数里实现将学生信息写入文件。【实验实现】 软件平台:VC+ 6.0硬件平台:32位机器主要功能模块分析:1、储存一个学生的信息:/*Sstudent.h 文件*/#ifndef _Sstudent_h_#define _Sstudent_h_#include using namespace std;struct birthday /出生日期unsigned short day; unsigned short month; unsigned short year; ;struct Sstudent /一个学生的基本信息char number12; /学号 char name12; /名字struct birthday bd; /出生日期char gender4; /性别char healthcase10; /健康情况Sstudent() void input(); /输入学生的基本信息void output(); /输出学生的基本信息void operator =(Sstudent s);bool operator (Sstudent &s); ;void Sstudent:input() /输入一个学生的信息cout请输入学生信息:endl;coutnumber;coutname;coutgender;coutbd.yearbd.monthbd.day;couthealthcase;coutendl;void Sstudent:output() /输出一个学生的信息cout学号: numberendl 姓名: nameendl性别: genderendl生日: bd.year/bd.month/bd.dayendl健康情况: healthcaseendlendl;void Sstudent:operator =(Sstudent s)strcpy(number,s.number);strcpy(name,);strcpy(gender,s.gender);bd.year=s.bd.year;bd.month=s.bd.month;bd.day=s.bd.day;strcpy(healthcase,s.healthcase);bool Sstudent:operator (Sstudent &s)if(strcmp(number,s.number) = 1) /若number 大于 s.numberreturn true; elsereturn false;#endif2、将文件中的学生健康信息写进排序二叉树BSTree:BSTree()root=NULL;BTreeNode *b=NULL;Sstudent s;fstream file;file.open(student.dat,ios:in|ios:binary);if(!file)cerrstudent.dat cant open!data); /调用插入函数建二叉树file.close();3、将排序二叉树中的学生信息写进文件思想:在退出程序调用析构函数时,通过前序遍历,将访问到的节点信息依次写进文件。BSTree:BSTree()fstream file;file.open(student.dat,ios:out|ios:binary);if(!file)cerrstudent.dat cant open!=0) while(p!=NULL)write1(file,p);stacktop+=p;p=p-lchild;top-;p=stacktop;if(p!=NULL)p=p-rchild; coutendl;void write1(fstream &outfile, BTreeNode *p) /将节点p写进文件流if(p=NULL)coutp=NULLdata), sizeof(p-data) );4、向学生健康表插入学生信息/具有插入功能的查找(递归)void BSTree:inst(BTreeNode *p,BTreeNode *&bst) if (bst=NULL) bst=p;else if (p-data data ) inst(p,bst-lchild); else inst(p,bst-rchild);/*功能:在当前的排序二叉树上查找关键字等于给定值el的结点,当查找成功时输出相应的信息,否则建立一个新结点并插入在当前排序二叉树的适当位置中。*/void BSTree:inst(Sstudent el) BTreeNode *p;p = sear(el.number);if (p != NULL ) cout已找到 data.number);if(k = -1) pfather=p;p=p-lchild;else if(k = 1) pfather=p;p=p-rchild;elsebreak;if (p = NULL ) cout找不到该同学信息,删除失败!lchild!=NULL & p-rchild!=NULL) /结点左右儿子都存在 BTreeNode *tmp = p-rchild;while(tmp-lchild)tmp = tmp-lchild;p-data = tmp-data;p-rchild = deleteNode(p-rchild,tmp-data.number);else /只有一个儿子或没有儿子的情况if(p-lchild = NULL)if(p = pfather-lchild) /p是左子节点pfather-lchild = p-rchild; elsepfather-rchild = p-rchild; else if(p-rchild = NULL)if(p = pfather-lchild) /p是左子节点pfather-lchild = p-lchild; elsepfather-rchild = p-lchild; p-data.output(); return p;/实例函数BTreeNode * BSTree:deleteNode(char num) BTreeNode *p=root;return deleteNode(p,num);6、在屏幕中输出全部学生信息/采用中序遍历的思想输出节点信息,则在屏幕上根据学生学号的升序输出。void BTree:prnt(BTreeNode *p) /递归函数 if (p!=NULL )prnt(p-lchild);p-data.output();prnt(p-rchild);/实例函数void BTree:prnt()prnt(root);7、用户界面主函数文件:int main() BSTree t; /新建一个二叉树:t int choice=10; /将choice初始化,使其不为04 Sstudent s; BTreeNode *p=NULL;char num12;while(choice)cout请输入您要进行的操作:endl;cout1-向学生健康表插入学生信息endl2-在健康表删除学生信息endl 3-在健康表中查询学生信息(按学生学号来进行查找)endl4-在屏幕中输出全部学生信息endl0-退出choice;switch(choice)case 1: s.input(); /输入学生信息 t.inst(s);break; case 2: coutnum; p=t.deleteNode(num); if (p!=NULL)cout删除成功!删除学生的信息为:getdata().output();break; case 3: coutnum; p=t.sear(num); if (p!=NULL)p-getdata().output();elsecout找不到该学生信息!endl;break; case 4: t.prnt();break; case 0: break; default: cout输入错误!请重新输入。endl;coutendl; return 0;【结果及结果分析】1、插入学生信息:插入后的二叉树为:2、删除学生信息:3、按学号查询学生信息:4、输出二叉树中所有的学生信息:【参考文献】、数据结构C+描述 朱振元 朱承 编著本课题研究的目的就是通过一系列教学活动,激发学生的学习兴趣,为学生创造和谐的“说”的氛围,为学生积淀“说”的素材,为学生创造“说”的情景和空间局党建工作总体思路是:坚持以习近平新时代中国特色社会主义思想为指导,全面学习宣传贯彻党的十九大、十九届三中全会精神force (youth teams) and County party leaders, aimed at weakening the anti-Japanese forces. Zhuang Shaozhen was removed from Office and to the underground revolution activities carried out in the country, political parties were dissolved. Zhejiang comrades and thus losing a foothold in Wujiang basis points. To make them stay, jindapeng served as captain of the young workers through activities, make the political player-wise into the youth team. Save a group of the backbone of the resistance, and gave the Communists . Commander Zhu Xi, led by Deputy Commander Wang Hesong, stationed along the junction of Jiangsu xincheng, Wuzhen. Zhu Xi troops KMT-CCP cooperation and anti-Japanese policy of solidarity, he moved to Jiangsu and Zhejiang provinces. Zhu Department times and day Army hand-to-hand combat made victory, grow has momentum, standing strict Tomb, and new Cheng of appeasement army giant Haru Brigade anyway, received adapted; living Taihu Lake of bin of two a even Hunan army with of allegiance; Jiangsu and Zhejiang junction area of Wang Chunlin Department about 500 people also has done a Yu Zhu Xi men; River, and Zhejiang, and Shanghai area many tour miscellaneous forces also attracted attached return, plus many local you

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论