(1)数据结构类型:链式队列
(2)分析:病人排队,医生看诊要先来排队的优先看病,满足数据结构中的“先进先出”原则,所以要选用队列。但由于人数不定,所以不适合用顺序存储队列,而链式队列较合适。
(3)数据结构类型定义:
struct patient {
char name[20];
char sex[10];
int age;
char address[20];
char telephone[12];
};
typedef struct node {
struct patient pat;
struct node *next;
}Node,*queNode;
typedef struct queue {
queNode font; // 链队列的头指针
queNode rear; // 指向队列的最后一个元素
}linkQue,*linkQueue;
linkQueue initQueue() /创建一个空队列/
int emptyQueue(linkQueue q) /判断队列是否为空/
void regist() /登记病人的信息/
void enterQueue(linkQueue q,struct patient pa,int priority) /病人 入队/
int outQueue(linkQueue q) /医生看诊 出队/
void deletePatient(linkQueue q,char name[]) /根据病人的姓名在队列中删除他/
void searchPatient() /查询挂号的病人信息/
void searchKeshi() /查询科室信息/
void getOrder(linkQueue q,char name[]) /根据病人的姓名查询在队列中的次序/
void printShengyu() /显示剩余排队人数/
void printJiuzhen() /显示当天就诊人数/
void sort() /降序显示不同科室当天门诊病人数/
void income() /统计当天挂号收费情况/
void menu() /主菜单函数/
#include#include #include #include struct patient { char name[20]; char sex[10]; int age; char address[20]; char telephone[12]; }; typedef struct node { struct patient pat; struct node *next; }Node,*queNode; typedef struct queue { queNode font; // 链队列的头指针 queNode rear; // 指向队列的最后一个元素 }linkQue,*linkQueue; struct zhenshi { char bks[20]; int num; char ysm[20]; }; struct doctor { char nam[20]; char statu[20]; int fare; }; struct person { char name[20]; char sex[10]; int age; char address[20]; char telephone[12]; char keshi[20]; char type[20]; }; int surgerySum1 = 0; //外科普通号 挂号人数 ,为了统计挂号费 int surgerySum2 = 0; //外科专家号 挂号人数 int neikeSum1 = 0; //内科普通号 挂号人数 int neikeSum2 = 0; //内科专家号 挂号人数 int surgery1 = 0; //外科普通号 就诊人数 int surgery2 = 0; //外科专家号 就诊人数 int neike3 = 0; //内科普通号 就诊人数 int neike4 = 0; //内科专家号 就诊人数 int sur1 = 0; //外科普通号 放弃人数 int sur2 = 0; //外科专家号 放弃人数 int nei3 = 0; //内科普通号 放弃人数 int nei4 = 0; //内科专家号 放弃人数 linkQueue initQueue() { linkQueue q = (linkQueue)malloc(sizeof(linkQue)); q->font = (queNode)malloc(sizeof(Node)); q->font->next = NULL; q->rear = q->font; return q; } linkQueue surgeryQue1; //外科普通号队列 linkQueue surgeryQue2; //外科专家号队列 linkQueue neikeQue3; //内科普通号队列 linkQueue neikeQue4; //内科专家号队列 int emptyQueue(linkQueue q) { if(q->rear == q->font) { return 0; // 队空 } else { return 1; } } void getOrder(linkQueue q,char name[]) { int no=0,flag=0; queNode temp = q->font->next; while(temp != NULL) { no++; if(strcmp(temp->pat.name,name) != 0) { temp = temp->next; } else { flag = 1; printf(" 病人目前在队列中的位置是:"); printf("%dn",no); break; } } if(flag == 0) { printf("n 该病人已经离队!n"); } Sleep(3000); } void deletePatient(linkQueue q,char name[]) { queNode temp = q->font; while(temp->next != NULL) { if(strcmp(temp->next->pat.name,name) == 0) { queNode p = temp->next; temp->next = p->next; free(p); break; } else { temp = temp->next; } } } void searchPatient() { int sum = surgerySum1 + surgerySum2 + neikeSum1 + neikeSum2; struct person p[sum]; FILE *fp; if((fp=fopen("E:\Codefield\C-code\C-single\patients.txt","r")) == NULL) { printf(" 文件打开失败!n"); return; } int i; for(i=0; i pat = pa; if(priority == 1) { temp->next = q->font->next; q->font->next = temp; if(emptyQueue(q) == 0) { q->rear = temp; } } else { temp->next = NULL; q->rear->next = temp; q->rear = temp; } } int outQueue(linkQueue q) { if(emptyQueue(q) == 0) { printf(" 当前没有人排队,无须看诊!n"); Sleep(2000); return 0; } queNode temp = q->font->next; q->font->next = temp->next; printf(" 病人看诊中.......n"); Sleep(3000); if(temp == q->rear) { q->rear = q->font; } free(temp); printf(" 该病人就诊完毕!n"); Sleep(2000); return 1; } void regist() { FILE *fp; if((fp=fopen("E:\Codefield\C-code\C-single\patients.txt","a")) == NULL) { printf(" 文件打开失败!n"); return; } struct patient per; printf("n"); printf(" 请登记病人的基本信息:nn"); printf(" 姓名、性别、年龄、家庭地址、电话nn"); printf(" 姓名:"); scanf("%s",per.name); printf("n"); printf(" 性别:"); scanf("%s",per.sex); printf("n"); printf(" 年龄:"); scanf("%d",&per.age); printf("n"); printf(" 家庭地址:"); scanf("%s",per.address); printf("n"); printf(" 电话:"); scanf("%s",per.telephone); fprintf(fp,"%s %s %d %s %s ",per.name,per.sex,per.age,per.address,per.telephone); printf(" =======================================================n"); printf(" 1.外科 2.内科 nn"); int keshi,zhenshi,pri; printf(" 请选择科室:"); scanf("%d",&keshi); switch(keshi) { case 1: printf(" =======================================================n"); printf(" 普通号诊室:1 专家号诊室:2 nn"); printf(" 请选择诊室:"); scanf("%d",&zhenshi); printf(" =======================================================n"); printf(" 1.急诊 2.普通门诊 nn"); printf(" 请选择病情状况:"); scanf("%d",&pri); if(zhenshi == 1) { surgerySum1++; enterQueue(surgeryQue1,per,pri); fprintf(fp,"%s %sn","外科","普通号"); } else { surgerySum2++; enterQueue(surgeryQue2,per,pri); fprintf(fp,"%s %sn","外科","专家号"); } break; case 2: printf(" =======================================================n"); printf(" 普通号诊室:3 专家号诊室:4 nn"); printf(" 请选择诊室:"); scanf("%d",&zhenshi); printf(" =======================================================n"); printf(" 1.急诊 2.普通门诊 nn"); printf(" 请选择病情状况:"); scanf("%d",&pri); if(zhenshi == 3) { neikeSum1++; enterQueue(neikeQue3,per,pri); fprintf(fp,"%s %sn","内科","普通号"); } else { neikeSum2++; enterQueue(neikeQue4,per,pri); fprintf(fp,"%s %sn","内科","专家号"); } break; } fclose(fp); printf("n 登记成功!n"); Sleep(3000); return; } void printShengyu() { printf("n =======================================n"); printf(" 外科普通号诊室1 剩余排队人数: %dnn",surgerySum1-surgery1-sur1); printf(" 外科专家号诊室2 剩余排队人数: %dnn",surgerySum2-surgery2-sur2); printf(" 内科普通号诊室3 剩余排队人数: %dnn",neikeSum1-neike3-nei3); printf(" 内科专家号诊室4 剩余排队人数: %dnn",neikeSum2-neike4-nei4); printf(" ======================================n"); Sleep(3000); } void printJiuzhen() { printf("n ========================================n"); printf(" 外科 内科n"); printf(" ----------------------------------------n"); printf(" 就诊人数 %d %dn",surgery1+surgery2,neike3+neike4); printf("n ========================================n"); Sleep(3000); } void income() { struct zhenshi zs[4]; struct doctor dt[4]; FILE *fp; if((fp=fopen("E:\Codefield\C-code\C-single\zhenshi.txt","r")) == NULL) { printf(" 文件打开失败!n"); return; } int i,j; for(i=0; i<4; i++) { fscanf(fp,"%s %d %sn",zs[i].bks,&zs[i].num,zs[i].ysm); } fclose(fp); if((fp=fopen("E:\Codefield\C-code\C-single\yisheng.txt","r")) == NULL) { printf(" 文件打开失败!n"); return; } for(i=0; i<4; i++) { fscanf(fp,"%s %s %dn",dt[i].nam,dt[i].statu,&dt[i].fare); } fclose(fp); int fei[4]; for(i=0; i<4; i++) { for(j=0; j<4; j++) { if(strcmp(zs[i].ysm,dt[j].nam) == 0) { fei[i] = dt[j].fare; break; } } } printf("n ======================================n"); printf(" 科室 挂号收费n"); printf(" --------------------------------------n"); printf(" 外科普通号 %dnn",surgerySum1*fei[0]); printf(" 外科专家号 %dnn",surgerySum2*fei[1]); printf(" 内科普通号 %dnn",neikeSum1*fei[2]); printf(" 内科专家号 %d",neikeSum2*fei[3]); printf("n ======================================n"); Sleep(3000); } void sort() { struct mz { char mzm[20]; int rens; }; struct mz arr[4] = {{"外科普通号",surgerySum1},{"外科专家号",surgerySum2},{"内科普通号",neikeSum1},{"内科专家号",neikeSum2}}; int i,j,k; struct mz t; for(i=0; i<4; i++) { k=i; for(j=i+1; j<4; j++) { if(arr[j].rens > arr[k].rens) k = j; } if(k!=i) { t = arr[i]; arr[i] = arr[k]; arr[k] = t; } } printf("n =========================================n"); printf(" 科室 门诊人数n"); printf(" -----------------------------------------n"); printf(" %s %dnn",arr[0].mzm,arr[0].rens); printf(" %s %dnn",arr[1].mzm,arr[1].rens); printf(" %s %dnn",arr[2].mzm,arr[2].rens); printf(" %s %d",arr[3].mzm,arr[3].rens); printf("n =========================================n"); Sleep(3000); } void menu() { char menu[] = { "nn" " ---------------------------------------------------------------------------------n" " **********************************************************************************n" " ** 欢迎使用××医院挂号系统 **n" "n" " ** 1. 登记病人信息 **n" "n" " ** 2. 医生为病人进行诊治 **n" "n" " ** 3. 病人放弃看病,从队列中删除 **n" "n" " ** 4. 查询病人信息 **n" "n" " ** 5. 查询科室信息 **n" "n" " ** 6. 查询某一病人在队列中的次序 **n" "n" " ** 7. 各诊室的剩余排队人数 **n" "n" " ** 8. 显示各科室当天就诊人数 **n" "n" " ** 9. 统计各科室当天的挂号收费情况 **n" "n" " ** 10. 降序显示各诊室当天门诊人数 **n" "n" " ** 0. 退出系统 **n" " **********************************************************************************n" " ---------------------------------------------------------------------------------nn" }; int select; do { printf("%s",menu); printf(" 请按编号选择相应的 *** 作: "); scanf("%d",&select); switch(select) { case 1: regist(); break; case 2: printf("n"); int z; printf(" 请选择要看诊的诊室号:1、2、3、4、 n"); printf(" 诊室号:"); scanf("%d",&z); switch(z) { case 1: surgery1 += outQueue(surgeryQue1); break; case 2: surgery2 += outQueue(surgeryQue2); break; case 3: neike3 += outQueue(neikeQue3); break; case 4: neike4 += outQueue(neikeQue4); break; } break; case 3: printf("n"); int zsh; char mingzi[20]; printf(" 请选择要放弃排队病人的诊室号:1、2、3、4、 n"); printf(" 诊室号:"); scanf("%d",&zsh); printf(" 请输入病人的姓名:"); scanf("%s",mingzi); switch(zsh) { case 1: deletePatient(surgeryQue1,mingzi); sur1++; break; case 2: deletePatient(surgeryQue2,mingzi); sur2++; break; case 3: deletePatient(neikeQue3,mingzi); nei3++; break; case 4: deletePatient(neikeQue4,mingzi); nei4++; break; } printf(" 该病人放弃看病,成功离队!n"); Sleep(2000); break; case 4: searchPatient(); break; case 5: searchKeshi(); break; case 6: printf("n"); int zs; char ming[20]; printf(" 请选择要查询病人次序的诊室号:1、2、3、4、 n"); printf(" 诊室号:"); scanf("%d",&zs); printf(" 请输入病人的姓名:"); scanf("%s",ming); switch(zs) { case 1: getOrder(surgeryQue1,ming); break; case 2: getOrder(surgeryQue2,ming); break; case 3: getOrder(neikeQue3,ming); break; case 4: getOrder(neikeQue4,ming); break; } break; case 7: printShengyu(); break; case 8: printJiuzhen(); break; case 9: income(); break; case 10: sort(); break; } }while(select!=0); } int main() { system("title xxx医院挂号系统"); system("color FD");//设置系统背景色和前景色 system("mode 100,30"); surgeryQue1 = initQueue(); surgeryQue2 = initQueue(); neikeQue3 = initQueue(); neikeQue4 = initQueue(); menu(); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)