病人就医管理设计要求如下:
以下是代码的实现,基于C语言。
设计的结构是采用链队列作为主要的存储结构,以及一些结构体作辅助;其中添加一些功能,一些防范用户输入的设计。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define MAXSIZE 100 //规定每天每个科室最大接诊量
//链队列的结构 FIFO
typedef struct linkedQueue {
int number;//预诊号
struct linkedQueue *next;//指向下一个数据的指针
}Queue;
//队列的指针结构
typedef struct{
struct linkedQueue *front,*rear;//rear -> end ; front -> frist
}Pionter;
//将挂号时产生的数据抽象出来成为一个结构图
typedef struct {
int department[MAXSIZE];//存入挂号时,所产生的诊号(用数组保存)
int count;//当前挂号总人数
int number;//排队人数
}List;
//设置结构体的全局变量
Queue *queueA,*queueB,*queueC;//A- 儿科 & B-外科 & C-内科
Pionter *piontA,*piontB,*piontC;//指针结构体
List *A,*B,*C;//存储挂号数据的结构体
/*
*获取预诊号
*@return int
*/
int getRegisteredNumber(List *list)
{
list->department[list->count] = ++(list->count);
++(list->number);
return list->count;
}
/*
*挂号
*@return void
*/
void registered()
{
/*就诊后不清除患者挂号信息,患者当天无需二次挂号,仅需用就诊号直接排队就诊。
*结合实际生活,例如:当我们挂号;排队后;就诊时,医生无法立即判断患者病情,需要医学
*影像等检查,由于检查无法第一时间出结果,患者需要转场取得检查结果后,再次前往就诊。
*/
//挂号,需要根据所输入诊室,来确定编号
char department;
printf("请输入你需要挂号的诊室(A-儿科/B-外科/C内科)\n");
scanf("%c",&department);
getchar();
department = toupper(department);//将输入chose转换成大写
if(department == 'A') {
printf("你的就诊号是:[A%d],",getRegisteredNumber(A));
printf("当前挂号人数为%d\n",A->number);
} else if(department == 'B') {
printf("你的就诊号是:[B%d],",getRegisteredNumber(B));
printf("当前挂号人数为%d\n",B->number);
} else if(department == 'C') {
printf("你的就诊号是:[C%d],",getRegisteredNumber(C));
printf("当前挂号人数为%d\n",C->number);
} else {
printf("输入有误\n");
return;
}
}
/*
添加病人进队列的具体操作
*/
void addSickDetail(Queue *queue,Pionter *piont,int number)
{
//输入预诊号,将其加入队列当中
queue = (Queue*)malloc(sizeof(Queue));
//如果rear为NULL时,代表队列为空
if(piont->rear == NULL && piont->front == NULL) {
queue->number = number;//为第一个添加的数据赋值
piont->rear = queue;//将rear指向第一个添加的数据
piont->front = queue;//将front也指向第一个添加的数据
queue->next = NULL;
}else {
queue->number = number;
piont->rear->next = queue;
piont->rear = queue;
queue->next = NULL;
}
}
bool isExit(Queue *queue,Pionter *piont,int number)
{
Queue *head = piont->front;//指向队列头的指针
if(head == NULL) {
return 0;
}
while(head != NULL) {
if(number == head->number) {
return 1;
}
head = head->next;
}
}
/*
*添加病人进队列
*/
void addSick()
{
char department;//科室
char word[5];
int number;
printf("请输入您的诊室(A-儿科/B-外科/C内科)\n");
scanf("%c",&department);
getchar();//缓冲区
//通过toupper函数实现无论用户输入大小写都可以自动转换成大写,防止用户输入性错误
department = toupper(department);
if(department == 'A') {
printf("请输入您的预诊号\n");
scanf("%s",&word);
word[0] = toupper(word[0]);
char *d = strtok(word,"A");
number = atoi(d);
if(number > 0 && number <= A->count) {
if(isExit(queueA,piontA,number) ) {
printf("您输入的预诊号已存在\n");
} else {
addSickDetail(queueA,piontA,number);
printf("添加成功\n");
}
}
else {
printf("您输入的预诊号不存在\n");
return;
}
}else if(department == 'B') {
printf("请输入您的预诊号\n");
scanf("%s",&word);
word[0] = toupper(word[0]);
char *d = strtok(word,"B");
number = atoi(d);
if(number > 0 && number <= B->count) {
if(isExit(queueB,piontB,number) ) {
printf("您输入的预诊号已存在\n");
} else {
addSickDetail(queueB,piontB,number);
printf("添加成功\n");
}
}
else {
printf("您输入的预诊号不存在\n");
return;
}
} else if(department == 'C') {
printf("请输入您的预诊号\n");
scanf("%s",&word);
word[0] = toupper(word[0]);
char *d = strtok(word,"C");
number = atoi(d);
if(number > 0 && number <= C->count) {
if(isExit(queueC,piontC,number) ) {
printf("您输入的预诊号已存在\n");
} else {
addSickDetail(queueC,piontC,number);
printf("添加成功\n");
}
}
else {
printf("您输入的预诊号不存在\n");
return;
}
}else {
printf("您输入的有误,请重新输入\n");
return;
}
}
/*
*弹出病人出队列的具体操作
*/
int popSickDetail(Queue *queue,Pionter *piont,List *list)
{
Queue *head = piont->front;//指向队列头的指针
Queue *foot = piont->rear;//指向队列尾的指针
int number;
//如果front和rear的地址一样说明队列中只有一个元素
if(head == NULL) {
printf("排队为空,无法就诊\n");
return 0;
}
//说明队列中只有一个元素
if(foot == head) {
number = foot->number;
piont->front = piont->rear = NULL;
free(head);
list->number--;
} else {
number = piont->front->number;
piont->front = piont->front->next;
free(head);
list->number--;
}
return number;
}
/*
*就诊-弹出队列最前面的元素
*@return
*/
void popSick()
{
char department;
int sickNumber;
printf("请输入您的诊室(A-儿科/B-外科/C内科)\n");
scanf("%c",&department);
getchar();
department = toupper(department);
if(department == 'A') {
sickNumber = popSickDetail(queueA,piontA,A);
if(sickNumber != 0) {
printf("请A%d号患者就诊\n",sickNumber);
}
} else if(department == 'B') {
sickNumber = popSickDetail(queueB,piontB,A);
if(sickNumber != 0) {
printf("请B%d号患者就诊\n",sickNumber);
}
} else if(department == 'C') {
sickNumber = popSickDetail(queueC,piontC,A);
if(sickNumber != 0) {
printf("请C%d号患者就诊\n",sickNumber);
}
} else {
printf("您输入的有误,请重新输入\n");
return;
}
}
/*
*打印队列的具体操作
*/
void printQueueDetail(Pionter *piont,char department)
{
//通过Pionter结构体,通过front&rear可以遍历链队列
Queue *head = piont->front;
if(head == NULL) {
printf("排队为空,无法查看排队\n");
return;
}
printf("%c诊室的排队为\n",department);
while(head != NULL) {
printf("%c%d\t",department,head->number);
head = head->next;
}
printf("\n");
}
/*
*查看排队-打印队列
*@return void
*/
void printQueue()
{
char department;
int number;
printf("请输入您的诊室(A-儿科/B-外科/C内科)\n");
scanf("%c",&department);
getchar();
department = toupper(department);
if(department == 'A') {
printQueueDetail(piontA,department);
} else if(department == 'B') {
printQueueDetail(piontB,department);
} else if(department == 'C') {
printQueueDetail(piontC,department);
} else {
printf("您输入的有误,请重新输入\n");
return;
}
}
/*
*初始化链队列
@return void
*/
void initQueue()
{
//初始化指向队列头和尾的指针
piontA = (Pionter*)malloc(sizeof(Pionter));
piontA->front = NULL;
piontA->rear = NULL;
piontB = (Pionter*)malloc(sizeof(Pionter));
piontB->front = NULL;
piontB->rear = NULL;
piontC = (Pionter*)malloc(sizeof(Pionter));
piontC->front = NULL;
piontC->rear = NULL;
//初始化list结构体
A = (List*)malloc(sizeof(List));
B = (List*)malloc(sizeof(List));
C = (List*)malloc(sizeof(List));
A->count = 0;
A->number = 0;
B->count = 0;
B->number = 0;
C->count = 0;
C->number = 0;
}
/*
*视窗函数
*@return void
*/
void view()
{
initQueue();//初始化操作
while(true)
{
printf("---------------------------------------\n");
printf("| 欢迎来到病人就医管理系统 |\n");
printf("---------------------------------------\n");
printf("| 1.挂号 |\n");
printf("| 2.排队 |\n");
printf("| 3.就诊 |\n");
printf("| 4.查看排队 |\n");
printf("| 5.下班 |\n");
printf("| 请选择(1,2,3,4,5) |\n");
printf("---------------------------------------\n");
int choice;
char *scanner;
printf("请输入:\n");
fflush(stdin);//清除缓冲区字符
scanf("%c",scanner);
getchar();//缓冲区
choice = atoi(scanner);
if(!(choice >= 1 && choice <= 5)) {
printf("您的输入有误\n");
continue;
}
switch(choice){
//挂号-initQueue
case 1:
registered();
break;
//排队-addSick
case 2:
addSick();
break;
//就诊-popSick
case 3:
popSick();
break;
//查看排队-printQueue
case 4:
printQueue();
break;
//下班-退出程序
case 5:
exit(0);
break;
default:
printf("输入有误,请重新输入\n");
break;
}
}
}
//主函数
int main()
{
view();
}
程序运行结果如下:
Sept1:病人进入医院挂号
Sept2:病人挂号后,排队。
Sept3:病人排队时观看排队情况
Sept4:病人就诊文章来源:https://www.toymoban.com/news/detail-758162.html
文章来源地址https://www.toymoban.com/news/detail-758162.html
到了这里,关于基于链队列的病人就医管理系统(数据结构实训)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!