本文實例為大家分享了C語言實現醫院管理系統的具體代碼,供大家參考,具體內容如下
#include "stdio.h"#include "string.h"#include "stdlib.h"#include "malloc.h"#define NULL 0typedef 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("非法命令!"); } }}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答
圖片精選