源程序(医院药房药品管理系统C++)_药房药品管理系统

其他范文 时间:2020-02-27 22:52:34 收藏本文下载本文
【www.daodoc.com - 其他范文】

源程序(医院药房药品管理系统C++)由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“药房药品管理系统”。

源程序: # include //包含文件读写 # include # include //包含strcmp()字符是否相等 #include //包含system(“cls”)清屏

#define MAX 60

//下列字符数组的大小 struct Date{//日期

char year[MAX];//年

char month[MAX];//月

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;//下一个结点

};

cla Cangkuguanli { //类定义与实现 private:

int 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;

length=0;//初始长度为0;

current=head;

do {

Goods * temp=new Goods;//构建新结点信息

length++;//每加一个结点 链表长度增1

temp->next=NULL;

cout

请输入药品名称: “;

cin>>temp->name;

cout

请输入单价

: ”;

cin>>temp->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->xiaoqi.day;

cout

cin>>temp->kind;

if(head==NULL){head=temp;current=temp;} //head头指针,current尾指针

else {current->next=temp,current=temp;}

do{

cout

cin>>g;

if(g!='Y'&&g!='N')

{

cout

}

}while(g!='Y'&&g!='N');

}while(g=='Y');//判断是否继续插入新结点

}

void Open()//打开一个数据文件,并建立链表关联 和文件中的记录对应

{

char fname[20];//文件名称

cout

cin>>fname;//输入要打开的文件名

ifstream infile(fname);//创建输入文件流

infile>>length;

cout

//if(length==0)cout

for(int i=0;i

{

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;}

}

infile.close();//关闭文件流

}//open

void Save()//保存链表信息到文件 {

if(length==0)

{

cout

return;

}

char fname[20];//文件名称

cout

cin>>fname;

ofstream outfile(fname);//创建输出文件流

Goods * temp=head->next;

outfile

while(temp!=NULL)//把所有结点写入到文件fname

{

outfilenamepricenumbercostkind

indate.yearindate.monthindate.dayxiaoqi.yearxiaoqi.monthxiaoqi.day

//写入每个结点信息

temp=temp->next;

}

outfile.close();//关闭文件流 }

void printinfor(Goods * current)//输出一个结点的信息到字符界面 {

if(current==NULL)

{ cout

}

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.yearindate.monthindate.day;cout.width(10);coutxiaoqi.yearxiaoqi.monthxiaoqi.day;cout

void Show()//输出所有结点信息到字符界面 { current=head->next;if(current==NULL){ cout

cout.width(8);cout

//循环输出所有结点

printinfor(current);

current=current->next;}

}//show Goods *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)

{

cout

return NULL;

} return temp;} void Queryindate()//按入库日期查询 { Date t;cout>t.year>>t.month>>t.day;

printinfor(Searchindate(t));}//Queryindate()Goods * Searchname(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

return NULL;

} return temp;} void

Queryname()//按药品名查询 { char r[MAX];cout>r;printinfor(Searchname(r));} void Query()//查询函数

一个次级菜单 { char m;do{ cout

cout 按入库的时间查询

***********“

cout

***********”

cout 退出

***********“>m;switch(m){ //分别调用按不同查询方式下的函数

case 'a': Queryindate();break;case 'b': Queryname();break;

case 'c': return;default: cout

void Removebynumber()//按总量删除某个结点 { char t[MAX];//需要删除的总量值

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->next=temp->next;

length--;//没删除一个结点,链表长度减1

f=true;

delete temp;//释放结点 cout

//break;

此处屏蔽break,也就是说找到第一个满足条件的结点,并不退出循环,而是继续删除

}

else{

current=current->next;

}

}

if(f==false)//false没有改动,表示没有满足条件的结点

{

cout

} }//Removebynumber void Removebyname()//按名称删除某个结点 { char t[20];

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

续删除

}

else{

current=current->next;

}

}

if(f==false)

{

cout

} }//Removebyname

void Removebyindate()//按购进时间删除某个结点 {

Date t,d;

bool f=false;

Goods * temp;

cout

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;

delete temp;cout

}

else{

current=current->next;

}

}

if(f==false)

{

cout

} }//Removebyindate

void Remove()//删除函数

{ char g='Y';

do{ cout 按药品总数量删除

***********”

***********“ 按入库时间删除

***********” 退出

***********“>g;switch(g){

case 'a': Removebynumber();break;case 'b': Removebyname();break;case 'c': Removebyindate();break;case 'd': return;default: cout

} 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->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->xiaoqi.day;

cout

cin>>temp->kind;

current->next=temp;//这时current指向尾指针,将要插入的结点接到current后面

current=temp;}//add

void Modify(){//通过药品名找到要修改的数据项

char n[MAX];cout>n;

Goods * temp=Searchname(n);//按商品名查找

cout

cin>>temp->price;

cout

cin>>temp->cost;

cout

cin>>temp->indate.year>>temp->indate.month>>temp->indate.day;

cout

cin>>temp->number;

cout

cin>>temp->kind;}

void operation(){ char g='Y';do{ cout

cout

cout

cout

MWDICINE STORE MANAGEMENT SYSTERMn“;

cout

&& 药品入库

&&&&&&&&&&&&&&& cout

&&

&& 药品出库

&&&&&&&&&&&&&&&

n”;n“;

cout

&&

&&

药品调价

&&&

n”;

cout

&&

&&

新药品入库

&&&

n“;

cout

&&

&&

打开文件

&&&&&&&&&&&&&&&

n”;

cout

&& &&

保存文件

&&&&&&&&&&&&&&&

n“;

cout

&&&

显示库存

&&&

n”;

cout

&&&

药品查询

&&&

n“;

cout

&&&

上下限制

&&&

n”;

cout

&&&

退出

&&&

n“;

cout

cout

cin>>g;switch(g){ case 'C':

Creatlist();break;case 'A':

Add();break;case 'M':

Modify();break;case 'D':

Show();break;case 'Q':

Query();break;case 'R':

Remove();break;case 'O':

Open();break;case 'S':

Save();break;case 'N':

system(”cls“);break;case 'E':

return;default: cout

input the right character!!!n”;}//switch }while(g!='E');}//operation };//Cangkuguanli int main(){ Cangkuguanli A;

A.operation();return 0;}

下载源程序(医院药房药品管理系统C++)word格式文档
下载源程序(医院药房药品管理系统C++).doc
将本文档下载到自己电脑,方便修改和收藏。
点此处下载文档

文档为doc格式

    热门文章
      整站推荐
        点击下载本文