源程序(医院药房药品管理系统C++)_第1页
源程序(医院药房药品管理系统C++)_第2页
源程序(医院药房药品管理系统C++)_第3页
源程序(医院药房药品管理系统C++)_第4页
源程序(医院药房药品管理系统C++)_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

1、精选优质文档-倾情为你奉上源程序:# include <fstream.h> /包含文件读写# include <iostream.h># include <string.h> /包含strcmp()字符是否相等#include <stdlib.h> /包含system("cls")清屏#define MAX 60 /下列字符数组的大小struct Date/日期 char yearMAX;/年 char monthMAX;/月 char dayMAX;/日;struct Goods/药品信息 char nameMAX;/药品

2、名称 char priceMAX;/药品价格 char numberMAX;/药品数量 char costMAX;/药品总价 char kindMAX;/药品的种类 Date indate;/入库日期 Date xiaoqi;/到期时间 Goods * next;/下一个结点 ;class Cangkuguanli /类定义与实现private: int length;/客户数量 Goods * head;/列表的头结点 Goods * current;/当前结点public: Cangkuguanli()/构造函数 head=new Goods;/创建头结点 current=head; cu

3、rrent->next=NULL; length=0;/长度为0 void Creatlist()/创建新的列表 char g='Y' int s=0; length=0;/初始长度为0;current=head;do Goods * temp=new Goods ;/构建新结点信息 length+; /每加一个结点 链表长度增1 temp->next=NULL; cout<<" 请输入药品名称: " cin>>temp->name; cout<<" 请输入单价 : " cin>

4、>temp->price; cout<<" 请输入药品数量: " cin>>temp->number; cout<<" 请输入总费用 : " cin>>temp->cost; cout<<" 请输入日期 (* * *) : " cin>>temp->indate.year>>temp->indate.month>>temp->indate.day; cout<<" 请输入药品有

5、效期 (* * *):" 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 cout<<" next ? (Y N)

6、" /是否继续存入新产品 cin>>g; if(g!='Y'&&g!='N') cout<<"n error !n " while(g!='Y'&&g!='N'); while(g='Y');/判断是否继续插入新结点 void Open ()/打开一个数据文件,并建立链表关联 和文件中的记录对应 char fname20;/文件名称 cout<<" input the name of the file n&q

7、uot; cin>>fname; /输入要打开的文件名ifstream infile (fname);/创建输入文件流 infile>>length;cout<<"n length is: "<<length<<endl;/if(length=0)cout<<" 数据为空n" for(int i=0;i<length;i+)/创建新的结点保存文件的数据 Goods * t=new Goods ;t->next=NULL;infile>>t->name&g

8、t;>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;infile.close();/关闭文件流/open void Save ()/保存链表信息到文件 if(length=0) cout<<

9、;" 列表为空 不需存盘 n" return ; char fname20;/文件名称 cout<<" input the name of the file you want to put data in n" cin>>fname; ofstream outfile(fname);/创建输出文件流 Goods * temp=head->next; outfile<<length<<endl;/先写入文件的长度 while (temp!=NULL)/把所有结点写入到文件fname outfile<

10、;<temp->name<<" "<<temp->price<<" "<<temp->number<<" "<<temp->cost<<" "<<temp->kind << " "<<temp->indate.year<<" "<<temp->indate.month<<&q

11、uot; "<<temp->indate.day<<" "<<temp->xiaoqi.year<<" "<<temp->xiaoqi.month<<" "<<temp->xiaoqi.day<<endl; /写入每个结点信息 temp=temp->next; outfile.close();/关闭文件流 void printinfor( Goods * current)/输出一个结点的信息到字符界面

12、 if(current=NULL) cout<<"n元素为空! n " return; cout.fill(' ');cout<<current->name;cout.width(8); cout.width(8);cout<<current->price;cout.width(8); cout<<current->number;cout.width(8);cout<<current->cost; /就是给current->cost10个字符输出,不够往前面加 空格 c

13、out.width(10);cout<<current->kind; cout.width(10); cout<< current->indate.year<<"."<<current->indate.month<<"."<<current->indate.day; cout.width(10); cout<<current->xiaoqi.year<<"."<<current->xiaoqi

14、.month<<"."<<current->xiaoqi.day; cout<<endl;/ printinforvoid Show()/输出所有结点信息到字符界面current=head->next;if(current=NULL)cout<<"列表为空 n"return ;cout.fill(' ');cout.width(2);cout<<"名称" cout.width(8);cout<<"价格"cout.wi

15、dth(8);cout<<"数量"cout.width(8);cout<<"总费用"cout.width(10);cout<<"药品的种类"cout.width(15);cout<<"购进时间"cout.width(15);cout<<"有效期"cout<<endl; /输出属性列while(current!=NULL) /循环输出所有结点 printinfor( current ); current=current->

16、;next; /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;

