c商品订购系统.docx
《c商品订购系统.docx》由会员分享,可在线阅读,更多相关《c商品订购系统.docx(8页珍藏版)》请在冰点文库上搜索。
c商品订购系统
Documentserialnumber【UU89WT-UU98YT-UU8CB-UUUT-UUT108】
c商品订购系统
#include
#include
#include
#include
#include
usingnamespacestd;
voidfile_1();
voidfile_2();
intmenu1();
voidmenu2();
voidchoose(int);
voidch1();
voidch2();
voidch3();
voidch4();
voidch5();
voidch6();
classgoods
{
public:
goods(void);
goods(string,string,float,string,float,string,float=0);
~goods(void);
voiddisplay1();
voiddisplay2();
stringgetnumber();
stringgetname();
floatgetprice();
floatgetstore();
stringgetunit2();
floatgetsold();
staticvoidtotalcount(float);
staticfloatgettotal();
voidplus_reduce(float);
private:
stringnumber;
stringname;
floatprice;
stringunit1;
floatstore;
stringunit2;
floatsold;
staticfloattotal;
};
intmain()etsold()>0)isplay2();
}
}
cout<<"总计:
"<:
gettotal()<<"元"<=0)
{
etname()<}
}
file2<<"合计:
"<:
gettotal()<<"元"<line();;
cout<<"\t\t|2.商品购买|"<line();
cout<<"\t\t|3.查看帐单|"<line();
cout<<"\t\t|4.确认结帐|"<line();
cout<<"\t\t|5.退出程序|"<line();
cout<<"\t\t请选择菜单(1~6):
";
intch;
cin>>ch;
choose(ch);
}
voidch1()isplay1();isplay1();etnumber())etstore()>1e-5)etunit2()=="台"&&fabs(m-float(int(m)))>1e-5)
{
cout<<"购买数量应为整数,请重新输入!
"<flag=1;//改变flag值,表示已找到商品
}
}
if(!
flag)//若flag为0则未找到商品
{
cout<<"找不到该商品,请重新输入!
"<gotoget;
}
}
back();//返回购物菜单
}
voidch3()//显示购物清单
{
if(goods:
:
gettotal()>0)
{
check();
}
else
{
cout<<"您尚未购买任何商品,是否立即购买(Y/N):
";
charyn;
cin>>yn;
if(yn=='y'||yn=='Y')
{
cout<<"即将进入购物系统!
";
system("pause");//暂停
system("cls");//清屏
ch2();//进入购物系统
}
}
back();//返回购物菜单
}
voidch4()//结算,支付函数
{
if(goods:
:
gettotal()>0)
{
cout<<"总计:
"<:
gettotal()<<"元"<floatn=0;
pay:
cout<<"请输入支付金额:
";//提示支付
floatm=0;
cin>>m;
n+=m;
if(goods:
:
gettotal()-n>0)//若支付金额不足,则提示不足金额,要求重新支付
{
cout<<"金额不足,还差"<:
gettotal()-n<<"元,"<<"请继续支付!
"<gotopay;
}
if(n-goods:
:
gettotal()>=0)//金额足够则完成支付,并找零
{
cout<<"找零"<:
gettotal()<<"元"<cout<<"支付完成,按任意键显示帐单!
";
system("pause");
check();
cout<<"收款"<cout<<"找零"<:
gettotal()<<"元"<cout<<"谢谢惠顾,欢迎下次光临!
"<file_2();//调用file_2,将清单存入
_exit();//退出
}
}
else
{
cout<<"您尚未购买任何商品,是否立即购买(Y/N):
";
charyn;
cin>>yn;
if(yn=='y'||yn=='Y')
{
cout<<"即将进入购物系统!
";
system("pause");//暂停
system("cls");//清屏
ch2();//进入购物系统
}
}
}
voidch5()//退出系统
{
cout<<"您是否确定退出本系统(Y/N):
";
charyn;
cin>>yn;
if(yn=='y'||yn=='Y')
{
_exit();//退出
}
else
{
back();//返回购物菜单
}
}
voidch6()//非菜单选项输入情况
{
cout<<"输入错误,请重新输入!
";
back();//返回购物菜单
}
voidchoose(intch)//将菜单选择与各函数相连接实现功能选择
{
switch(ch)
{
case1:
ch1();break;
case2:
ch2();break;
case3:
ch3();break;
case4:
ch4();break;
case5:
ch5();break;
default:
ch6();
}
}