源程序(医院药房药品管理系统C++)_第1页
源程序(医院药房药品管理系统C++)_第2页
源程序(医院药房药品管理系统C++)_第3页
免费预览已结束,剩余9页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

源程序 :# include / 包含文件读写# include # include / 包含 strcmp() 字符是否相等#include / 包含 system(cls) 清屏#define max 60/下列字符数组的大小struct date/ 日期char yearmax;/年char monthmax;/月char daymax;/日;struct goods/ 药品信息charnamemax;/药品名称char pricemax;/药 品 价 格 charnumbermax;/药品数量char costmax;/药 品 总 价 char kindmax;/药品的种类date indate;/ 入库日期date xiaoqi;/ 到期时间goods * next;/ 下一个结点;classcangkuguanli /类定义与实现private:int length;/ 客户数量goods * head;/ 列表的头结点goods * current;/ 当前结点public:cangkuguanli()/ 构造函数head=new goods;/ 创建头结点current=head;current-next=null; length=0;/ 长度为 0void creatlist()/ 创建新的列表char g=y; int s=0;length=0;/ 初始长度为0;current=head; do goods * temp=new goods ;/ 构建新结点信息length+;/每加一个结点链表长度增1 temp-next=null;couttemp-name;couttemp-price;couttemp-number;couttemp-cost;couttemp-indate.yeartemp-indate.monthtemp-indate.day; couttemp-xiaoqi.yeartemp-xiaoqi.monthtemp-xiaoqi.day;couttemp-kind;if(head=null)head=temp;current=temp;/head 头指针, current 尾指针else current-next=temp,current=temp; docoutg; if(g!=y&g!=n)coutn error !n ;while(g!=y&g!=n);while(g=y);/判断是否继续插入新结点void open ()/ 打开一个数据文件,并建立链表关联和文件中的记录对应char fname20;/ 文件名称coutfname;/输入要打开的文件名ifstreaminfile (fname);/ 创建输入文件流infilelength;coutn length is: lengthendl;/if(length=0)cout数据为空 n;for(int i=0;inext=null;infilet-namet-pricet-numbert-costt-kind t-indate.yeart-indate.montht-indate.day;if(head=null)head=t;current=t;/跟上面的链表创建相似else current-next=t,current=t;infile.close();/ 关闭文件流/openvoid save ()/ 保存链表信息到文件if(length=0)cout列表为空不需存盘n; return ;char fname20;/ 文件名称coutfname;ofstreamoutfile(fname);/ 创建输出文件流goods * temp=head-next; outfilelengthendl;/先写入文件的长度while (temp!=null)/把所有结点写入到文件fnameoutfilenamepricenumber cost kindindate.yearindate.monthindate.dayxiaoqi.yearxiaoqi.month xiaoqi.daynext;outfile.close();/ 关闭文件流void printinfor( 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(10);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.width(15); cout 购进时间 ; cout.width(15); cout 有效期 ;coutnext;/showgoods *searchindate(date t)/按购入日期搜索返回结点指针temp/结构体 t 含有 t.year t.month t.day 三个信息块date d;bool f=false;goods * temp;current=head-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)coutn没有满足要求的信息n; return null;return temp;voidqueryindate()/ 按入库日期查询date t;coutt.yeart.montht.day; printinfor(searchindate (t);/queryindate()goods * searchname (char r)/ 搜索药品名返回结点指针tempgoods * temp; current=head-next; bool f=false;while(current!=null)if(strcmp(current-name,r)=0)temp=current;f=true;break;current=current-next;if(f=false)coutn商品名为: r的商品不存在n ; return null;return temp;voidqueryname()/按药品名查询char rmax;coutr; printinfor(searchname (r);void query ()/ 查询函数一个次级菜单char m; docout*endl; cout*按入库的时间查询*endl;cout*按药品的名称查询*endl;cout*退出*endl;cout*m;switch (m) / 分别调用按不同查询方式下的函数case a: queryindate();break; case b: queryname();break; case c: return ;default: couterror! ;while(m!=h);/queryvoid removebynumber () / 按总量删除某个结点char tmax; /需要删除的总量值bool f=false;/ 表示是否找到满足要求的结点goods * temp;/指向找到的结点,并删除coutt;current=head;while(current-next!=null)if(strcmp(current-next-number,t)=0) /判断是否满足条件temp=current-next; current-next=temp-next;length-;/没删除一个结点,链表长度减1f=true;delete temp;/释放结点coutnext;if(f=false)/false没有改动,表示没有满足条件的结点cout 此药品不存在,无须删除n;/removebynumbervoid removebyname () / 按名称删除某个结点char t20; bool f=false; goods * temp;coutt; 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;coutnext;if(f=false)cout 此药品不存在,无须删除n;/removebynamevoid removebyindate () / 按购进时间删除某个结点date t,d; bool f=false;goods * temp;coutt.yeart.montht.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; delete temp;coutnext;if(f=false)cout 此元素不存在,无须删除n;/removebyindatevoid remove ()/ 删除函数char g=y; docout*endl; cout*按药品总数量删除*endl; cout*按药品名称删除*endl;cout*按入库时间删除*endl;cout*退出*endl; cout*g;switch (g)case a:removebynumber ();break; case b: removebyname();break; case c: removebyindate();break; case d: return ;default: coutnext!=null)/找到尾指针current=current-next;temp=new goods; temp-next=null; length+;/ 链表长加1couttemp-name;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;/addvoid modify ()/通过药品名找到要修改的数据项char nmax;cout 请输入您要修改的药品名:n;goods * temp=searchname (n);/ 按商品名查找couttemp-price;couttemp-cost;couttemp-indate.yeartemp-indate.monthtemp-indate.day; couttemp-number;couttemp-kind;void operation ()char g=y; do coutt; cout.fill(*);cout.width(21); cout*;cout 医院药房管理系统; cout.fill(*);cout.width(19); cout*; coutn;coutt*n;couttmwdicine store management systermn;coutt*n;coutt& 药品入库&n; coutt&药品出库&n;coutt&药品调价&n;coutt& 新药品入库&n; coutt&打开文件&n;n;coutt&保存文件&coutt&显示库存&n;coutt&药品查询&n;coutt&上下限制&n;coutt&退出&n;coutt*n; coutt*n;coutt; cout.fill(*); cout.width(18); cout*;cout 医院药房管理系统;cout.fill(*); cout.width(22); cout*; coutg;switch (g)case c:creatlist();break; case a:add();break;case m:modify ();

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论