C++實現(xiàn)病人就醫(yī)管理系統(tǒng)
本文實例為大家分享了C++語言實現(xiàn)病人就醫(yī)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
函數(shù)可實現(xiàn)反應(yīng)病人到醫(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> ©); // 復(fù)制構(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)造新隊列——復(fù)制構(gòu)造函數(shù)模板
{
Init();
for (Node<ElemType> *tmpPtr = copy.front->next; tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{ // 對copy隊列每個元素對當(dāng)前隊列作入隊列操作
InQueue(tmpPtr->data);
}
}
template<class ElemType>
LinkQueue<ElemType> &LinkQueue<ElemType>::operator =(const LinkQueue<ElemType> ©)
// 操作結(jié)果:將隊列copy賦值給當(dāng)前隊列——重載賦值運算符
{
if (© != this)
{
Clear();
for (Node<ElemType> *tmpPtr = copy.front->next; tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{ // 對copy隊列每個元素對當(dāng)前隊列作入隊列操作
InQueue(tmpPtr->data);
}
}
return *this;
}
#endif
Hospitalize.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
全部代碼下載鏈接:C++語言實現(xiàn)病人就醫(yī)管理系統(tǒng)
更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++課程設(shè)計之運動會管理系統(tǒng)
- C++學(xué)校運動會管理系統(tǒng)的實現(xiàn)
- C++實現(xiàn)學(xué)校運動會管理系統(tǒng)
- linux下C/C++學(xué)生信息管理系統(tǒng)
- C++實現(xiàn)企業(yè)職工工資管理系統(tǒng)
- C++實現(xiàn)景區(qū)信息管理系統(tǒng)
- C++實現(xiàn)停車場管理系統(tǒng)
- 基于C++語言實現(xiàn)機動車違章處罰管理系統(tǒng)
- C++學(xué)生信息管理系統(tǒng)
- C++實現(xiàn)簡單的信息管理系統(tǒng)
- C++實現(xiàn)簡單職工管理系統(tǒng)
- C++基礎(chǔ)學(xué)生管理系統(tǒng)
- C++實現(xiàn)簡單的圖書管理系統(tǒng)
- C++實現(xiàn)簡單職工信息管理系統(tǒng)
- C++實現(xiàn)簡單的學(xué)生管理系統(tǒng)
相關(guān)文章
C++ std::initializer_list 實現(xiàn)原理解析及遇到問題
這篇文章主要介紹了C++ std::initializer_list 實現(xiàn)原理勘誤,本文通過源碼解析給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02
C++編程析構(gòu)函數(shù)拷貝構(gòu)造函數(shù)使用示例詳解
這篇文章主要為大家介紹了C++編程構(gòu)造函數(shù)中析構(gòu)函數(shù)及拷貝構(gòu)造函數(shù)的使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11
C++實現(xiàn)LeetCode(7.翻轉(zhuǎn)整數(shù))
這篇文章主要介紹了C++實現(xiàn)LeetCode(7.翻轉(zhuǎn)整數(shù)),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-07-07
詳解C++標(biāo)準(zhǔn)庫中處理正則表達式的類std::regex
std?是?C++?標(biāo)準(zhǔn)庫的命名空間,包含了大量標(biāo)準(zhǔn)的?C++?類、函數(shù)和對象,這些類和函數(shù)提供了廣泛的功能,包括輸入輸出、容器、算法、字符串處理等,這篇文章主要介紹了C++標(biāo)準(zhǔn)庫中提供的用于處理正則表達式的類std::regex,需要的朋友可以參考下2024-03-03

