1、源程序:#include/包含文件读写#include#include/包含strcmp()字符是否相等#include/包含system(cls)清屏#defineMAX60/下列字符数组的大小structDate/日期charyearMAX;/年charmonthMAX;/月chardayMAX;/日;structGoods/药品信息charnameMAX;/药品名称charpriceMAX;/药品价格charnumberMAX;/药品数量charcostMAX;/药品总价charkind
3、harg=Y;ints=0;length=0;/初始长度为0;current=head;doGoods*temp=newGoods;/构建新结点信息length+;/每加一个结点链表长度增1temp-next=NULL;couttemp-name;couttemp-price;couttemp-number;couttemp-cost;couttemp-indate.yeartemp-indate.monthtemp-indate.day;couttemp-xiaoqi.yeartemp-xiaoqi.monthtemp-xiaoqi.day;
4、couttemp-kind;if(head=NULL)head=temp;current=temp;/head头指针,current尾指针elsecurrent-next=temp,current=temp;docoutg;if(g!=Ywhile(g!=Ywhile(g=Y);/判断是否继续插入新结点voidOpen()/打开一个数据文件,并建立链表关联和文件中的记录对应charfname20;/文件名称coutfname;/输入要打开的文件名ifstreaminfile(fname);/创建输入文件流infilelength;co
5、utnlengthis:lengthendl;/if(length=0)cout数据为空n;for(inti=0;inext=NULL;infilet-namet-pricet-numbert-costt-kindt-indate.yeart-indate.montht-indate.day;if(head=NULL)head=t;current=t;/跟上面的链表创建相似elsecurrent-next=t,current=t;infile.close();/关闭文件流/openvoidSave()/保存链表信息到文件if(length=0)co
6、ut列表为空不需存盘n;return;charfname20;/文件名称coutfname;ofstreamoutfile(fname);/创建输出文件流Goods*temp=head-next;outfilelengthendl;/先写入文件的长度while(temp!=NULL)/把所有结点写入到文件fnamenumberindate.monthxiaoqi.monthoutfilenamepricecostkindindate.yearindate.dayxiaoqi.yearxiaoqi.daynext;outfile.
7、close();/关闭文件流voidprintinfor(Goods*current)/输出一个结点的信息到字符界面if(current=NULL)coutn元素为空!n;return;cout.fill();coutname;cout.width(8);cout.width(8);coutprice;cout.width(8);coutnumber;cout.width(8);coutcost;/就是给current-cost10个字符输出,不够往前面加空格cout.width(10);coutkind;cout.width(1
8、0);coutindate.year.indate.month.indate.day;cout.width(10);coutxiaoqi.year.xiaoqi.month.xiaoqi.day;coutnext;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.
10、t-next;if(f=false)coutn没有满足要求的信息n;returnNULL;returntemp;voidQueryindate()/按入库日期查询Datet;coutt.yeart.montht.day;printinfor(Searchindate(t);/Queryindate()Goods*Searchname(charr)/搜索药品名返回结点指针tempGoods*temp;current=head-next;boolf=false;while(current!=NULL)if(strcmp(curren
12、*退出*endl;cout*m;switch(m)/分别调用按不同查询方式下的函数casea:Queryindate();break;caseb:Queryname();break;casec:return;default:couterror!;while(m!=h);/QueryvoidRemovebynumber()/按总量删除某个结点chartMAX;/需要删除的总量值boolf=false;/表示是否找到满足要求的结点Goods*temp;/指向找到的结点,并删除coutt;current=head;
13、while(current-next!=NULL)if(strcmp(current-next-number,t)=0)/判断是否满足条件temp=current-next;current-next=temp-next;length-;/没删除一个结点,链表长度减1f=true;deletetemp;/释放结点coutnext;if(f=false)/false没有改动,表示没有满足条件的结点cout此药品不存在,无须删除n;/RemovebynumbervoidRemovebyname()/按名称删除某个结点chart20;boolf=f
15、temp;coutt.yeart.montht.day;current=head;while(current-next!=NULL)d=current-next-indate;if(d.year=t.yearcurrent-next=temp-next;length-;f=true;deletetemp;coutnext;if(f=false)cout此元素不存在,无须删除n;/RemovebyindatevoidRemove()/删除函数endl;endl;charg=Y;docout*按药品总数量删除*endl;cout*按药品
17、me;couttemp-price;couttemp-number;couttemp-cost;couttemp-indate.yeartemp-indate.monthtemp-indate.day;couttemp-xiaoqi.yeartemp-xiaoqi.monthtemp-xiaoqi.day;cout请输入药品的种类:temp-kind;current-next=temp;/这时current指向尾指针,将要插入的结点接到current后面current=temp;/addvoidModify()/通过药品名找到要修改的数据项charn
18、MAX;cout请输入您要修改的药品名:n;Goods*temp=Searchname(n);/按商品名查找couttemp-price;couttemp-cost;couttemp-indate.yeartemp-indate.monthtemp-indate.day;couttemp-number;couttemp-kind;voidoperation()charg=Y;docoutt;cout.fill(*);cout.width(21);cout*;cout医院药房管理系统cout.fill(*);cout.width(19);cout*;coutn;coutt***n;couttMWDICINESTOREMA