C语言版医院管理系统 C语言版医院管理系统

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

C语言版医院管理系统 C语言版医院管理系统

qjb742615041   2021-03-30 我要评论

#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "malloc.h"
#define NULL 0
typedef struct
{ int num;
 char name[10];
 int age;
 char sex;
}people; //一个患者的信息

typedef struct Node
 {
 people *data;
 struct Node *next;
 }queue; // 定义队列结构体

typedef struct
{
 queue *front;
 queue *rear;
}linkqueue; //定义队列指针

int Initqueue(linkqueue *q) //初始化队列
{
 q->front=(queue *)malloc(sizeof(queue));
 if(q->front!=NULL)
 {
 q->rear=q->front;
 q->front->next=NULL;
 return 1;
 }
 else return 0;
}

int Isempty(linkqueue *Q)
{
 if(Q->front==Q->rear)
 return 1;
 else return 0;
}

int Enterqueue(linkqueue *Q,people *x)
{ 
 /* 将数据元素x插入到队列Q中 */
 queue *NewNode;
 NewNode=(queue * )malloc(sizeof(queue));
 if(NewNode!=NULL)
 {
 NewNode->data=x;
 NewNode->next=NULL;
 Q->rear->next=NewNode;
 Q->rear=NewNode;
 return(1);
 }
 else return(0); /* 溢出!*/
}

/*出队操作。*/
people *Deletequeue(linkqueue *Q)/* 将队列Q的队头元素出队,并存放到x所指的存储空间中 */
{ 
 people *x;
 queue *p;
 p=Q->front->next;
 Q->front->next=p->next; /* 队头元素p出队 */
 if(Q->rear==p) /* 如果队中只有一个元素p,则p出队后成为空队 */
 Q->rear=Q->front; 
 x=p->data;
 free(p); /* 释放存储空间 */
 return x; 
}


void main()

{ int s,y,flag=1;//s接收病历号,y接收年龄,flag控制循环次数。
 char mz[10],d,choice;//mz[]接收姓名,d接收性别,
 people *x;
 linkqueue Q;
 Initqueue(&Q);
 printf("   *************医院看病管理系统***************\n");
 printf("   *           *\n");
 printf("   *   1 : 病人到达时请输入   *\n");
 printf("   *           *\n");
 printf("   *   2 : 一位患者就医时,请输入  *\n");
 printf("   *           *\n");
 printf("   *   3 : 不再接收病人时,请输入  *\n");
 printf("   *           *\n");
 printf("   *   0 : 退出系统,请输入:   *\n");
 printf("   *           *\n");
 printf("   ********************************************\n");
 while(flag)
 {
 printf("请输入命令:");
  flushall();
 scanf("%c",&choice); 
 switch(choice) 
 {
  case'1':people r;
  printf("\n请输入病历号:");
   scanf("%d",&s);
  r.num=s;
  printf("姓名:");
  scanf("%s",&mz);
  strcpy(r.name,mz);
  printf("性别:");
  flushall(); //程序缓冲空间函数
  scanf("%c",&d);
  r.sex=d;
  printf("年龄:");
       scanf("%d",&y);
   r.age=y;
  Enterqueue(&Q,&r);
  break; 
  case'2':if(!Isempty(&Q))
  
  { x=Deletequeue(&Q);
  printf("\n  %d号病人就诊!",x->num);
  }
  else printf("\n病人已全部被医治完了!");
  break;
  case'3':printf("\n今天停止挂号,请下列病人依次就诊:");
   while(!Isempty(&Q))
  {
   x=Deletequeue(&Q);
   printf("%d号 ",x->num);
  }
  flag=0;
  break;
  case'0':break;
  default:printf("非法命令!");
 }
  }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们