1、
源程序医院药房药品管理系统C
25
2020年4月19日
文档仅供参考
源程序:
# include
2、char day[MAX];//日 }; struct Goods{//药品信息 char name[MAX];//药品名称 char price[MAX];//药品价格 char number[MAX];//药品数量 char cost[MAX];//药品总价 char kind[MAX];//药品的种类 Date indate;//入库日期 Date xiaoqi;//到期时间 Goods * next;//下一个结点 }; class Cangkuguanli { //类定义与实现 private: in
3、t length;//客户数量 Goods * head;//列表的头结点 Goods * current;//当前结点 public: Cangkuguanli()//构造函数 { head=new Goods;//创立头结点 current=head; current->next=NULL; length=0;//长度为0 } void Creatlist()//创立新的列表 { char g='Y'; int s=0;
4、 length=0;//初始长度为0; current=head; do { Goods * temp=new Goods ;//构建新结点信息 length++; //每加一个结点 链表长度增1 temp->next=NULL; cout<<" 请输入药品名称: "; cin>>temp->name;
5、 cout<<" 请输入单价 : "; cin>>temp->price; cout<<" 请输入药品数量: "; cin>>temp->number; cout<<" 请输入总费用 : "; cin>>temp->cost; cout<<" 请输入日期 (**** ** **) : "; cin>>temp->indate.year>>temp->indate.month>>temp->indate.day; cout<<" 请输入药
6、品有效期 (**** ** **):"; cin>>temp->xiaoqi.year>>temp->xiaoqi.month>>temp->xiaoqi.day; cout<<" 请输入药品种类: "; cin>>temp->kind; if(head==NULL){head=temp;current=temp;} //head头指针,current尾指针 else {current->next=temp,current=temp;} do{
7、 cout<<" next ? (Y N) "; //是否继续存入新产品 cin>>g; if(g!='Y'&&g!='N') { cout<<"\n error !!!!\n "; } }while(g!='Y'&&g!='N'); }while(g=='Y');//判断是否继续插入新结点 } void Open ()//打开一个数据文件,并建立链表关联 和文件中的记录对应 { char fname[20];//文
8、件名称
cout<<" input the name of the file \n";
cin>>fname; //输入要打开的文件名
ifstream infile (fname);//创立输入文件流
infile>>length;
cout<<"\n length is: "< 9、 Goods * t=new Goods ;
t->next=NULL;
infile>>t->name>>t->price>>t->number>>t->cost>>t->kind>>
t->indate.year>>t->indate.month>>t->indate.day;
if(head==NULL){head=t;current=t;}//跟上面的链表创立相似
else {current->next=t,current=t;}
}
10、 infile.close();//关闭文件流
}//open
void Save ()//保存链表信息到文件
{
if(length==0)
{
cout<<" 列表为空 不需存盘 \n";
return ;
}
char fname[20];//文件名称
cout<<" input the name of the file you want to put data in \n";
cin>>fname;
ofstream outfile(fnam 11、e);//创立输出文件流
Goods * temp=head->next;
outfile< 12、 "< 13、 cout.fill(' ');
cout< 14、
cout< 15、t=head->next;
if(current==NULL)
{
cout<<"列表为空 \n";
return ;
}
cout.fill(' ');
cout.width(2);
cout<<"名称";
cout.width(8);
cout<<"价格";
cout.width(8);
cout<<"数量";
cout.width(8);
cout<<"总费用";
cout.width(10);
cout<<"药品的种类";
cout.width(15);
cout<<"购进时间";
16、cout.width(15);
cout<<"有效期";
cout< 17、next;
while(current!=NULL)
{
d=current->indate;
if(!strcmp(d.year,t.year)&&!strcmp(d.month,t.month)&&!strcmp(d.day,t.day))
{
temp=current;
f=true;
break;
}
current=current->next;
}
if(f==false)
{
cout<<"\n 没有满足要求的信息 \n"; 18、
return NULL;
}
return temp;
}
void Queryindate()//按入库日期查询
{
Date t;
cout<<" input the date (**** ** **): ";
cin>>t.year>>t.month>>t.day;
printinfor(Searchindate (t));
}//Queryindate()
Goods * Searchname (char r[])//搜索药品名 返回结点指针temp
{ Goods * temp;
current=head->next; 19、
bool f=false;
while(current!=NULL)
{
if(strcmp(current->name,r)==0)
{
temp=current;
f=true;
break;
}
current=current->next;
}
if(f==false)
{
cout<<"\n 商品名为 : "< 20、oid Queryname() //按药品名查询
{
char r[MAX];
cout<<" input the name: ";
cin>>r;
printinfor(Searchname (r));
}
void Query ()//查询函数 一个次级菜单
{
char m;
do{
cout<<" ********************************************************** "< 21、"< 22、 Queryindate();break;
case 'b': Queryname();break;
case 'c': return ;
default: cout<<"error!! ";
}
}while(m!='h');
}//Query
void Removebynumber () //按总量删除某个结点
{
char t[MAX]; //需要删除的总量值
bool f=false; //表示是否找到满足要求的结点
Goods * temp; //指向找到的结点,并删除
cout<<" 请输入药品的数量: ";
23、
cin>>t;
current=head;
while(current->next!=NULL)
{
if(strcmp(current->next->number,t)==0) //判断是否满足条件
{
temp=current->next;
current->next=temp->next;
length--; //没删除一个结点,链表长度减1
f=true;
delete temp;//释放结点
cout<<"已删除此药品\n";
//b 24、reak; 此处屏蔽break,也就是说找到第一个满足条件的结点,并不退出循环,而是继续删除
}
else{
current=current->next;
}
}
if(f==false)//false没有改动,表示没有满足条件的结点
{
cout<<"此药品不存在 ,无须删除 \n";
}
}//Removebynumber
void Removebyname () //按名称删除某个结点
{
char t[20];
bool f=false;;
Goods * temp 25、
cout<<" 请输入药品的名称:";
cin>>t;
current=head;
while(current->next!=NULL)
{
if(strcmp(current->next->name,t)==0)
{
temp=current->next;
current->next=temp->next;
length--;
f=true;
delete temp;cout<<"已删除此药品\n";
//break 26、此处屏蔽break,也就是说找到第一个满足条件的结点,并不退出循环,而是继续删除
}
else{
current=current->next;
}
}
if(f==false)
{
cout<<"此药品不存在 ,无须删除 \n";
}
}//Removebyname
void Removebyindate () //按购进时间删除某个结点
{
Date t,d;
bool f=false;
Goods * temp;
cout<<" 请输入查找药品的日期: 27、";
cin>>t.year>>t.month>>t.day;
current=head;
while(current->next!=NULL)
{
d=current->next->indate;
if(d.year==t.year&&d.month==t.month&&d.day==t.day)
{
temp=current->next;
current->next=temp->next;
length--;
f=true;
28、
delete temp;
cout<<"已删除此药品\n";
}
else{
current=current->next;
}
}
if(f==false)
{
cout<<"此元素不存在 ,无须删除 \n";
}
}//Removebyindate
void Remove ()//删除函数
{
char g='Y';
do{
cout<<" ************************************************** 29、 "< 30、 31、
void Add()
{
Goods * temp;
current=head;
while(current->next!=NULL)//找到尾指针
{
current=current->next;
}
temp=new Goods;
temp->next=NULL;
length++;//链表长加1
cout<<" 请输入药品名称: ";
cin>>temp->name;
cout<<" 请输入单价 : ";
cin>>temp 32、>price;
cout<<" 请输入药品数量 : ";
cin>>temp->number;
cout<<" 请输入总费用 : ";
cin>>temp->cost;
cout<<" 请输入入购日期 (**** ** **) ";
cin>>temp->indate.year>>temp->indate.month>>temp->indate.day;
cout<<"请输入有效期 (**** ** **)";
cin>>temp->xiaoqi.year>>temp->xiaoqi.month>>temp->x 33、iaoqi.day;
cout<<" 请输入药品的种类:"< 34、cin>>temp->price;
cout<<" 请输入药品的总费用:\n";
cin>>temp->cost;
cout<<" 请输入日期 (**** ** **):\n";
cin>>temp->indate.year>>temp->indate.month>>temp->indate.day;
cout<<" 请输入药品的数量:\n";
cin>>temp->number;
cout<<" 请输入药品的种类:\n";
cin>>temp->kind;
}
void operation ()
{
char 35、g='Y';
do{
cout<<"\t";
cout.fill('*');
cout.width(21);
cout<<'*';
cout<<"医院药房管理系统";
cout.fill('*');
cout.width(19);
cout<<'*';
cout<<"\n";
cout<<"\t********************************************************\n";
cout<<"\t MWDICINE STORE MANAGEMENT SYSTERM\n";
cout<< 36、"\t********************************************************\n";
cout<<"\t && && 38、 \n";
cout<<"\t &&& 39、\n";
cout<<"\t";
cout.fill('*');
cout.width(18);
cout<<'*';
cout<<"医院药房管理系统";
cout.fill('*');
cout.width(22);
cout<<'*';
cout< 40、': Query ();break;
case 'R': Remove();break;
case 'O': Open ();break;
case 'S': Save();break;
case 'N': system ("cls");break;
case 'E': return ;
default: cout<<" error!! input the right character !!!!! \n";
}//switch
}while(g!='E');
}//operation
};//Cangkuguanli
int main ()
{
Cangkuguanli A;
A.operation(); return 0;}
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818