IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 数据结构与算法 -> 数据结构,简单模拟看病情况 -> 正文阅读

[数据结构与算法]数据结构,简单模拟看病情况

#include<iostream>
#include<string>
using namespace std;
#include<fstream>
typedef struct node//information contained in each patient(每个病人所包含的信息)
{
	string name;//姓名
	int sex;//性别
	int no;//medical record number(病历号)
	node* next;
}node;
//queueed patients are stored in queues(排队的病人用队列储存)
typedef struct
{
	node data;//patient information(病人的信息)
	node* front;//队头
	node* rear;//队尾
	
}queue;
//the diagnosed patients are stored in the stack(诊断完的病人用栈储存)
typedef struct
{
	node data;//patient information(病人的信息)
	node* top;//stack top(栈顶)
}stack;
class Treatment
{
private:
	queue q;
	stack s;
	int no;//medical record number(病历号)
public:
	Treatment()//initialization(初始化)
	{
		//no header node(没头结点)
		q.rear = q.front=NULL;
		no = 0;
		s.top = NULL;
	}
	void LineUp()//排队
	{
		while (1)//realize continuous input of information(实现连续输入信息)
		{
			node* temp;
			temp = new node;
			temp->next = NULL;
			cout << "姓名" << endl;
			cin >> temp->name;
			cout << "性别" << endl;
			cout << "1,男;2,女" << endl;
			do
			{
				cin >> temp->sex;
				if (temp->sex != 1 &&temp->sex != 2)
					cout << "输入有误,请重新输入" << endl;
				else break;
			} while (1);
			temp->no = ++no;
			if (q.front == NULL)
			{
				q.front = temp;
				q.rear = q.front;
			}
			q.rear->next = temp;
			q.rear = temp;
			
			cout << "输入完毕,是否继续输入下一个排队病人的信息" << endl;
			cout << "Y:继续;N:不了" << endl;
			char choice;
			while (1)
			{
				
				cin >> choice;
				if (choice != 'Y' && choice != 'N')
					cout << "选择有误" << endl;
				else break;
			}
			if (choice == 'N')
			{
				q.rear->next = NULL;
				return;
			}
		}
	}
	void diagnosis()//诊断
	{
		if (q.front == NULL)
		{
			cout << "暂时没有看病的病人" << endl;
			return;
		}
		node* temp=q.front;
		while (temp)
		{
			cout << temp->no << " 号病人" << "开始就诊" << endl;
			cout << "姓名 " << temp->name << endl;
			cout << "性别" << (temp->sex == 1 ? "男" : "女") << endl;
			cout << "输入OK诊治完毕" << endl;
			string flag;
			while (1)
			{
				cin >> flag;
				if (flag == "OK")
				{
					
					cout << temp->no << " 号病人" << "诊治完毕" << endl;
					cout << "姓名 " << temp->name << endl;
					cout << "性别" << (temp->sex == 1 ? "男" : "女") << endl;
					//enter the stack(进栈)
					if (s.top == NULL)
					{
						
						s.top = temp;
						s.top->next = NULL;
					}
					else
					{
						temp->next = s.top->next;
						s.top->next = temp;
					}
					//to delete the information of the patient in the queue
					//诊治完要删除该病人在队列里的信息
					node* t = temp->next;
					
					q.front = t;
					temp = t;
					

					break;
				}
				else cout << "指令有误,请重新输入" << endl;
			}
			cout << "是否继续诊断下一位病人" << endl;
			char choice;
			cout << "Y:是;N:否" << endl;
			while (1)
			{
				cin >> choice;
				if (choice == 'N')
				{
					
					return;
				}
				else if (choice == 'Y')
				{
					
					temp = temp->next;
					break;
				}
				else cout << "输入指令有误请重新输入" << endl;
			}
		}
	}
	void QueueSituation()//view queuing(查看排队情况)
	{
	
		node* temp = q.front;
		if (temp == NULL)
		{
			cout << "队列为空" << endl;
			return;
		}
		for (; temp; temp = temp->next)
		{
			cout<<temp->no<<'\t' << temp->name << '\t' << (temp->sex == 1 ? "男" : "女") << endl;
		}
	}
	void StackSituation()//view queuing(查看诊治完的病人)
	{
		node* temp = s.top;
		if (temp == NULL)
		{
			cout << "还没诊治过病人" << endl;
			return;
		}
		for (; temp; temp = temp->next)
			cout << temp->no << "  " << temp->name << "  "<< (temp->sex == 1?"男":"女") << endl;
	}
	void SaveInformation()//save diagnosis and treatment(保存诊治情况)
	{
		node* temp = s.top;      
		if (temp == NULL)
		{
			cout << "暂无诊治情况" << endl;
			return;
		}

		ofstream ofs;
		ofs.open("诊治表", ios::out);
		if (!ofs.is_open())
		{
			cout << "文件打开失败" << endl;
			return;
		}
		for (; temp; temp = temp->next)
			ofs << temp->no << '\t' << temp->name << '\t' << (temp->sex == 1 ? "男" : "女") << endl;
		cout << "保存完毕" << endl;
		ofs.close();
			
	}
	void ViewInformation()
	{
		
		ifstream ifs;//读文件流
		ifs.open("诊治表",ios::in);//为读文件而打开文件
		string buf;
		if (!ifs.is_open())
		{
			cout << "打开文件失败,该功能退出" << endl;
			return;
		}
		if (!getline(ifs, buf))cout << "文件为空" << endl;
		cout << buf << endl;
		while (getline(ifs, buf))
		{

			cout << buf << endl;
		}
		ifs.close();
	}
};
int main()
{
	Treatment treatment;
	

	do
	{
		cout << "输入想实现的功能" << endl;
		cout << "0,下班" << endl
			<< "1,排队看病" << endl
			<< "2,开始诊治" << endl
			<< "3,查看队列情况" << endl
			<< "4,查看诊治完成情况" << endl
			<< "5,保存诊治信息" << endl
			<< "6,查看文件诊治情况" << endl;
		int choice;
		cin >> choice;
		switch (choice)
		{
			case 0:return 0;
			case 1:treatment.LineUp(); break;
			case 2:treatment.diagnosis(); break;
			case 3:treatment.QueueSituation(); break;
			case 4:treatment.StackSituation(); break;
			case 5:treatment.SaveInformation(); break;
			case 6:treatment.ViewInformation(); break;
			default :cout << "输入有误" << endl;
		}
		system("pause");
		system("cls");
	} while (1);
}

  数据结构与算法 最新文章
【力扣106】 从中序与后续遍历序列构造二叉
leetcode 322 零钱兑换
哈希的应用:海量数据处理
动态规划|最短Hamilton路径
华为机试_HJ41 称砝码【中等】【menset】【
【C与数据结构】——寒假提高每日练习Day1
基础算法——堆排序
2023王道数据结构线性表--单链表课后习题部
LeetCode 之 反转链表的一部分
【题解】lintcode必刷50题<有效的括号序列
上一篇文章      下一篇文章      查看所有文章
加:2021-07-26 12:18:24  更:2021-07-26 12:19:26 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年3日历 -2024/3/29 6:58:32-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码