}//关闭文件
rf.close();
}
voidSale:
:
query()//查询商品
{
if(head==NULL)cout<<"产商品信息为空!
(库中暂无商品)";
else
{loop:
cout<<"\n\n\n\n█查找商品信息█\n";
inty=1;
Goods*p=head;
cout<<"\n请输入索引号";
intsyh;
cin>>syh;
cout<<"\n请输入商品名:
";
charn[20];
cin>>n;
while(p)
{
if(strcmp(n,p->getn())==0)
{
cout<<"\n|---------------------------------------------------------------------------|";
cout<<"\n|商品索引号:
"<getsyh()<<"商品名"<getn()<<"\t单价:
"<getp()<<"\t总数:
"<getn1()<<"\t已卖数:
"<getn2()<<"\t剩余数:
"<getn1()-p->getn2();
cout<<"\n|---------------------------------------------------------------------------|";
y=0;
}
p=p->getnext();
}
if(y)cout<<"\n错误,无该商品!
";
elsecout<<"\n恭喜,操作成功!
\n";
}
cout<<"\n\n\n|-------------------------|";
cout<<"\n|您想继续查找商品信息吗?
|\n|是(Y)否(N)|";
cout<<"\n|-------------------------|\n";
chary;
cin>>y;
if(y=='Y'||y=='y')gotoloop;//loop是一个c语言语句行的标号,就是为了配合goto(跳转)语句而给某行程序起的名字。
}
voidSale:
:
show()//显示商品
{
if(head==NULL)cout<<"\n\n产商品信息为空!
(库中暂无商品)";
else
{
cout<<"\n\n\n\n█商品价目信息█\n";
inti=0;
Goods*p=head;
cout<<"\n|---------------------------------------------------------------------------|";
while(p)
{
if(p->getn1()-p->getn2()>0)
{
cout<<"\n|["<
"<getsyh()<<"商品名"<getn()<<"\t单价:
"<getp()<<"总数:
"<getn1()<<"已卖数:
"<getn2()<<"剩余数:
"<getn1()-p->getn2();
cout<<"\n|---------------------------------------------------------------------------|";
}
if(p->getn1()-p->getn2()<=0)
{
cout<<"\n|["<
"<getsyh()<<"商品名"<getn()<<"\t单价:
"<getp()<<"总数:
"<getn1()<<"已卖数:
"<getn2()<<"剩余数:
"<getn1()-p->getn2()<<"\
\n(注意,货源为零。
请及时进货!
)";
cout<<"\n|---------------------------------------------------------------------------|";
}
p=p->getnext();
i++;
}
cout<<"\n|商品种类数:
"<
cout<<"\n|---------------|\n\n\n\n";
}
}
voidSale:
:
addg()//增加商品
{loop1:
cout<<"\n\n\n█创建新商品█\n";
Goods*p=newGoods;
loop:
intsyh;
cout<<"\n请输入商品索引号";
cin>>syh;
p->setsyh(syh);
charc[20];
cout<<"\n\n请输入商品名\n";//还应输入商品条形码
cin>>c;
//检验---------------------------
Goods*p1=head;
while(p1)
{
if(strcmp(c,p1->getn())==0)
{cout<<"\n错误,商品名重复!
\n";gotoloop;
}
p1=p1->getnext();
}//------------------------------
p->setn(c);
cout<<"\n请输入价格\n";
floatpr;
cin>>pr;
p->setp(pr);
cout<<"\n请输入商品总数\n";
intn1;
cin>>n1;
p->setn1(n1);
p->setn2(0);
p->setnext(NULL);
if
(head==NULL)head=last=p;
else
{last->setnext(p);
last=last->getnext();
}
cout<<"\n恭喜,操作成功!
\n";
cout<<"\n\n\n|-------------------------|";
cout<<"\n|您想继续新建商品吗?
|\n|是(Y)否(N)|";
cout<<"\n|-------------------------|\n";
chary;
cin>>y;
if(y=='Y'||y=='y')gotoloop1;
}
voidSale:
:
delg()//删除商品
{
if(head==NULL)cout<<"产商品信息为空!
(库中暂无商品)因此不能进行此操作";//应弹出是否录入产品信息选项
else
{
cout<<"\n\n\n\n█删除商品信息█\n";
cout<<"\n|---------------------------------------|";
cout<<"\n|█删除菜单█|";
cout<<"\n|--------------------------------------|";
cout<<"\n|A全部删除|";
cout<<"\n|---------------------------------------|";
cout<<"\n|B单个删除|";
cout<<"\n|----------------------------------------|\n请您选择一个任务:
";
chary;
cin>>y;
if(y=='A'||y=='a')//全部删除
{
Goods*p=head;
while(p)
{
Goods*temp=p->getnext();
deletep;
p=temp;
}
head=last=NULL;
cout<<"\n\n数据库已经全部删除!
";
}
else//删除单个
{
loop:
inty=1;
Goods*p=head;
cout<<"\n请输入要删除商品名:
";
charn[20];
cin>>n;
while(p)
{
if(strcmp(n,head->getn())==0)
{head=head->getnext();
deletep;y=0;break;
}//第一个就是
else
{
if((p->getnext()->getn()!
=NULL)&&(strcmp(n,p->getnext()->getn()))==0)
{Goods*temp=p->getnext();
p->setnext(temp->getnext());
deletetemp;y=0;break;
}
}
p=p->getnext();
}
if(y)cout<<"\n错误,无该商品!
";
elsecout<<"\n恭喜,操作成功!
\n";
cout<<"\n\n\n|-------------------------|";
cout<<"\n|您想继续删除商品信息吗?
|\n|是(Y)否(N)|";
cout<<"\n|-------------------------|\n";
charc;
cin>>c;
if(c=='Y'||c=='y')gotoloop;
}
}
}
voidSale:
:
modify()//修改商品
{
if(head==NULL)cout<<"产商品信息为空!
(库中暂无商品)因此不能进行此操作";//应弹出是否录入产品信息选项
else
{loop:
cout<<"\n\n\n\n█修改商品信息█\n";
inty=1;
Goods*p=head;
cout<<"\n请输入要修改商品名:
";
charn[20];
cin>>n;
while(p)
{
if(strcmp(n,p->getn())==0)
{
cout<<"\n请修改索引号[原索引号:
"<getsyh()<<"]\n\n";
intsyh;
cin>>syh;
p->setsyh(syh);
cout<<"\n请修改价格[原价格:
"<getp()<<"]\n\n";
floatpr;cin>>pr;
p->setp(pr);
loop1:
cout<<"\n请修改商品总数[原总数:
"<getn1()<<",已卖数:
"<getn2()<<"]\n\n";
intn3;
cin>>n3;
p->setn1(n3);
y=0;
}
p=p->getnext();
}
if(y)cout<<"\n错误,无该商品!
";
elsecout<<"\n恭喜,操作成功!
\n";
}
cout<<"\n\n\n|-------------------------|";
cout<<"\n|您想继续修改商品信息吗?
|\n|是(Y)否(N)|";
cout<<"\n|-------------------------|\n";
chary;
cin>>y;
if(y=='Y'||y=='y')gotoloop;
}
voidSale:
:
saveg()//保存信息
{//写入文件
ofstreamwf("good.txt",ios:
:
in|ios:
:
trunc,filebuf:
:
openprot);
if(wf.fail())cout<<"\n\n文件读取错误!
";
else
{
Goods*p=head;
intn=0;
while(p)
{
wf.write((char*)p,sizeof(Goods));
p=p->getnext();
n++;
}
//cout<<"\n\n保存"<";
}
//关闭文件
wf.close();
}
voidSale:
:
chaxun()//查询菜单
{
charc2;
do
{
cout<<"\n|-------------------------------------------|";
cout<<"\n|█查询菜单█|";
cout<<"\n|-------------------------------------------|";
cout<<"\n|A查找商品|";
cout<<"\n|--------------------------------------------|";
cout<<"\n|B查询所有|";
cout<<"\n|--------------------------------------------|";
cout<<"\n|C商品排名|";
cout<<"\n|--------------------------------------------|";
cout<<"\n|D退出查询|";
cout<<"\n|--------------------------------------------|";
cout<<"\n|请您选择一个任务|";
cout<<"\n|-------------------------------------------|\n\n\n";
cin>>c2;
switch(c2)
{case'a':
case'A':
query();break;
case'b':
case'B':
show();break;
case'c':
case'C':
rank();break;
case'd':
case'D':
break;
}
}
while(c2!
='d'&&c2!
='D');
}//break;
voidSale:
:
guanli()//管理菜单
{
charc3;
do
{
cout<<"\n|--------------------------------------------|";
cout<<"\n|█商品管理█|";
cout<<"\n|--------------------------------------------|";
cout<<"\n|A新建商品|";
cout<<"\n|-------------------------------------------|";
cout<<"\n|B删除商品|";
cout<<"\n|-----------------------------------------