S1 商品信息管理系统
生活随笔
收集整理的這篇文章主要介紹了
S1 商品信息管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
//void welcome();//歡迎界面
void display(int);//輸出信息
int size=0;
class Product
{
public:void addProduct();void queryById();void queryByName();void queryByBrand();void queryByMode();void queryAll();void welcome();void find();void show();double setId(){return Id;}string setName(){return Name;}string setBrand(){return Brand;}string setMode(){return Mode;}double setprice(){return price;}
private:int Id;string Name;string Brand;string Mode;double price;
};
Product product[10000];
void Product::welcome()
{int n,a;cout<<"*---------------------------*"<<endl;cout<<"|--------商品管理系統-------|"<<endl;cout<<"|---------------------------|"<<endl;cout<<endl;cout<<"|---------------------------|"<<endl;cout<<"|--------1.添加商品---------|"<<endl;cout<<"|--------2.查找商品---------|"<<endl;cout<<"|--------3.查找所有商品-----|"<<endl;cout<<"|--------4.退出系統---------|"<<endl;cout<<"*---------------------------*"<<endl;cout<<"請輸入指令:"<<endl;cin>>n;switch(n){case 1:Product::addProduct();Product::welcome();break;case 2:while(1){Product::find();cin>>a;if(a==1)Product::queryById();else if(a==2)Product::queryByName();else if(a==3)Product::queryByBrand();else if(a==4)Product::queryByMode();elseProduct::welcome();}break;case 3:Product::show();break;case 4:break;default:break;}
}
void Product::find()
{cout<<"*---------------------------------*"<<endl;cout<<"|--------1.以圖書編號查找---------|"<<endl;cout<<"|--------2.以圖書名查找-----------|"<<endl;cout<<"|--------3.以作者名查找-----------|"<<endl;cout<<"|--------4.以出版社查找-----------|"<<endl;cout<<"|--------5.回到主菜單-------------|"<<endl;cout<<"*---------------------------------*"<<endl;cout<<"請輸入指令:";}
void Product::addProduct()
{char m;cout<<"輸入商品編號:";cin>>product[size].Id;cout<<"輸入商品名稱:";cin>>product[size].Name;cout<<"輸入商品品牌:";cin>>product[size].Brand;cout<<"輸入商品型號:";cin>>product[size].Mode;cout<<"輸入價格:";cin>>product[size].price;cout<<"加入成功!"<<endl;display(size);size++;cout<<"是否繼續加入圖書(是y,否n)"<<endl;cin>>m;if(m=='y')Product::addProduct();if(m=='n')Product::welcome();
}
void display(int i)
{cout<<"+-----------------------------------------------------------------------+"<<endl;cout<<setiosflags(ios::left)<<"+"<<setw(10)<<"商品編號"<<setw(10)<<"商品名稱"<<setw(10)<<"品牌"<<setw(10)<<"型號"<<setw(10)<<"價格"<<setw(3)<<"|"<<endl;cout<<"|-----------------------------------------------------------------------|"<<endl;cout<<setiosflags(ios::left)<<"|"<<setw(10)<<product[i].setId()<<setw(10)<<product[i].setName()<<setw(10)<<product[i].setBrand()<<setw(10)<<product[i].setBrand()<<setw(10)<<product[i].setprice()<<setw(3)<<"|"<<endl;cout<<"+-----------------------------------------------------------------------+"<<endl;
}
void Product::queryById()
{int id;cout<<"輸入要查詢的商品編號:"<<endl;cin>>id;bool flag=false;int n;for(n=0; n<=size; n++)if(id==product[n].Id){flag=true;break;}if(flag)display(n);elsecout<<"無查詢結果!"<<endl;
}
void Product::queryByName()
{string name;cout<<"輸入要查詢的商品名稱:"<<endl;cin>>name;bool flag=false;int n;for(n=0; n<=size; n++)if(name==product[n].Name){flag=true;break;}if(flag)display(n);elsecout<<"查無此商品!"<<endl;
}
void Product::queryByBrand()
{string brand;cout<<"輸入要查詢的商品品牌:"<<endl;cin>>brand;int n;bool flag=false;for(n=0; n<=size; n++)if(brand==product[n].Brand){flag=true;break;}if(flag)display(n);elsecout<<"查無此商品!
"<<endl; } void Product::queryByMode() { string mode; cout<<"輸入要查詢的商品型號:"<<endl; cin>>mode; int n; bool flag=false; for(n=0; n<=size; n++) if(mode==product[n].Mode) { flag=true; break; } if(flag) display(n); else cout<<"查無此商品!
"<<endl; } void Product::show() { for(int n=0; n<size; n++) { display(n); } } int main() { Product p; p.welcome(); return 0; }
感悟:在上一個的基礎上 再做這個就相對easy多了!? 累的脖子疼 趴在床上編程序不easy啊。
轉載于:https://www.cnblogs.com/cxchanpin/p/6898673.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的S1 商品信息管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Sublime Text 3 安装Pac
- 下一篇: linux下su和su - 的区别