一,题目: 病人在医院的看病流程:挂号—>候诊—>就诊。在本程序中只模拟等待就诊过程,所以主要完成的功能如下:
(1)候诊——输入排队病人的病历号和姓名,加入到病人排队队列中。
(2)就诊——病人排队队列中最前面的病人就诊,将其从队列中删除。
(3)查看排队情况——针对就诊病人进行的查询。输入所要查询病人的病历号,显示其之前排队病人的人数以及他们的病历号和姓名。
(4)查看看诊——看病医生进行的查询操作。判断是否还有人在候诊,如有显示候诊人数。
(5)下班——退出运行。
(6)上班——初始化排队队列。
二、功能代码:
//Queue.h
#ifndef QUEUE_H
#define QUEUE_H
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef int ElemType;
typedef int Status;
#define MAXSIZE 100
#define ERROR 0
#define OK 1
typedef struct person
{
int num;
char name[20];
struct person *next;
}Qperson;
typedef struct
{
Qperson * front;
Qperson * rear;
}LinkQueue;
Status InitQueue(LinkQueue &Q);
Status EnQueue(LinkQueue &Q,ElemType e,char mingzi[]);
Status DeQueue(LinkQueue &Q,ElemType &e,char mingzi[]);
void GetHead(LinkQueue Q);
Status LocateQueue(LinkQueue Q,ElemType e);
int Length(LinkQueue Q);
int Length_H(LinkQueue Q,ElemType e);
void GetQueue(LinkQueue &Q,ElemType e);
#endif
//Queue.cpp
#include"Queue.h"
Status InitQueue(LinkQueue &Q)
{
Qperson *p;
p=new person;
if(!p) return ERROR;
Q.front =Q.rear=p;
p->next=NULL;
return OK;
}
Status EnQueue(LinkQueue &Q,ElemType e,char mingzi[])
{
Qperson *p;
p=new Qperson;
if(!p) return ERROR;
p->num=e;
strcpy(p->name,mingzi);
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return OK;
}
Status DeQueue(LinkQueue &Q,ElemType &e,char mingzi[])
{
Qperson *p;
if(Q.front ==Q.rear) return ERROR;
p=Q.front->next;
e=p->num;
strcpy(mingzi,p->name);
Q.front->next=p->next;
if(p==Q.rear) Q.rear =Q.front ;
delete p;
return OK;
}
void GetHead(LinkQueue Q)
{
if(Q.front ==Q.rear)
return ;
else
{
cout<<"病历号 姓名 "<<endl;
cout<<Q.front->next->num ;
cout<" ";
cout<<Q.front->next->name <<endl;
}
}
Status LocateQueue(LinkQueue Q,ElemType e)
{
Qperson *p;
p=Q.front->next;
if(Q.front ==Q.rear) return ERROR;
while(p)
{
if(p->num==e)
return OK;
p=p->next;
}
return ERROR;
}
int Length(LinkQueue Q)
{
int i=0;
Qperson *p;
p=Q.front->next;
while(p!=NULL)
{
i++;
p=p->next;
}
return i;
}
int Length_H(LinkQueue Q,ElemType e)
{
int i=0;
Qperson *p;
p=Q.front->next;
while(p->num!=e)
{
i++;
p=p->next;
}
return i;
}
void GetQueue(LinkQueue &Q,ElemType e)
{
Qperson *p;
p=Q.front->next;
if(Q.front==Q.rear)
return ;
if(Q.front->next->num==e)
cout<<"你就是下一位就诊病人"<<endl;
else
{cout<<"你的前面的候诊人数为:"<<Length_H(Q,e)<<endl;
cout<<"病历号 姓名"<<endl;
while(p->num!=e)
{
cout<<p->num;
cout<<" ";
cout<<p->name<<endl;
p=p->next;
}
}
}
//Function.h
#ifndef FUNCTION_H
#define FUNCTION_H
#include"Queue.h"
void initQueue(LinkQueue &Q);
void houzhen(LinkQueue &Q);
void jiuzhen(LinkQueue &Q);
void Findjiuzhen(LinkQueue &Q);
void Findhouzhen(LinkQueue &Q);
void menu();
#endif
//Function.cpp
#include"Function.h"
void initQueue(LinkQueue &Q)
{
if(InitQueue(Q)==OK)
{
cout<<"准备工作已完成"<<endl;
}
else
{
cout<<"准备工作没有完成"<<endl;
}
}
void houzhen(LinkQueue &Q)
{
ElemType e;
char mingzi[20];
cout<<"请输入病人信息:"<<endl;
cout<<"请输入病历号:";
cin>>e;
cout<<"请输入姓名:";
cin>>mingzi;
if(EnQueue(Q,e,mingzi)==OK)
cout<<"候诊成功"<<endl;
else
cout<<"候诊失败"<<endl;
}
void jiuzhen(LinkQueue &Q)
{
ElemType e;
char mingzi[20];
cout<<"当前病人就诊信息:"<<endl;
cout<<"病历号 姓名"<<endl;
if(DeQueue(Q,e,mingzi)==ERROR)
cout<<"出现错误"<<endl;
else
cout<<e;
cout<<" ";
cout<<mingzi<<endl;
}
void Findjiuzhen(LinkQueue &Q)
{
ElemType e;
cout<<"请输入病人的病历号:";
cin>>e;
if(LocateQueue(Q,e)==ERROR)
cout<<"病历号输入错误,没有找到此人"<<endl;
else
GetQueue(Q,e);
cout<<endl;
}
void Findhouzhen(LinkQueue &Q)
{
cout<<"当前侯诊人数为"<<Length(Q)<<endl;
}
void menu()
{
LinkQueue Q;
int flag=0;
int choice;
while(1){
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>>choice;
if(flag==0&&choice!=1)
cout<<"还没有开始上班!"<<endl;
else
switch(choice)
{
case 1:
initQueue(Q);
flag=1;
break;
case 2:
houzhen(Q);
break;
case 3:
jiuzhen(Q);
break;
case 4:
Findjiuzhen(Q);
break;
case 5:
Findhouzhen(Q);
break;
case 0:
return ;
break;
default :
cout<<"编号输入错误"<<endl;
}
system("pause");
system("cls");
}
}
//main.cpp
#include"Function.h"
int main()
{
menu();
return 0;
}