![医院设施管理系统C++类树_第1页](http://file4.renrendoc.com/view/71bb3da4e48990805236b7803589b31a/71bb3da4e48990805236b7803589b31a1.gif)
![医院设施管理系统C++类树_第2页](http://file4.renrendoc.com/view/71bb3da4e48990805236b7803589b31a/71bb3da4e48990805236b7803589b31a2.gif)
![医院设施管理系统C++类树_第3页](http://file4.renrendoc.com/view/71bb3da4e48990805236b7803589b31a/71bb3da4e48990805236b7803589b31a3.gif)
![医院设施管理系统C++类树_第4页](http://file4.renrendoc.com/view/71bb3da4e48990805236b7803589b31a/71bb3da4e48990805236b7803589b31a4.gif)
![医院设施管理系统C++类树_第5页](http://file4.renrendoc.com/view/71bb3da4e48990805236b7803589b31a/71bb3da4e48990805236b7803589b31a5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
医院设施管理系统C++类树医院设施管理系统C++类树医院设施管理系统C++类树资料仅供参考文件编号:2022年4月医院设施管理系统C++类树版本号:A修改号:1页次:1.0审核:批准:发布日期:C++类树医院设施管理树的应用,统计任意两个结点之间的结点个数,支出给定结点的子结点,浏览整个医院的结构,C++,类,树,医院设施管理,C++,类#include<iostream>#include<queue>#include<fstream>#include<cstdlib>#include<string>#include<iomanip>usingnamespacestd;classhosnode{public: stringname; intnum; hosnode(stringn=NULL,intnumber=0); stringName(); intNum(); friendostream&operator<<(ostream&out,hosnode&node);};hosnode::hosnode(stringn,intnumber){ name=n; num=number;}stringhosnode::Name(){ returnname;}inthosnode::Num(){ returnnum;}ostream&operator<<(ostream&out,hosnode&node){ out<<""<<"|"<<setiosflags(ios_base::left)<<setw(8)<<<<"|"<<resetiosflags(ios_base::left)<<setw(8)<<node.num<<"|"; returnout;}classtreenode{ //treenode*parent;//父结点public: hosnodevalue; treenode*pc;//最左边子结点 treenode*ls;//左兄弟节点 treenode*rs;//右兄弟节点 treenode(hosnodem_value); /*voidsetvalue(hosnodem_value); voidsetchild(treenode*pointer); voidsetsibling(treenode*pointer); voidinsertfirst(treenode*node); voidinsertnext(treenode*node); voidprint();*/ voidvisit();};treenode::treenode(hosnodem_value):value(m_value){ pc=NULL; ls=NULL; rs=NULL;}voidtreenode::visit(){ cout<<value<<endl;}classtree{public: tree(); treenode*root; treenode*getroot(); treenode*Parent(treenode*cur);//查找cur的父结点 treenode*find(stringcur);//查找医院相关部门cur voidinsert(stringparent,hosnode*value);//结点的插入函数(通过不断地插入操作构建医院结构树) voidrootfirst(treenode*root);//先根深度遍历 voidrootlast(treenode*root);//后根深度遍历 voidwith(treenode*root);//广度优先遍历 intcount(stringgparent,stringchild);//父结点包含子结点个数的统计 voids_treatment();//模拟处理函数 voidinterface1();//操作界面 voidshow(stringn);//浏览输出函数};tree::tree(){ root=NULL;}treenode*tree::getroot(){ returnroot;}voidtree::insert(stringparent,hosnode*value){ hosnode*tmp; treenode*tmp1,*tmp2,*tmp3; if(root==NULL) { tmp=newhosnode(parent,1); tmp2=newtreenode(*value); root=newtreenode(*tmp); root->pc=tmp2; } else { tmp1=find(parent); if(tmp1) { tmp2=newtreenode(*value); if(tmp1->pc==NULL) { tmp1->pc=tmp2; } else { tmp3=tmp1->pc; while(tmp3->ls) { tmp3=tmp3->ls; } tmp3->ls=tmp2; } } }}treenode*tree::Parent(treenode*cur){ if(!cur) returnNULL; else { treenode*pointer=root,*tmp; queue<treenode*>nqueue; if(pointer) nqueue.push(pointer); while(!nqueue.empty()) { pointer=nqueue.front(); tmp=pointer->pc; if(tmp!=NULL) { if((tmp->value).Name()==(cur->value).Name()) returnpointer; else { tmp=tmp->ls; if(tmp!=NULL) { while((tmp->value).name!=(cur->value).name) { tmp=tmp->ls; if(!tmp) break; } if(tmp!=NULL) returnpointer; } } } nqueue.pop(); if(pointer->pc!=NULL) { nqueue.push(pointer->pc); tmp=pointer->pc->ls; while(tmp) { nqueue.push(tmp); tmp=tmp->ls; } } } returnNULL; }}treenode*tree::find(stringcur){ treenode*pointer=root,*tmp; queue<treenode*>nqueue; if(pointer) nqueue.push(pointer); while(!nqueue.empty()) { pointer=nqueue.front(); if((pointer->value).Name()==cur) returnpointer; nqueue.pop(); if(pointer->pc!=NULL) { nqueue.push(pointer->pc); tmp=pointer->pc->ls; while(tmp) { nqueue.push(tmp); tmp=tmp->ls; } } } returnNULL;}voidtree::with(treenode*root){ treenode*pointer=root,*tmp; intn=0; queue<treenode*>nqueue; cout<<""<<"--------------------\n"; cout<<""<<"|名称"<<"|"<<"数量|\n"; cout<<""<<"--------------------\n"; if(pointer) nqueue.push(pointer); while(!nqueue.empty()) { pointer=nqueue.front(); n=count("医院",pointer->); cout<<""<<"|"<<setiosflags(ios_base::left)<<setw(8)<<pointer-> <<setw(2)<<"|"<<setw(8)<<n<<resetiosflags(ios_base::left)<<"|"<<endl; cout<<""<<"--------------------\n"; nqueue.pop(); if(pointer->pc!=NULL) { nqueue.push(pointer->pc); tmp=pointer->pc->ls; while(tmp) { nqueue.push(tmp); tmp=tmp->ls; } } }}inttree::count(stringgparent,stringchild){ intn=1; if(find(gparent)==NULL||find(child)==NULL) return0; elseif(root->==child) return1; else { treenode*tmp2=find(child); n=tmp2->value.num; while((Parent(tmp2)->value).Name()!=gparent)//查找父结点 { n*=(Parent(tmp2)->value).Num(); tmp2=Parent(tmp2); } returnn; }}voidtree::interface1(){ cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; cout<<"%%%1、构建医院%%%\n"; cout<<"%%%2、包含统计操作%%%\n"; cout<<"%%%3、结点及孩子结点输出%%%\n"; cout<<"%%%4、浏览医院结构%%%\n"; cout<<"%%%5、终止操作%%%\n"; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; cout<<"请选择。。。";}voidtree::show(stringn){ treenode*tmp=find(n),*tmp2; while(tmp==NULL) { inta; stringname; cout<<"该医院不包含该部门(设施)!!!"<<endl; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%\n"; cout<<"%%%%%1、继续查找%%%%%\n"; cout<<"%%%%%2、返回上层%%%%%\n"; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%\n"; cout<<"请选择。。。"; cin>>a; switch(a) { case1: cout<<"输入了解的部门的名称:"; cin>>name; tmp=find(name); break; case2: system("cls"); s_treatment(); break; } system("cls"); } if(tmp->pc==NULL) cout<<"该名称单位不包含任何下属设施!"<<endl; else { cout<<"所包含的下属设施:"<<endl; cout<<""<<"--------------------\n"; cout<<""<<"|名称"<<"|"<<"数量|\n"; cout<<""<<"--------------------\n"; cout<<(tmp->pc)->value<<endl; cout<<""<<"--------------------\n"; tmp2=tmp->pc->ls; while(tmp2) { cout<<tmp2->value<<endl; cout<<""<<"--------------------\n"; tmp2=tmp2->ls; } }}voidtree::s_treatment(){ stringtmp1,tmp2; intn; ifstreaminf("data.txt"); interface1(); cin>>n; system("cls"); while(n!=5) { switch(n) { case1: if(!inf) { cout<<"读取失败!!"<<endl; exit(0); } while(!inf.eof()) { inf>>tmp1>>tm
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电子商务平台交易安全保障合同
- 租赁居间合同
- 游戏娱乐项目开发合作协议
- 数据中心建设及运维服务协议
- 基于物联网的智能家庭设备采购合同
- 东营视频会议系统施工方案
- 医疗大数据分析与应用服务合同
- 有限合伙股份转让协议
- 设备经营租赁合同
- 网络购物平台售后服务协议
- 国家农产品质量安全监督抽查抽样单
- 聘书模板可编辑
- 高校教师个人总结3000字数
- 离心式压缩机功率公式
- 柴油机突然停机的原因及判断处理
- 参保人员就医流程doc
- 微观经济学图示分析汇总分解(共17页)
- 现场材料浪费罚款单(精编版)
- ABB智能定位器TZID-C调试说明书(中文正式版)
- 东南大学建筑学专业课程设置
- Q∕CR 562.2-2017 铁路隧道防排水材料 第2部分:止水带
评论
0/150
提交评论