C語言實(shí)現(xiàn)醫(yī)院管理系統(tǒng)
這個(gè)是C語言學(xué)完后的一個(gè)程序?qū)嵺`的內(nèi)用。編寫一個(gè)醫(yī)院病人管理系統(tǒng)。這個(gè)程序有一些BUG,要操作得當(dāng),否則可能結(jié)果有問題。不過作為作業(yè)應(yīng)付一下還是有模有樣的。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct patient
{
char ID[10];
char name[10];
char bingli[300];
int cost[3];
struct patient * next;
}node1;
typedef struct storage
{
int amount[3];
int price[3];
}node2;
node2 init(node2 temp)
{
temp.amount[0]=20;
temp.amount[1]=20;
temp.amount[2]=10;
temp.price[0]=5;
temp.price[1]=9;
temp.price[2]=16;
return temp;
}
void mainmeun()
{
printf("\n");
printf(" 健康是快樂的源泉\n");
printf("********************************\n");
printf("1.注冊(cè)新病人信息\n");
printf("2.查詢病人信息\n");
printf("3.寫病歷\n");
printf("4.病人消費(fèi)\n");
printf("5.列出所有病人信息\n");
printf("6.載入所有病人信息\n");
printf("7.保存\n");
printf("8.查詢藥品庫存\n");
printf("9.離開\n");
printf("*********************************\n");
}
node1 * create(node1 *p1)
{
node1 *p;
p=(node1 *)malloc(sizeof(node1));
printf("請(qǐng)輸入病人ID\n");
scanf("%s",p->ID);
while(p1->ID&&strcmp(p1->ID,p->ID))
{
p1=p1->next;
}
if(p1==NULL)
{
printf("請(qǐng)輸入病人姓名\n");
scanf("%s",p->name);
strcpy(p->bingli,"0");
p->cost[0]=0;
p->cost[1]=0;
p->cost[2]=0;
p->next=NULL;
printf("已注入您的信息\n");
return p;
}
else
{
printf("輸入病人ID以存在,注冊(cè)失敗\n");
return p;
}
}
node1 * insert(node1 * head,node1 *p)
{
node1 *p1;
if(head==NULL)
{
head=p;
p->next=NULL;
}
else
{
p1=head;
while(p1->next)
{
p1=p1->next;
}
p1->next=p;
p->next=NULL;
}
return(head);
}
void search(node1 *p1)
{
int sum;
char a[10];
printf("請(qǐng)輸入病人ID\n");
scanf("%s",a);
while(p1->ID&&strcmp(p1->ID,a))
{
p1=p1->next;
}
if(p1)
{
printf("ID:%s\n",p1->ID);
printf("姓名:%s\n",p1->name);
printf("病例:%s\n",p1->bingli);
printf("消費(fèi)記錄:\n");
if(p1->cost[0])
printf("巴米爾\t%d\n",p1->cost[0]);
if(p1->cost[1])
printf("感冒靈\t%d\n",p1->cost[1]);
if(p1->cost[2])
printf("病毒靈\t%d\n",p1->cost[2]);
sum=p1->cost[0]*5+p1->cost[1]*9+p1->cost[2]*16;
printf("總費(fèi)用\t%d\n",sum);
}
else
printf("該病人沒有注冊(cè)\n");
}
void bingli(node1 *p)
{
char a[10];
char bingli[300];
char enter[5]=":\n";
printf("請(qǐng)輸入病人ID\n");
scanf("%s",a);
while(p->ID&&strcmp(p->ID,a))
{
p=p->next;
}
if(p==NULL)
{
printf("無該病人信息\n");
}
else
{
printf("請(qǐng)寫病例:\n");
scanf("%s",bingli);
strcpy(p->bingli,bingli);
strcat(p->bingli,enter);
}
}
node2 buy(node1 *p,node2 temp)
{
char i[10];
printf("請(qǐng)輸入病人ID\n");
scanf("%s",i);
while(p->ID&&strcmp(p->ID,i))
{
p=p->next;
}
while(1)
{
int a,b,c,d;
printf("1.購(gòu)買巴米爾\n");
printf("2.購(gòu)買感冒靈\n");
printf("3.購(gòu)買病毒靈\n");
printf("0.退出\n");
scanf("%d",&a);
switch(a)
{
case 1:
do
{
printf("現(xiàn)有庫存%d\n",temp.amount[0]);
printf("購(gòu)買巴米爾數(shù)量:");
scanf("%d",&b);
temp.amount[0]=temp.amount[0]-b;
p->cost[0]+=b*5;
}while(b>20);
break;
case 2:
do
{
printf("現(xiàn)有庫存%d\n",temp.amount[1]);
printf("購(gòu)買感冒靈數(shù)量:");
scanf("%d",&c);
temp.amount[1]=temp.amount[1]-c;
p->cost[1]+=c*9;
}while(c>20);
break;
case 3:
do
{
printf("現(xiàn)有庫存%d\n",temp.amount[2]);
printf("購(gòu)買病毒靈數(shù)量:");
scanf("%d",&d);
temp.amount[2]=temp.amount[2]-d;
p->cost[2]+=d*16;
}while(d>=10);
break;
case 0:
return temp;
}
}
}
void list(node1 *p)
{
if(p==NULL)
printf("尚無病人信息\n");
else
{
do{
printf("病人ID:%s\n",p->ID);
printf("病人姓名:%s\n",p->name);
printf("病人病例:%s\n",p->bingli);
printf("購(gòu)買巴米爾費(fèi)用:%d\n",p->cost[0]);
printf("購(gòu)買感冒靈費(fèi)用:%d\n",p->cost[1]);
printf("購(gòu)買病毒靈費(fèi)用:%d\n",p->cost[2]);
printf("\n");
p=p->next;
}while(p!=NULL);
}
}
node1 * load(node1 *p)
{
char ID[10],name[10],bingli[300];
int cost0,cost1,cost2;
FILE *fp;
fp=fopen("information.txt","r");
int n=0;
node1 *p1,*p2;
while(!feof(fp))
{
n++;
p1=(node1 *)malloc(sizeof(node1));
fscanf(fp,"%s",ID);
fscanf(fp,"%s",name);
fscanf(fp,"%s",bingli);
fscanf(fp,"%d",&cost0);
fscanf(fp,"%d",&cost1);
fscanf(fp,"%d",&cost2);
strcpy(p1->ID,ID);
strcpy(p1->name,name);
strcpy(p1->bingli,bingli);
p1->cost[0]=cost0;
p1->cost[1]=cost1;
p1->cost[2]=cost2;
p1->next=NULL;
if(n==1)
{
p=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}
}
fclose(fp);
return p;
}
void save(node1 *p)
{
FILE *fp;
fp=fopen("information.txt","w");
if(p!=NULL)
do{
fprintf(fp,"%s\n",p->ID);
fprintf(fp,"%s\n",p->name);
fprintf(fp,"%s\n",p->bingli);
fprintf(fp,"%d\n",p->cost[0]);
fprintf(fp,"%d\n",p->cost[1]);
fprintf(fp,"%d\n",p->cost[2]);
p=p->next;
}while(p!=NULL);
fclose(fp);
}
void liststock(node2 temp)
{
printf("藥品\t數(shù)量\t價(jià)格\t\n");
printf("巴米爾\t%d\t%d\t\n",temp.amount[0],temp.price[0]);
printf("感冒靈\t%d\t%d\t\n",temp.amount[1],temp.price[1]);
printf("病毒靈\t%d\t%d\t\n",temp.amount[2],temp.price[2]);
}
chose()
{
node1 *head=NULL,*p;
node2 temp;
temp=init(temp);
while(1)
{
mainmeun();
int a;
scanf("%d",&a);
switch(a)
{
case 1:
p=create(head);
head=insert(head,p);
break;
case 2:
search(head);
break;
case 3:
bingli(head);
break;
case 4:
temp=buy(head,temp);
break;
case 5:
list(head);
break;
case 6:
head=load(head);
break;
case 7:
save(head);
break;
case 8:
liststock(temp);
break;
case 9:
printf("謝謝使用\n");
return(0);
default:
printf("輸入有誤,重新輸入\n");
break;
}
}
}
void main()
{
chose();
}
運(yùn)行時(shí)的截圖,由于模塊太多,就看看主頁面吧。

更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C語言學(xué)生管理系統(tǒng)源碼分享
- C語言通訊錄管理系統(tǒng)完整版
- C語言實(shí)現(xiàn)圖書管理系統(tǒng)
- C語言編寫學(xué)生成績(jī)管理系統(tǒng)
- C語言職工管理系統(tǒng)設(shè)計(jì)
- C語言職工信息管理系統(tǒng)源碼
- C語言圖書管理系統(tǒng)簡(jiǎn)潔版
- C語言數(shù)據(jù)結(jié)構(gòu)之學(xué)生信息管理系統(tǒng)課程設(shè)計(jì)
- C語言利用結(jié)構(gòu)體數(shù)組實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
- 學(xué)生成績(jī)管理系統(tǒng)C語言代碼實(shí)現(xiàn)
相關(guān)文章
C++ 標(biāo)準(zhǔn)模板庫 STL 順序容器詳解
這篇文章主要介紹了C++ 標(biāo)準(zhǔn)模板庫 STL 順序容器詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-05-05
C++ const限定符以及頂層const和底層const的案例詳解
這篇文章主要介紹了C++ const限定符以及頂層const和底層const的案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09
基于VC中使用ForceInclude來強(qiáng)制包含stdafx.h的解決方法
本篇文章是對(duì)VC中使用ForceInclude來強(qiáng)制包含stdafx.h的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C語言多線程服務(wù)器的實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了C語言多線程服務(wù)器的實(shí)現(xiàn)實(shí)例,文章用實(shí)例講解的很清楚,有對(duì)這方面不太懂的同學(xué)可以參考下2021-02-02
C++?超詳細(xì)分析多態(tài)的原理與實(shí)現(xiàn)
這篇文章主要介紹了C++多態(tài)的原理與實(shí)現(xiàn),多態(tài)是一種面向?qū)ο蟮脑O(shè)計(jì)思路,本身和C++不是強(qiáng)綁定的,其他語言當(dāng)中一樣有多態(tài),只不過實(shí)現(xiàn)的方式可能有所不同。下面來一起了解更多詳細(xì)內(nèi)容吧2022-03-03
詳解C++中的指針結(jié)構(gòu)體數(shù)組以及指向結(jié)構(gòu)體變量的指針
這篇文章主要介紹了C++中的指針結(jié)構(gòu)體數(shù)組以及指向結(jié)構(gòu)體變量的指針的用法,是C++入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-09-09

