C语言程序设计医院信息管理系统附源代码.docx

上传人:b****5 文档编号:6840616 上传时间:2023-01-11 格式:DOCX 页数:22 大小:75.39KB
下载 相关 举报
C语言程序设计医院信息管理系统附源代码.docx_第1页
第1页 / 共22页
C语言程序设计医院信息管理系统附源代码.docx_第2页
第2页 / 共22页
C语言程序设计医院信息管理系统附源代码.docx_第3页
第3页 / 共22页
C语言程序设计医院信息管理系统附源代码.docx_第4页
第4页 / 共22页
C语言程序设计医院信息管理系统附源代码.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

C语言程序设计医院信息管理系统附源代码.docx

《C语言程序设计医院信息管理系统附源代码.docx》由会员分享,可在线阅读,更多相关《C语言程序设计医院信息管理系统附源代码.docx(22页珍藏版)》请在冰豆网上搜索。

C语言程序设计医院信息管理系统附源代码.docx

C语言程序设计医院信息管理系统附源代码

专业设计报告

 

课程名称:

C语言程序设计

课题名称:

医院信息管理系统

专业班别:

12本计算机科学与技术二班

姓名:

学号:

指导教师:

设计日期:

2012-5-25

 

 

教师评语:

等级

项目

及格

专业设计目的

设计基本要求

算法分析

源程序代码

源程序代码测试

设计总结

 

成绩评定:

指导教师签名:

日期:

2012年月日

 

课程设计题目医院信息管理程序

作者姓名:

同组成员:

摘要利用结构体存储每个病人的信息和每种药品的信息,并使用链表存储全部病人的信息;能完成对医院内所有病人信息的注册、查询、删除和修改等操作,同时又能对药房内库存的药品进行查询;可以将链表中的病人信息保存在文件中,并且可以对文件中的病人信息进行读取与显示

1.专业设计目的

1、掌握链表的操作,包括链表节点的创建、释放还有链表的遍历

2、掌握对二进制文件的创建、增添等基本操作。

3、熟悉C语言函数的使用方法,学会模块化处理问题以及多个源文件的处理方式

