该系统是基于C++实现的药品管理系统,可以作为毕业设计进行。
点击此处获取源码资源
main函数
#include<iostream> /*密码为:123456 */
#include<string>
#include <stdlib.h>
#include<conio.h>
#include"number.h"
using namespace std;
class medicine :public number,public product
{
private:
string name;
public:
medicine(){}
medicine(string nam,int y,int m,int d,int nu,float pr,int ex):date(y,m,d),number(y,m,d,pr,ex),product(y,m,d,nu)
{
name=nam;
}
~medicine(){}
void set_name(const string nam)
{
name=nam;
}
void show()
{
cout<<"药品名称:"<<name<<endl;
product::show();
number::show();
}
friend int main();
};
int main()
{
int p=0;
int s1,s2,s3,s4,s5;//缓存
float sk; //缓存
while(p==0)
{
for(int i=0;i<3;i++)
{
cout<<"请输入十一位数密码:";
char c;
string str;
string str1="123456";//此处改密码
while((c=getch())!=13)
{
if(c!=8)
{
cout<<"*";
str+=c;
}
else if(!str.empty())
{
str.erase(str.end()-1);
cout<<"\b"<<" "<<"\b";
}
}
if(str==str1)
{
//
int length=0;
medicine s[8];
while(p==0)
{
cout<<endl<<" 欢迎访问药品管理系统!"<<endl;
cout<<" *****药品管理系统*****"<<endl;
cout<<" 请选择您需要进行的操作!"<<endl;
cout<<" 1 药品添加"<<endl;
cout<<" 2 删除药品"<<endl;
cout<<" 3 药品内容更改"<<endl;
cout<<" 4 药品信息查找"<<endl;
cout<<" 5 药品库输出"<<endl;
cout<<" 6 药品库函数调用(运算符重载)"<<endl;
cout<<" 7 系统退出"<<endl;
cout<<"输入操作代码:";
int a=0;
char key;
do
{
cin>>key;
if((key>='1'&&key<='7'))
a=1;
else
cout<<"指令无效!"<<endl;
}while(a==0);
switch(key)
{
cout<<"输入操作代码:";
case'1':
{
string name;
cout<<"请输入要增加的药名:";
cin>>name;
cout<<"生产日期为: ";
cout<<"年: ";
cin>>s1;
cout<<"月: ";
cin>>s2;
cout<<"日: ";
cin>>s3;
cout<<"库存量为: ";
cin>>s4;
cout<<"单价为: ";
cin>>sk;
cout<<"保质期为(个月): ";
cin>>s5;
s[length]=medicine(name,s1,s2,s3,s4,sk,s5);
length++;
system("cls");
cout<<"添加药品"<<name<<"成功!"<<endl;
break;
}
case'2':
{
string name;
cout<<"请输入要删除的药品名称:"<<endl;
cin>>name;
if(length<=0)
{
system("cls");
cout<<"药品"<<name<<"不存在!"<<endl;
}
else
{
for(int point=0;point<length;point++)
{
if(s[point].name==name)
{
for(;point<length;point++)
{
s[point]=s[point+1];
}
length--;
system("cls");
cout<<"删除成功!"<<endl;
}
else
{
if(point>=(length-1))
{
system("cls");
cout<<"药品"<<name<<"不存在!"<<endl;
}
}
}
}
break;
}
case '3':
{
string name,sex,nation,number,address;
cout<<"请输入要修改的药品名称: ";
cin>>name;
for(int point=0;point<length;point++)
{
if(s[point].name==name)
{
cout<<"新的药品名称: ";
cin>>name;
cout<<"新的生产日期: ";
cout<<"年: ";
cin>>s1;
cout<<"月: ";
cin>>s2;
cout<<"日: ";
cin>>s3;
cout<<"新的库存量: ";
cin>>s4;
cout<<"新的单价: ";
cin>>sk;
cout<<"新的保质期(个月): ";
cin>>s5;
s[point]=medicine(name,s1,s2,s3,s4,sk,s5);
system("cls");
cout<<"修改药品"<<name<<"成功!"<<endl;
}
}
break;
}
case '4':
{
string name;
cout<<"请输入要查询的药品名称:"<<endl;
cin>>name;
if(length<=0)
{
system("cls");
cout<<"药品"<<name<<"不存在!"<<endl;
}
else
{
for(int point=0;point<length;point++)
{
if(s[point].name==name)
{
system("cls");
s[point].show();
}
else
{
if(point>=(length-1))
{
system("cls");
cout<<"药品"<<name<<"不存在!"<<endl;
}
}
}
break;
}
}
case '5':
{
system("cls");
for(int i=0;i<length;i++)
{
s[i].show();
cout<<endl;
}
break;
}
case'6':
{
cout<<" ***** 药品函数调用(运算符重载)*****"<<endl;
cout<<" 1.药品数量前置自加"<<endl;
cout<<" 2.药品数量后置自减"<<endl;
cout<<" 3.药品价格加法运算"<<endl;
cout<<" 4.药品价格减法运算"<<endl;
cout<<"输入操作代码:";
int f=0;
char key1;
do
{
cin>>key1;
if((key1>='1'&&key1<='4'))
f=1;
else
{
cout<<"指令无效!"<<endl;
}
}while(f==0);
switch(key1)
{
int r1,r2;
case'1':
{
cout<<"请输入操作成员序号:";
cin>>r1;
++s[r1].num;
cout<<"药品数量前置自加运算输出:";
s[r1].show();
break;
}
case'2':
{
cout<<"请输入操作成员序号:";
cin>>r1;
s[r1].num--;
cout<<"药品数量后置自减运算输出:";
s[r1].show();
break;
}
case'3':
{
cout<<"请输入操作成员序号1:";
cin>>r1;
cout<<"请输入操作成员序号2:";
cin>>r2;
s[r1].price+=s[r2].price;
cout<<"药品价格加法r1=r1+r2运算输出:";
s[r1].show();
break;
}
case'4':
{
cout<<"请输入操作成员序号1:";
cin>>r1;
cout<<"请输入操作成员序号2:";
cin>>r2;
s[r1].price+=s[r2].price;
cout<<"药品价格加法r1=r1-r2运算输出:";
s[r1].show();
break;
}
}
}
case'7':
{
p=1;
system("cls");
cout<<"退出系统成功!"<<endl;
}
break;
}
}
break;
}
else
{
cout<<endl<<"密码错误!"<<endl;
if(i==2)
{
cout<<"系统退出。"<<endl;
return 0;
}
else
cout<<"您还有"<<(2-i)<<"次机会"<<endl;
}
}
return 0;
}
return 0;
}
运行主界面截图:
点击此处获取源码资源