您的位置:首页 > 其它

商品的管理系统

2014-05-22 22:48 155 查看
/*烟台大学计算机学院学生
*All right reserved.
*文件名称:商品的管理系统
*作者:杨飞
*完成日期:2014年5月20日
*版本号:v1.0
*对任务及求解方法的描述部分:商品的管理系统
*我的程序:*/
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdlib>
using namespace std;
class Product
{
private:
int hao;
string name;
string pin;
string xing;
double price;
public:
void add();
void findgood();
void findquan();
void genhao();
void genname();
void genpin();
void genxing();
void display();
void welcomeframe();
};
int size=0;
Product product[100000];
void  Product::welcomeframe()
{
cout<<"|---------------------------|"<<endl;
cout<<"|--------商品管理系统-------|"<<endl;
cout<<"|---------------------------|"<<endl;
cout<<"|--------1.增加商品---------|"<<endl;
cout<<"|--------2.查找商品---------|"<<endl;
cout<<"|--------3.查找全部商品-----|"<<endl;
cout<<"|--------4.退出系统---------|"<<endl;
cout<<"|---------------------------|"<<endl;
cout<<"请输入指令:"<<endl;
int n;
cin>>n;
switch(n)
{
case 1:
add();
break;
case 2:
findgood();
break;
case 3:
findquan();
break;
case 4:
exit(0);
}
}
void Product::add()
{
char n;
cout<<"输入商品编号:";
cin>>product[size].hao;
cout<<"输入商品名称:";
cin>>product[size].name;
cout<<"输入商品品牌:";
cin>>product[size].pin;
cout<<"输入商品型号:";
cin>>product[size].xing;
cout<<"输入价格:";
cin>>product[size].price;
cout<<"添加成功!"<<endl;
product[size].display();
size++;
cout<<"是否继续添加图书(是y,否n)"<<endl;
cin>>n;
if(n=='y')
Product::add();
if(n=='n')
welcomeframe();
}
void Product::genhao()
{
int n,h=1;
cout<<"请输入你想查找的编号:"<<endl;
cin>>n;
for(int i=0;i<size;i++)
{
if(product[i].hao==n)
{
product[i].display();
h=2;
}
if(h==1)
cout<<"查无此物!"<<endl;
}
welcomeframe();
}
void Product::findgood()
{
cout<<"|---------------------------------|"<<endl;
cout<<"|--------1.以商品编号查找---------|"<<endl;
cout<<"|--------2.以商品名查找-----------|"<<endl;
cout<<"|--------3.以商品品牌查找-----------|"<<endl;
cout<<"|--------4.以商品型号查找-----------|"<<endl;
cout<<"|--------5.回到主菜单-------------|"<<endl;
cout<<"|---------------------------------|"<<endl;
cout<<"请输入指令:";
int n;
cin>>n;
switch(n)
{
case 1:
genhao();
break;
case 2:
genname();
break;
case 3:
genpin();
break;
case 4:
genxing();
break;
case 5:
welcomeframe();
break;
}
}
void Product::findquan()
{
for(int i=0;i<size;i++)
{
product[i].display();
}
welcomeframe();
}
void Product::genname()
{
int h=1;
string n;
cout<<"请输入你想查找的商品名字:"<<endl;
cin>>n;
for(int i=0;i<size;i++)
{
if(product[i].name==n)
{
product[i].display();
h=2;
}
if(h==1)
cout<<"查无此物!"<<endl;
}
welcomeframe();
}
void Product::genpin()
{
int h=1;
string n;
cout<<"请输入你想查找的商品品牌:"<<endl;
cin>>n;
for(int i=0;i<size;i++)
{
if(product[i].pin==n)
{
product[i].display();
h=2;
}
if(h==1)
cout<<"查无此物!"<<endl;
}
welcomeframe();
}
void Product::genxing()
{
int h=1;
string n;
cout<<"请输入你想查找的商品型号:"<<endl;
cin>>n;
for(int i=0;i<size;i++)
{
if(product[i].xing==n)
{
product[i].display();
h=2;
}
if(h==1)
cout<<"查无此物!"<<endl;
}
welcomeframe();
}
void Product::display()
{
cout<<"+-----------------------------------------------------------------------+"<<endl;
cout<<setiosflags(ios::left)<<"+"<<setw(10)<<"商品编号"<<setw(10)<<"商品名称"<<setw(10)<<"品牌"<<setw(10)<<"型号"<<setw(10)<<"价格"<<setw(3)<<"|"<<endl;
cout<<"|-----------------------------------------------------------------------|"<<endl;
for(int i=0;i<size;i++)
{
cout<<setiosflags(ios::left)<<"|"<<setw(10)<<product[i].hao<<setw(10)<<product[i].name<<setw(10)<<product[i].pin<<setw(10)<<product[i].xing<<setw(10)<<product[i].price<<setw(3)<<"|"<<endl;
}
}
int main()
{
Product p;
p.welcomeframe();
return 0;
}

运行结果:


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: