前言
模拟病人在医院等待就诊过程。
病人在医院的看病流程:挂号> 候诊一> 就诊。在本程序中只模拟等待就诊过程,
简述
文件linkqueue.h和文件linkqueue.cpp是针对队列的操作。队列采用链式存储,包含队列的初始化、进队、出队、判队空、求队列长度、查找和输出队列中元素等基本操作。
文件aap.h和文件app.cpp是针对病人的操作。病人信息被定义为结构体类型包含病人候诊、就诊、查看排队、查看看诊情况、上班、 下班和菜单等操作。
注:小白,望指正。
正文
#include"app.h"
#ifndef_linkqueue_h
#define_linkqueue_h
#include"iostream"
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status
typedef struct Node
{
DataType data;
Node*next;
}QNode;
typedef struct
{
QNode *front,*rear;
}LinkQueue;
Status init_Queue(LinkQueue &q);
Status In_Queue(LinkQueue &q,DataType x);
Status Out_Queue(LinkQueue &q,DataType &x);
Status Empty_Queue(LinkQueue q);
int Locate(LinkQueue q,int x);
void Show(LinkQueue q,int n);
int Length(LinkQueue q);
#endif
//linkqueue.cpp文件
#include"linkqueue.h"
Status Init_Queue(LinkQueue &q)
{
QNode *p;
p=new QNode;
if(p=NULL)
return 0;
p->next=NULL;
q.front=q.rear=p;
return OK;
}
Status In_Queue(LinkQueue &q,DataType x)
{
QNode*P=new QNode;
p->data=x;
p->next=NULL;
q.rear->next=p;
q.rear=p;
reurn OK;
}
Status OutQueue(LinkQueue &q,DataType &x)
{
if(q.rear=q.front)
return ERROR;
QNode*p=q.front->next;
x=p->data;
q.front->next=p->next;
if(p==q.rear)
q.rear==q.front;
delete p;
return ok;
}
Status Empty_Queue(LinkQueue q)
{
if(q.front==q.rear)
return OK;
else return ERROR;
}
int Locate(LinkQueue q,int x)
{
int n=1;
QNode*p=q.front->next;
while(p&&p->data.num!=x)
{
p=p->next;
n++;
}
if(p==NULL)
return 0;
else return n;
}
void Show(LinkQueue q,int n)
{
if(q.front==q.rear)return ;
QNode*p=q.front->next;
int i=1;
cout<<setw(10)<<"病历号"<<setw(10)<<"姓名"<<endl;
while(i<=n)
{
cout<<setw(10)<<p->data.num<<setw(10)<<p->data.name<<endl;
p=p->next;
i++;
}
}
int Length(LinkQueue q)
{
QNode*p=q.front;
int count=0;
while(p!=q.rear)
{
p=p->next;
count++;
}
return count;
}
//app.h文件
#ifndef_opeator_h
#define_opearor_h
typedef struct//患者信息结构体
{
int num;
char name[20];
} DataType;
#include"linkqueue.h"
void Waiting(LinkQueue &q);
void Treatment(LinkQueue &q);
void Search_Wait(LinkQueue q);
void Searh_Treatment(LinkQueue q);
void Work(LinkQueue &q);
void Menu();
#endif
//app.cpp文件
#include"app.h"
void Waiting(LinkQueue &q)
{
DataType x;
cout<<"请输入候诊病人信息:"<<endl;
cout<<"病历号:";
cin>>x.num;
cout<<"姓名:";
cin>>x.name;
In_Queue(q,e);
}
void Treatment(LinkQueue &q)
{
DataType x;
if(Out_Queue(q,x)==ERROR)
{
cout<<"无等候就诊的病人!"<<endl;
reurn ;
}
cout<<"当前就诊病人信息:"<<endl;
cout<<setw(10)<<"病历号"<<setw(10)<<"姓名"<<endl;
cout<<setw(10)<<x.num<<setw(10)<<x.name<<endl;
}
void Search_Wait(LinkQueue q)
{
int x,n;
cout<<"请输入查询病人病历号:"<<endl;
cin>>x;
n=Locate(q,x);
if(n==0)
cout<<"不存在该病人!"<<endl;
else
if(n==1)
cout<<"您就是下一位就诊的病人!"<<endl;
else
{
cout<<"该病人前还有"<<n-1<<"个人在等待!"<<endl;
cout<<"等待的病人信息:"<<endl;
Show(q,n-1);
}
}
void Search_Treatment(LinkQueue q)
{
if(Empty_Queue(q)==1)
cout<<"无病人等候!"<<endl;
else
cout<<"共有"<<Length(q)<<"个病人在候诊!"<<endl;
}
void Work(LinkQueue &q)
{
Init_Queue(q);
cout<<"准备工作已完成!"<<endl;
}
void Menu()
{
LinkQueue q;
bool flag=false;
system("cls");
int ch;
do
{
cout<<"********************************************"<<endl;
cout<<" "<<endl;
cout<<" 医院候诊管理系统 "<<endl;
cout<<" "<<endl;
cout<<" 1.上班 2.候诊 "<<endl;
cout<<" 3.就诊 4.查询候诊情况 "<<endl;
cout<<" 5.查询就诊情况 0.下班 "<<endl;
cout<<" "<<endl;
cout<<"********************************************"<<endl;
}
cout<<"请输入选项:";
cin>>ch;
switch(ch)
{
case 1:
{
Work(q);
flag=ture;
break;
}
case 2:
{
if(flag=false)
cout<<"未上班!"<<endl;
else
Waiting(q);
break;
}
case 3:
{
if(flag=false)
cout<<"未上班!"<<endl;
else
Treatment(q);
break;
}
case 4:
{
if(flag=false)
cout<<"未上班!"<<endl;
else
Search_Wait(q);
break;
}
case 5:
{
if(flag=false)
cout<<"未上班!"<<endl;
else
Search_Treatment(q);
break;
}
case 0:
{
return ;
default:
cout<<"数据输入不合法,请重新输入!"<<endl;
}
system("pause");
system("cls");
}while(ch!=0);
cout<<"\n欢迎再次使用本系统!"<<endl;
}
//main.cpp文件
#include"app.h"
int main()
{
Menu();
return 0;
}