這篇文章給大家分享的是有關(guān)C++如何實現(xiàn)病人就醫(yī)管理系統(tǒng)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

具體內(nèi)容如下
函數(shù)可實現(xiàn)反應病人到醫(yī)院看病,排隊看醫(yī)生的情況,有行醫(yī)類模板的定義及所有類函數(shù)的編寫代碼
部分代碼展示:
lk_queue.h
#ifndef __LK_QUEUE_H__
#define __LK_QUEUE_H__
#include "utility.h" // 實用程序軟件包
#include "node.h" // 結(jié)點類模板
// 鏈隊列類模板
template<class ElemType>
class LinkQueue
{
protected:
// 鏈隊列實現(xiàn)的數(shù)據(jù)成員:
Node<ElemType> *front, *rear; // 隊頭隊尾指指
// 輔助函數(shù)模板:
void Init(); // 初始化隊列
public:
// 抽象數(shù)據(jù)類型方法聲明及重載編譯系統(tǒng)默認方法聲明:
LinkQueue(); // 無參數(shù)的構(gòu)造函數(shù)模板
virtual ~LinkQueue(); // 析構(gòu)函數(shù)模板
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> ©); // 復制構(gòu)造函數(shù)模板
LinkQueue<ElemType> &operator =(const LinkQueue<ElemType> ©);// 重載賦值運算符
};
// 鏈隊列類模板的實現(xiàn)部分
template <class ElemType>
void LinkQueue<ElemType>::Init()
// 操作結(jié)果:初始化隊列
{
rear = front = new Node<ElemType>; // 生成頭結(jié)點
}
template<class ElemType>
LinkQueue<ElemType>::LinkQueue()
// 操作結(jié)果:構(gòu)造一個空隊列
{
Init();
}
template<class ElemType>
LinkQueue<ElemType>::~LinkQueue()
// 操作結(jié)果:銷毀隊列
{
Clear();
}
template<class ElemType>
int LinkQueue<ElemType>::Length() const
// 操作結(jié)果:返回隊列長度
{
int count = 0; // 計數(shù)器
for (Node<ElemType> *tmpPtr = front->next; tmpPtr != NULL; tmpPtr = tmpPtr->next)
{ // 用tmpPtr依次指向每個元素
count++; // 對棧每個元素進行計數(shù)
}
return count;
}
template<class ElemType>
bool LinkQueue<ElemType>::Empty() const
// 操作結(jié)果:如隊列為空,則返回true,否則返回false
{
return rear == front;
}
template<class ElemType>
void LinkQueue<ElemType>::Clear()
// 操作結(jié)果:清空隊列
{
ElemType tmpElem; // 臨時元素值
while (Length() > 0)
{ // 隊列非空,則出列
OutQueue(tmpElem);
}
}
template <class ElemType>
void LinkQueue<ElemType>::Traverse(void (*visit)(const ElemType &)) const
// 操作結(jié)果:依次對隊列的每個元素調(diào)用函數(shù)(*visit)
{
for (Node<ElemType> *tmpPtr = front->next; tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{ // 對隊列每個元素調(diào)用函數(shù)(*visit)
(*visit)(tmpPtr->data);
}
}
template<class ElemType>
StatusCode LinkQueue<ElemType>::OutQueue(ElemType &e)
// 操作結(jié)果:如果隊列非空,那么刪除隊頭元素,并用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; // 釋放出隊的結(jié)點
return SUCCESS;
}
else
{ // 隊列為空
return UNDER_FLOW;
}
}
template<class ElemType>
StatusCode LinkQueue<ElemType>::GetHead(ElemType &e) const
// 操作結(jié)果:如果隊列非空,那么用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)
// 操作結(jié)果:插入元素e為新的隊尾,返回SUCCESS
{
Node<ElemType> *tmpPtr = new Node<ElemType>(e); // 生成新結(jié)點
rear->next = tmpPtr; // 新結(jié)點追加在隊尾
rear = tmpPtr; // rear指向新隊尾
return SUCCESS;
}
template<class ElemType>
LinkQueue<ElemType>::LinkQueue(const LinkQueue<ElemType> ©)
// 操作結(jié)果:由隊列copy構(gòu)造新隊列——復制構(gòu)造函數(shù)模板
{
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> ©)
// 操作結(jié)果:將隊列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" //鏈隊列
//行醫(yī)類
class HospitalListWLY
{
private:
//行醫(yī)類數(shù)據(jù)成員
LinkQueue<unsigned int>queue; //病人隊列
//輔助函數(shù)
void StandInALine(); //排隊
void Cure(); //就診
void Display(); //查看排隊
public:
//方法聲明及重載編譯系統(tǒng)默認方法聲明
HospitalListWLY(){}; //無參數(shù)的構(gòu)造函數(shù)
~HospitalListWLY(){}; //析構(gòu)函數(shù)
void Work(); //醫(yī)生行醫(yī)工作
};
//行醫(yī)類的實現(xiàn)部分
void HospitalListWLY::StandInALine()
//操作結(jié)果:輸入病人的病歷號,加入到病人排隊隊列中
{
unsigned int num; //病歷號
cout<<"請輸入病歷號:";
cin>>num; //輸入病人的病歷號
queue.InQueue(num); //將病歷號加入到病人排隊隊列中
}
void HospitalListWLY::Cure()
//操作結(jié)果:病人排隊隊列中最前面的病人就診,將其從隊列中刪除
{
if (queue.Empty())
{ //無病人
cout<<"現(xiàn)已沒有病人在排隊了!"<<endl;
}
else
{
unsigned int num; //病歷號
queue.OutQueue(num); //病人排隊隊列中最前面的病人就診,并將其從隊列中刪除
cout<<num<<"號病人現(xiàn)在就醫(yī)."<<endl;
}
}
void HospitalListWLY::Display()
//操作結(jié)果:從隊首到隊尾列出所有的排隊病人的病歷號
{
queue.Traverse(Write); //從隊首到隊尾列出所有的排隊病人的病歷號
cout<<endl;
}
void HospitalListWLY::Work()
//操作結(jié)果:醫(yī)生行醫(yī)工作
{
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感謝各位的閱讀!關(guān)于“C++如何實現(xiàn)病人就醫(yī)管理系統(tǒng)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站www.chinadenli.net,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站題目:C++如何實現(xiàn)病人就醫(yī)管理系統(tǒng)-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://www.chinadenli.net/article36/dgeisg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、電子商務、服務器托管、網(wǎng)站建設、商城網(wǎng)站、外貿(mào)網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容