17、 break; current=current->next; if(f=false) cout<<"n 没有满足要求的信息 n" 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 (

18、char r)/搜索药品名 返回结点指针temp Goods * 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) cout<<"n 商品名为 : "<<r<<" 的商品不存在 n " return NULL; return temp;void Q

19、ueryname() /按药品名查询char rMAX;cout<<" input the name: "cin>>r;printinfor(Searchname (r);void Query ()/查询函数 一个次级菜单char m; do cout<<" * "<<endl; cout<<"*<a> 按入库的时间查询 *"<<endl; cout<<"*<b> 按药品的名称查询 *"<<end

20、l; cout<<"*<c> 退出 *"<<endl; cout<<" * "<<endl; cin>>m; switch (m) /分别调用按不同查询方式下的函数 case 'a': Queryindate();break; case 'b': Queryname();break; case 'c': return ; default: cout<<"error! " while(m!='h&#

21、39;);/Query void Removebynumber () /按总量删除某个结点char tMAX; /需要删除的总量值 bool f=false; /表示是否找到满足要求的结点 Goods * temp; /指向找到的结点,并删除 cout<<" 请输入药品的数量: " cin>>t; current=head; while(current->next!=NULL) if(strcmp(current->next->number,t)=0) /判断是否满足条件 temp=current->next; current

22、->next=temp->next; length-; /没删除一个结点,链表长度减1 f=true; delete temp;/释放结点cout<<"已删除此药品n"/break; 此处屏蔽break,也就是说找到第一个满足条件的结点,并不退出循环,而是继续删除 else current=current->next; if(f=false)/false没有改动,表示没有满足条件的结点 cout<<"此药品不存在 ,无须删除 n" /Removebynumbervoid Removebyname () /按名称删

23、除某个结点char t20; bool f=false; Goods * temp; 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;

24、此处屏蔽break,也就是说找到第一个满足条件的结点,并不退出循环,而是继续删除 else current=current->next; if(f=false) cout<<"此药品不存在 ,无须删除 n" /Removebynamevoid Removebyindate () /按购进时间删除某个结点 Date t,d; bool f=false; Goods * temp; cout<<" 请输入查找药品的日期: " cin>>t.year>>t.month>>t.day; curre

25、nt=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;cout<<"已删除此药品n" else current=current->next; if(f=false) cout<

26、;<"此元素不存在 ,无须删除 n" /Removebyindatevoid Remove ()/删除函数char g='Y' do cout<<" * "<<endl; cout<<"*<a> 按药品总数量删除 *"<<endl; cout<<"*<b> 按药品名称删除 *"<<endl; cout<<"*<c> 按入库时间删除 *"<<en

27、dl; cout<<"*<d> 退出 *"<<endl; cout<<" * "<<endl; cin>>g; switch (g) case 'a': Removebynumber ();break; case 'b': Removebyname();break; case 'c': Removebyindate();break; case 'd': return ; default: cout<<&quo

28、t;error! " while(g!='d');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->

29、price; cout<<" 请输入药品数量 : " cin>>temp->number; cout<<" 请输入总费用 : " cin>>temp->cost; cout<<" 请输入入购日期 (* * *) " cin>>temp->indate.year>>temp->indate.month>>temp->indate.day; cout<<"请输入有效期 (* * *)"

30、; cin>>temp->xiaoqi.year>>temp->xiaoqi.month>>temp->xiaoqi.day; cout<<" 请输入药品的种类:"<<endl; cin>>temp->kind; current->next=temp;/这时current指向尾指针,将要插入的结点接到current后面 current=temp;/addvoid Modify ()/通过药品名找到要修改的数据项char nMAX;cout<<"请输入您

31、要修改的药品名:"<<endl;cin>>n; Goods * temp=Searchname (n);/按商品名查找 cout<<" 请输入单价:" cin>>temp->price; cout<<" 请输入药品的总费用:n" cin>>temp->cost; cout<<" 请输入日期 (* * *):n" cin>>temp->indate.year>>temp->indate.month

32、>>temp->indate.day; cout<<" 请输入药品的数量:n" cin>>temp->number; cout<<" 请输入药品的种类:n" cin>>temp->kind;void operation ()char g='Y'docout<<"t"cout.fill('*');cout.width(21);cout<<'*'cout<<"医院药房管

33、理系统"cout.fill('*');cout.width(19);cout<<'*' cout<<"n" cout<<"t*n" cout<<"t MWDICINE STORE MANAGEMENT SYSTERMn" cout<<"t*n" cout<<"t && && <C> 药品入库 &&&&&&

34、;&&&&&&&&& n" cout<<"t && && <R> 药品出库 &&&&&&&&&&&&&&& n" cout<<"t && && <M> 药品调价 &&& n" cout<<"t && && <A>新药品入库 &&& n" cout<<"t && && <O> 打开文件 &&&&&&&&&&&&&&& n" cout<<"t && && <S> 保存文件 &&&am

温馨提示

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

评论

0/150

提交评论