這篇文章給大家分享的是有關C++如何實現病人就醫管理系統的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
具體內容如下
函數可實現反應病人到醫院看病,排隊看醫生的情況,有行醫類模板的定義及所有類函數的編寫代碼
部分代碼展示:
lk_queue.h
#ifndef __LK_QUEUE_H__
#define __LK_QUEUE_H__
#include "utility.h" // 實用程序軟件包
#include "node.h" // 結點類模板
// 鏈隊列類模板
template<class ElemType>
class LinkQueue
{
protected:
// 鏈隊列實現的數據成員:
Node<ElemType> *front, *rear; // 隊頭隊尾指指
// 輔助函數模板:
void Init(); // 初始化隊列
public:
// 抽象數據類型方法聲明及重載編譯系統默認方法聲明:
LinkQueue(); // 無參數的構造函數模板
virtual ~LinkQueue(); // 析構函數模板
int Length() const; // 求隊列長度
bool Empty() const; // 判斷隊列是否為空
void Clear(); // 將隊列清空
void Traverse(void (*visit)(const ElemType &)) const ; // 遍歷隊列
StatusCode OutQueue(ElemType &e); // 出隊操作
StatusCode GetHead(ElemType &e) const; // 取隊頭操作
StatusCode InQueue(const ElemType &e); // 入隊操作
LinkQueue(const LinkQueue<ElemType> ©); // 復制構造函數模板
LinkQueue<ElemType> &operator =(const LinkQueue<ElemType> ©);// 重載賦值運算符
};
// 鏈隊列類模板的實現部分
template <class ElemType>
void LinkQueue<ElemType>::Init()
// 操作結果:初始化隊列
{
rear = front = new Node<ElemType>; // 生成頭結點
}
template<class ElemType>
LinkQueue<ElemType>::LinkQueue()
// 操作結果:構造一個空隊列
{
Init();
}
template<class ElemType>
LinkQueue<ElemType>::~LinkQueue()
// 操作結果:銷毀隊列
{
Clear();
}
template<class ElemType>
int LinkQueue<ElemType>::Length() const
// 操作結果:返回隊列長度
{
int count = 0; // 計數器
for (Node<ElemType> *tmpPtr = front->next; tmpPtr != NULL; tmpPtr = tmpPtr->next)
{ // 用tmpPtr依次指向每個元素
count++; // 對棧每個元素進行計數
}
return count;
}
template<class ElemType>
bool LinkQueue<ElemType>::Empty() const
// 操作結果:如隊列為空,則返回true,否則返回false
{
return rear == front;
}
template<class ElemType>
void LinkQueue<ElemType>::Clear()
// 操作結果:清空隊列
{
ElemType tmpElem; // 臨時元素值
while (Length() > 0)
{ // 隊列非空,則出列
OutQueue(tmpElem);
}
}
template <class ElemType>
void LinkQueue<ElemType>::Traverse(void (*visit)(const ElemType &)) const
// 操作結果:依次對隊列的每個元素調用函數(*visit)
{
for (Node<ElemType> *tmpPtr = front->next; tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{ // 對隊列每個元素調用函數(*visit)
(*visit)(tmpPtr->data);
}
}
template<class ElemType>
StatusCode LinkQueue<ElemType>::OutQueue(ElemType &e)
// 操作結果:如果隊列非空,那么刪除隊頭元素,并用e返回其值,返回SUCCESS,
// 否則返回UNDER_FLOW,
{
if (!Empty())
{ // 隊列非空
Node<ElemType> *tmpPtr = front->next; // 指向隊列頭素
e = tmpPtr->data; // 用e返回隊頭元素
front->next = tmpPtr->next; // front指向下一元素
if (rear == tmpPtr)
{ // 表示出隊前隊列中只有一個元素,出隊后為空隊列
rear = front;
}
delete tmpPtr; // 釋放出隊的結點
return SUCCESS;
}
else
{ // 隊列為空
return UNDER_FLOW;
}
}
template<class ElemType>
StatusCode LinkQueue<ElemType>::GetHead(ElemType &e) const
// 操作結果:如果隊列非空,那么用e返回隊頭元素,返回SUCCESS,
// 否則返回UNDER_FLOW,
{
if (!Empty())
{ // 隊列非空
Node<ElemType> *tmpPtr = front->next; // 指向隊列頭素
e = tmpPtr->data; // 用e返回隊頭元素
return SUCCESS;
}
else
{ // 隊列為空
return UNDER_FLOW;
}
}
template<class ElemType>
StatusCode LinkQueue<ElemType>::InQueue(const ElemType &e)
// 操作結果:插入元素e為新的隊尾,返回SUCCESS
{
Node<ElemType> *tmpPtr = new Node<ElemType>(e); // 生成新結點
rear->next = tmpPtr; // 新結點追加在隊尾
rear = tmpPtr; // rear指向新隊尾
return SUCCESS;
}
template<class ElemType>
LinkQueue<ElemType>::LinkQueue(const LinkQueue<ElemType> ©)
// 操作結果:由隊列copy構造新隊列——復制構造函數模板
{
Init();
for (Node<ElemType> *tmpPtr = copy.front->next; tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{ // 對copy隊列每個元素對當前隊列作入隊列操作
InQueue(tmpPtr->data);
}
}
template<class ElemType>
LinkQueue<ElemType> &LinkQueue<ElemType>::operator =(const LinkQueue<ElemType> ©)
// 操作結果:將隊列copy賦值給當前隊列——重載賦值運算符
{
if (© != this)
{
Clear();
for (Node<ElemType> *tmpPtr = copy.front->next; tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{ // 對copy隊列每個元素對當前隊列作入隊列操作
InQueue(tmpPtr->data);
}
}
return *this;
}
#endifHospitalize.h
#ifndef __HOSPITALIZE_H__
#define __HOSPITALIZE_H__
#include"lk_queue.h" //鏈隊列
//行醫類
class HospitalListWLY
{
private:
//行醫類數據成員
LinkQueue<unsigned int>queue; //病人隊列
//輔助函數
void StandInALine(); //排隊
void Cure(); //就診
void Display(); //查看排隊
public:
//方法聲明及重載編譯系統默認方法聲明
HospitalListWLY(){}; //無參數的構造函數
~HospitalListWLY(){}; //析構函數
void Work(); //醫生行醫工作
};
//行醫類的實現部分
void HospitalListWLY::StandInALine()
//操作結果:輸入病人的病歷號,加入到病人排隊隊列中
{
unsigned int num; //病歷號
cout<<"請輸入病歷號:";
cin>>num; //輸入病人的病歷號
queue.InQueue(num); //將病歷號加入到病人排隊隊列中
}
void HospitalListWLY::Cure()
//操作結果:病人排隊隊列中最前面的病人就診,將其從隊列中刪除
{
if (queue.Empty())
{ //無病人
cout<<"現已沒有病人在排隊了!"<<endl;
}
else
{
unsigned int num; //病歷號
queue.OutQueue(num); //病人排隊隊列中最前面的病人就診,并將其從隊列中刪除
cout<<num<<"號病人現在就醫."<<endl;
}
}
void HospitalListWLY::Display()
//操作結果:從隊首到隊尾列出所有的排隊病人的病歷號
{
queue.Traverse(Write); //從隊首到隊尾列出所有的排隊病人的病歷號
cout<<endl;
}
void HospitalListWLY::Work()
//操作結果:醫生行醫工作
{
int select=0;
while(select!=4)
{
cout<<"1。排隊—輸入排隊病人的病歷號,加入到病人隊列中."<<endl;
cout<<"2.就診—病人排隊隊列中最前面的病人就診,并將其從隊列中刪除"<<endl;
cout<<"3.查看排隊—從隊首到隊尾列出所有的排隊病人的病歷號"<<endl;
cout<<"4.下班—退出運行"<<endl;
cout<<"請選擇:";
cin>>select; //選擇功能
switch(select)
{
case 1:
StandInALine(); //排隊——輸入病人的病歷號,加入到病人隊列中
break;
case 2:
Cure(); //就診——病人排隊隊列中最前面的病人就診,并將其從隊列中刪除
break;
case 3:
Display(); //查看隊列——從隊首到隊尾列出所有的排隊病人的病歷號
break;
}
}
}
#endif感謝各位的閱讀!關于“C++如何實現病人就醫管理系統”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。