这个适合初学者去学习!!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//1、确定数据类型信息
typedef struct patient
{
char ID[10]; //编号
char name[10]; //姓名
char details[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()
{
//2、选择输入项
printf("\n");
printf("*************欢迎使用医疗管理系统*******************\n");
printf("1.注册学生信息\n");
printf("2.查询学生信息\n"); //4、输出项
printf("3.填写详细信息\n");
printf("4.学生购买消费\n");//3、用于计算项
printf("5.列出所有学生信息\n"); //5、输出所以学生信息
printf("6.查询药品库存\n");
printf("7.退出系统\n");
printf("**************请选择操作项******************\n");
}
node1 * create(node1 *p1) //注册学生信息
{
node1 *p;
p=(node1 *)malloc(sizeof(node1));
printf("请输入学生编号\n");
scanf("%s",p->ID);
while(p1->ID&&strcmp(p1->ID,p->ID))
{
p1=p1->next;
}
if(p1==NULL)
{
printf("请输入学生姓名\n");
scanf("%s",p->name);
strcpy(p->details,"0");
p->cost[0]=0;
p->cost[1]=0;
p->cost[2]=0;
p->next=NULL;
printf("已注入您的信息!\n");
return p;
}
else
{
printf("输入学生编号以存在,注册失败!\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("请输入学生编号\n");
scanf("%s",a);
while(p1->ID&&strcmp(p1->ID,a))
{
p1=p1->next;
}
if(p1)
{
printf("编号:%s\n",p1->ID);
printf("姓名:%s\n",p1->name);
printf("详细信息:%s\n",p1->details);
printf("消费记录:\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("总费用\t%d\n",sum);
}
else
printf("该学生没有注册!\n");
}
void details(node1 *p) //详细信息
{
char a[10];
char details[300];
char enter[5]=":\n";
printf("请输入学生编号\n");
scanf("%s",a);
while(p->ID&&strcmp(p->ID,a))
{
p=p->next;
}
if(p==NULL)
{
printf("无该学生信息!\n");
}
else
{
printf("请写详细信息:\n");
scanf("%s",details);
strcpy(p->details,details);
strcat(p->details,enter);
}
}
node2 buy(node1 *p,node2 temp) //消费记录
{
char i[10];
printf("请输入学生编号\n");
scanf("%s",i);
while(p->ID&&strcmp(p->ID,i))
{
p=p->next;
}
while(1)
{
int a,b,c,d;
printf("1.购买阿莫西林胶囊\n");
printf("2.购买连花清瘟胶囊 \n");
printf("3.购买板蓝根\n");
printf("0.退出\n");
scanf("%d",&a);
switch(a)
{
case 1:
do
{
printf("现有库存%d\n",temp.amount[0]);
printf("购买阿莫西林胶囊数量:");
scanf("%d",&b);
temp.amount[0]=temp.amount[0]-b;
p->cost[0]+=b*5;
}while(b>20);
break;
case 2:
do
{
printf("现有库存%d\n",temp.amount[1]);
printf("购买连花清瘟胶囊数量:");
scanf("%d",&c);
temp.amount[1]=temp.amount[1]-c;
p->cost[1]+=c*9;
}while(c>20);
break;
case 3:
do
{
printf("现有库存%d\n",temp.amount[2]);
printf("购买板蓝根数量:");
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("学生编号:%s\n",p->ID);
printf("学生姓名:%s\n",p->name);
printf("学生详细信息:%s\n",p->details);
printf("购买阿莫西林胶囊费用:%d\n",p->cost[0]);
printf("购买连花清瘟胶囊费用:%d\n",p->cost[1]);
printf("购买板蓝根费用:%d\n",p->cost[2]);
printf("\n");
p=p->next;
}while(p!=NULL);
}
}
void liststock(node2 temp) //药品信息
{
printf("药品\t数量\t价格\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;
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:
details(head);
break;
case 4:
temp=buy(head,temp);
break;
case 5:
list(head);
break;
case 6:
liststock(temp);
break;
case 7:
printf("谢谢使用!!\n");
return(0);
default:
printf("输入有误!重新输入\n");
break;
}
}
}
//主函数main
int main()
{
chose();
return 0;
}