2.设计基本要求(

1、使用结构体来存储病人的信息,结构体中包括病的id号码、姓名、病历以及消费信息,并用链表将所有病人信息整合。

2、用文件来存储链表的信息以便下次再使用该程序时载入病人信息

3、能够实现病人信息的注册、病人信息的查询、病人消费统计、保存链表信息、载入链表信息、查询库存等几项功能。

4、要求用四个源文件main.c、link.c、find.c、save_load.c

5、系统完成后应实现类似下面所示界面

 

3、算法分析

1、数据结构

设计链表中的一个节点存储一个病人的信息,使用下面的结构体类型定义:

structpatient{

charid[10];

charname[10];

charcasehist[200];

intcost[3];

inttransfusion;

intsurgery;

structpatient*next;

};

其中cost数组用来存储病人卖药的的个数(总共三种药),casehist存储病历内容,transfusion用来存储病人输液的花费,surgery存储手术的花费。

Structpatient*next用来指向下一个病人结构体的起始地址从而形成一个链表。

此外还要用到一个结构体来存储库存中当前的药品情况。

structstorage{

intamount[3];

intprice[3];

};

2、函数定义

程序代码有main.c、link.c、find.c、save_load.c四个源文件组成,使用头文件head.h把四个源文件连接起来,四个文件中所包含的函数说明如表所示。

源文件

函数原型

功能说明

 

Main.c

 

voidtest()

检测有无存储病人的二进制文件

voidinit(structstorage*temp)

初始化库存中的药品,参数为指向structstorage类型的指针

voidprintmenu()

打印提示菜单

Voidliststock(structstoragetemp)

列出库存中的药品

structpatient*enroll()

注册新病人信息

voidfreeall(structpatient*temp)

清除链表内容,参数为指向structpatient类型的指针

 

Find.c

voidsearch(structpatient*temp)

查询单个病人的信息,参数为指向structpatient类型的指针

voidlistall(structpatient*temp)

列出所有病人的信息,参数为指向structpatient类型的指针

 

Link.c

structpatient*insert(structpatient*head,structpatient*rea

加入新节点,参数为指向structpatient类型的指针

voidmodify(structpatient*temp)

修改病人病历,参数为指向structpatient类型的指针

voidbuy(structpatient*temp,structstorage*s)

/用于病人的消费处理,参数为指向structpatient类型的指针与指向structstorage的指针

Save_load.c

voidsave(structpatient*head)

将链表信息保存到文件中,参数为指向structpatient类型的指针

structpatient*load(structpatient*head)

将文件信息写入到链表中,参数为指向structpatient类型的指针

3、处理过程

(1)检查存储病人信息的文件是否存在,若不存在则创建一个新文件并设置flag值为1,以标记现在可以对链表进行操作。

(2)初始化库存令巴米尔、感冒灵、病毒唑3种药的数量分别为20、20、10,价格分别为5、9、16。

(3)输出提示菜单让用户悬着要操作的项目.

1)写病历前先检查是否有可用的链表(此标记为flag的值,若为1则代表可以修改病历,否则要求用户重新做出选择)。

确认有可用链表之后进入modify函数。

要求用户输入病人的id号码,然后在链表中寻找该病所对应的节点,若无此病人的id则直接输出提示信息后返回:

若找到后,先输出原来的病历内容,然后提示用户输入当前日期和新添加的病历内容,调用strcmp函数将新内容追加到原来的casehist字符串数组中。

printf("原有病历:

%s\n",temp->casehist);

printf("输入当前日期年份");

gets(a);

printf("输入当前月份");

gets(b);

printf("输入当前日子");

gets(c);

strcat(temp->casehist,a);

strcat(temp->casehist,"/");

strcat(temp->casehist,b);

strcat(temp->casehist,"/");

strcat(temp->casehist,c);

strcat(temp->casehist,":

");

printf("请输入新病历的内容\n");

gets(d);

strcat(temp->casehist,d);

········

2)载入链表信息是首先定义一个文件指针,然后以只读方式打开文件。

若失败则输出提示信息返回,成功后调用malloc函数来申请一块内存,用read函数将文件内容写入到节点中,随后调用insert函数将节点加入链表,如此循环下去直到fread函数返回0值,即文件已经读到了末尾时,再将链表的头指针返回给主函数即可。

Flag值置为1,用来代表已有可用链表。

if((fp=fopen("data","r"))==0){

printf("文件不存在!

");

returnhead;

}

while

(1){

rear=(structpatient*)malloc(sizeof(structpatient));

if(fread(rear,sizeof(structpatient),1,fp))

head=insert(head,rear);

}

else{

free(rear);

flag=1;

break;

}

}

4、源程序代码

/*head.h*/

#ifndefFIRST

#include

#include

#include

structpatient{//存储一个病人的信息

charid[10];//id数组存储病人号码

charname[10];//name数组存储病人姓名

charcasehist[200];//casehist存储病历内容

intcost[3];//cost数组存储病人买药的个数(总共三种)

inttransfusion;//transfusion存储病人输液的花费

intsurgery;//surgery存储手术的花费

structpatient*next;

//structpatient*next用来指向下一个病人结构体的起始地址从而形成一个链表

};

structstorage{//存储库存中当前的药品情况

intamount[3];

intprice[3];

};

intflag;

voidsearch(structpatient*temp);//查询单个病人的信息,参数为指向structpatient类型的指针

voidlistall(structpatient*temp);//列出所有病人的信息,参数为指向structpatient类型的指针

structpatient*insert(structpatient*head,structpatient*rear);

//加入新节点,参数为指向structpatient类型的指针

voidmodify(structpatient*temp);//修改病人病历,参数为指向structpatient类型的指针

voidbuy(structpatient*temp,structstorage*s);

//用于病人的消费处理,参数为指向structpatient类型的指针与指向structstorage的指针

structpatient*load(structpatient*head);

//将文件信息写入到链表中,参数为指向structpatient类型的指针

voidsave(structpatient*head);

//将链表信息保存到文件中,参数为指向structpatient类型的指针

#defineFIRST

#endif

/*find.c*/

#include"head.h"

voidsearch(structpatient*temp){//定义search函数,查询单个病人的信息

chart[10];//定义字符数组

intsum;//定义整型变量sum

printf("请输入病人的id\n");

gets(t);/输入字符串

while(temp&&strcmp(temp->id,t)){

//比较字符串temp->id和t,其值和temp逻辑与运算,结果为非0时,执行循环体

temp=temp->next;

}

if(temp){//temp的值为非0时,执行下列步骤

printf("id:

%s\n",temp->id);

printf("\n姓名:

%s",temp->name);

printf("\n病历:

\n%s",temp->casehist);

printf("\n消费记录:

\n");

if(temp->cost[0]){

printf("巴米尔%d个\n",temp->cost[0]);

}

if(temp->cost[1]){

printf("感冒灵%d个\n",temp->cost[1]);

}

if(temp->cost[2]){

printf("病毒唑%d个\n",temp->cost[2]);

}

if(temp->transfusion){

printf("输液费%d\n",temp->transfusion);

}

if(temp->surgery){

printf("手术费%d\n",temp->surgery);

}

sum=temp->cost[0]*5+temp->cost[1]*9+temp->cost[2]*16+temp->transfusion+temp->surgery;

//计算sum的值

printf("总费用%d元",sum);

}

else{

printf("无该病人的信息!

\n");

}

}

voidlistall(structpatient*temp){//定义listall函数,列出所有病人的信息

printf("id姓名\n");

while(temp){

printf("%s%s\n",temp->id,temp->name);

temp=temp->next;

}

}

/*link.c*/

#include"head.h"

structpatient*insert(structpatient*head,structpatient*rear){/*!

!

!

!

!

!

可以出现重复id*/

structpatient*temp;

if(head){

temp=head;

while(temp->next){

temp=temp->next;

}

temp->next=rear;

rear->next=0;

}

else{

head=rear;

rear->next=0;

}

returnhead;

}

voidmodify(structpatient*temp){//修改病人病历

chart[10],d[200];//定义字符组

chara[4],b[2],c[2];//定义字符组

printf("请输入病人的id\n");

gets(t);//输入病人的id

while(temp&&strcmp(temp->id,t)){//自动查找病人的id

temp=temp->next;

}

if(temp){

printf("原有病历:

%s\n",temp->casehist);

printf("输入当前日期年份");

gets(a);//输入年份

printf("输入当前月份");

gets(b);//输入月份

printf("输入当前日子");

gets(c);//输入日期

strcat(temp->casehist,a);//把字符串a接到temp->casehist后面

strcat(temp->casehist,"/");//把字符“/”接到temp->casehist后面

strcat(temp->casehist,b);//把字符串b接到temp->casehist后面

strcat(temp->casehist,"/");//把字符“/”接到temp->casehist后面

strcat(temp->casehist,c);//把字符串c接到temp->casehist后面

strcat(temp->casehist,":

");//把字符“:

”接到temp->casehist后面

printf("请输入新病历的内容\n");

gets(d);//输入新病历内容

strcat(temp->casehist,d);//把字符串d接到temp->casehist后面

strcat(temp->casehist,"\n");//把字符"\n"接到temp->casehist后面

}

else{

printf("无此病人信息!

\n");

}

}

voidbuy(structpatient*temp,structstorage*s){//病人消费处理

chart[10];

inta,b,c,d,e;

intflag1;

printf("请输入病人的id\n");

gets(t);//输入病人的id

while(temp&&strcmp(temp->id,t)){//自动查找病人的id

temp=temp->next;

}

if(temp){

flag1=0;

do{

printf("请输入买入巴米尔的个数:

\n");

scanf("%d",&a);

flag1=0;

if(a>s->amount[0]){//若输入的值大于库存的值,则提示"库存不足"

printf("库存不足!

\n");

flag1=1;

}

}while(flag1);//flag1=1时,执行循环体

flag1=0;

do{

printf("请输入买入感冒灵的个数:

\n");

scanf("%d",&b);

flag1=0;

if(b>s->amount[1]){//若输入的值大于库存的值,则提示"库存不足"

printf("库存不足!

\n");

flag1=1;

}

}while(flag1);//flag1=1时,执行循环体

flag1=0;

do{

printf("请输入买入病毒唑的个数:

\n");

scanf("%d",&c);

flag1=0;

if(c>s->amount[2]){//若输入的值大于库存的值,则提示"库存不足"

printf("库存不足!

\n");

flag1=1;

}

}while(flag1);//flag1=1时,执行循环体

temp->cost[0]+=a;//temp->cost[0]和a的值相加后赋给temp->cost[0]

temp->cost[1]+=b;//temp->cost[1]和b的值相加后赋给temp->cost[1]

temp->cost[2]+=c;//temp->cost[2]和c的值相加后赋给temp->cost[2]

printf("请输入输液费\n");

scanf("%d",&d);

temp->transfusion+=d;//temp->transfusion和d的值相加后赋给temp->transfusion

printf("请输入手术费\n");

scanf("%d",&e);

temp->surgery+=e;//temp->surgery和e的值相加后赋给temp->surgery

s->amount[0]-=a;//s->amount[0]减去a的值后赋给s->amount[0]

s->amount[1]-=b;//s->amount[1]减去b的值后赋给s->amount[1]

s->amount[2]-=c;//s->amount[2]减去c的值后赋给s->amount[2]

printf("\n购买成功!

\n");

}

else{

printf("无此病人信息!

\n");

}

}

/*main.h*/

#include"head.h"

voidtest();//检测有无存储病人的二进制文件

voidinit(structstorage*temp);

//初始化库存中的药品,参数为指向structstorage类型的指针

voidprintmenu();//打印提示菜单

voidliststock(structstoragetemp);//列出库存中的药品

structpatient*enroll();//注册新病人信息

voidfreeall(structpatient*temp);//清除链表内容,参数为指向structpatient类型的指针

voidmain(){

structpatient*head=0,*rear;

structstoragestock;

charch;

printf("欢迎使用医院管理系统\n");

test();

init(&stock);

while

(1){

printmenu();

fflush(stdin);

ch=getchar();

fflush(stdin);

switch(ch){

case'1':

if(flag){//检查是否有可用的链表

rear=enroll();

head=insert(head,rear);//调用insert函数将节点加入链表

printf("注册成功!

\n");

}

else{

printf("您没有载入信息不能注册!

\n");

}

break;

case'2':

if(flag){//检查是否有可用的链表

search(head);//查询病人信息

}

else{

printf("您没有载入信息不能进行查询!

\n");

}

break;

case'3':

if(flag){//检查是否有可用的链表

modify(head);//修改病人病历

}

else{

printf("您没有载入信息不能修改病历!

\n");

}

break;

case'4':

if(flag){//检查是否有可用的链表

buy(head,&stock);//病人的消费

}

else{

printf("您没

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1