物资管理系统c++.docx
- 文档编号:555273
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:11
- 大小:16.97KB
物资管理系统c++.docx
《物资管理系统c++.docx》由会员分享,可在线阅读,更多相关《物资管理系统c++.docx(11页珍藏版)》请在冰点文库上搜索。
物资管理系统c++
#include
#include
#include
(1)
#include
#include
#include
#include
classBrand//品牌
{
private:
charbrnd_name[20];//品牌名称
intBrand_code;//品牌代号
intquantity;//数量
floatbrnd_price;//价格
public:
voidgetdata();//输入数据
voidshowdata();//删除数据
};
classItem//品种
{
private:
charItem_name[10];//品种名称
intItem_code;//品种代号
charcolour[10];//颜色
intquantity;//数量
floatItem_price;//新增成员价格
charItem_date[14];//日期
Brandbrnd[3];//3个品牌
public:
voidgetdata();
voidshowdata();
voidadd();
voidremove();
voidsearch();
voidshowab();
voidprint();//打印当日进货表
voidprint2();//打印出货表
//私有的成员函数在内部使用
};
//GETBrandDATA
//获取商标的数据,这是临时存储空间
voidBrand:
:
getdata()
{//改用中文
cout<<"\n\n\t\t\t\t输入商标名称";
cin>>brnd_name;
cout<<"\n\t\t\t\t输入商标代码";
cin>>Brand_code;
cout<<"\n\t\t\t\t输入数量";
cin>>quantity;
cout<<"\n\t\t\t\t输入价格";
cin>>brnd_price;
}
//SHOWBrandDATA
//显示商标的数据
voidBrand:
:
showdata()
{
cout<<"\n\n\t\t\t\t名称:
";cout< cout<<"\n\n\t\t\t\t代码: ";cout< cout<<"\n\n\t\t\t\t数量: ";cout< cout<<"\n\n\t\t\t\t价格: ";cout< } //GETItemDATA //获取项目的数据,这是临时存储空间 voidItem: : getdata() { cout<<"\n\t\t\t\t输入商品名称"; cin>>Item_name; cout<<"\n\t\t\t\t输入商品代码"; cin>>Item_code; cout<<"\n\t\t\t\t输入颜色"; cin>>colour; cout<<"\n\t\t\t\t输入数量"; cin>>quantity; cout<<"\n\t\t\t\t输入价格";//为按价格检索输入价格 cin>>Item_price; cout<<"\n\t\t\t\t输入日期";//为打印进货表输入日期 cin>>Item_date;system("cls"); cout<<"\n\n\t\t\t\t输入商标1"; brnd[0].getdata();system("cls"); cout<<"\n\n\t\t\t\t输入商标2"; brnd[1].getdata();system("cls"); cout<<"\n\n\t\t\t\t输入商标3"; brnd[2].getdata();system("cls"); } //SHOWItemDATA //显示项目的数据 voidItem: : showdata() { cout<<"\n\n\t\t\t\t\t\t商品资料"; cout<<"\n\n\t\t\t\t商品名称: "; cout< //写一个字符串到标准的输出流(或缓冲区)-Writeastringtostdout cout<<"\n\n\t\t\t\t商品代码: "; cout< cout<<"\n\n\t\t\t\t颜色: "; cout< cout<<"\n\n\t\t\t\t数量: "; cout< cout<<"\n\n\t\t\t\t价格: ";//可显示价格和日期 cout< cout<<"\n\n\t\t\t\t日期: "; cout< getch(); //清屏 cout<<"\n\n\t\t\t\t商标1"< getch(); //清屏 cout<<"\n\n\t\t\t\t商标2"< getch(); //清屏 cout<<"\n\n\t\t\t\t商标3"< } //AddItem /*这个函数先把数据缓存,再放到硬盘上 */ voidItem: : add() { //清屏 //loop1: system("cls"); ofstreamfile("TIS.txt",ios: : out|ios: : ate);//打开程序以输入 if(! file)//如果程序不能被打开 { cout<<"\n\t\t\t\t错误无法打开文件\n"; getch(); exit (1); } Itemp1; p1.getdata(); //把数据写到硬盘上 file.write(reinterpret_cast } //TRAVERSE /*thisfunctionshowsthelistofalltheBrands*/ voidItem: : showab() { //清屏 //loop2: system("cls"); ifstreamfile("TIS.txt",ios: : in);//打开文件以输出 if(! file) { cout<<"\n\t\t\t\t错误无法打开文件\n";getch(); exit (1); } Itemp1; file.read(reinterpret_cast //存储数据 while(! file.eof()) { //清屏 p1.showdata();//在屏幕上显示 getch();//等待键盘输入 file.read(reinterpret_cast sizeof(Item)); } } voidItem: : search() { //clrscr(); //loop3: system("cls");charname1[10]; intcode; floatprice;//新增选项 intoption; cout<<"\n\t\t\t\t (1)按名称搜索\n\t\t\t\t (2)按代码检索\n\t\t\t\t(3)按价格检索"; cout<<"\n\t\t\t\t输入选择: "; cin>>option; //增加按价格搜索功能,用多重选择替原换条件语句 switch(option) { case1: cout<<"\n\t\t\t\t输入商品名称"; cin>>name1; code=0; price=0; break; case2: cout<<"\n\t\t\t\t输入商品代码"; cin>>code; strcpy(name1,"null"); price=0; break; case3: cout<<"\n\t\t\t\t输入商品价格"; cin>>price; code=0; strcpy(name1,"null"); break; } fstreamfile("TIS.txt",ios: : in);//OpenFileForOutput/Read if(! file)//IfFileCouldNotBeOpened { cout<<"\n\t\t\t\t错误无法打开文件\n"; getch(); exit (1); } charflag='a';//FlagToCheckIfFound Itemp1;; file.read(reinterpret_cast //ReadDataToObject while(! file.eof())//UntillThereAreContacts { if((strcmp(p1.Item_name,name1)==0)||(p1.Item_code==code)||(p1.Item_price==price))//Compare { //clrscr(); p1.showdata(); getch(); flag='z';//SetFlag break;//BreakLoop } file.read(reinterpret_cast sizeof(Item)); //ReadNextContact } if(flag! ='z')//IfNotFound { cout<<("\n\t\t\t\t商品未找到\n"); getch(); } } //REMOVEItem //removeisabitdifferentfirstallthedataexcepttheItemtobedeletedissavedinanotherfilecalleddelete... //thentheoriginalfileiswashedandallthedataiscopiedbackagain voidItem: : remove() { //loop4: //clrscr(); system("cls");charname1[10]; intcode; intoption; cout<<"\n\t\t\t\t (1)按名称删除\n\t\t\t\t (2)按代码删除"; cout<<"\n\t\t\t\t输入选择: "; cin>>option; if(option==1) { cout<<"\n\t\t\t\t输入商品名称"; cin>>name1; code=0; } else { cout<<"\n\t\t\t\t输入商品代码"; cin>>code; strcpy(name1,"null"); } ifstreamfile("TIS.txt",ios: : in); ofstreamtemp("delete.txt",ios: : trunc); ofstreamtemp2("delete2.txt",ios: : out|ios: : ate);//将删除商品写入"delete2"文件中 if(! file||! temp||! temp2) { cout<<"\n\t\t\t\t无法打开文件\n"; getch(); exit (1); } file.seekg(0); temp.seekp(0); Itemp1; file.read(reinterpret_cast while(! file.eof()) { if((strcmp(name1,p1.Item_name)==0)||(code==p1.Item_code))//比较商品资料以判断是否记入出货列表 { temp2.write(reinterpret_cast file.read(reinterpret_cast } else { temp.write(reinterpret_cast file.read(reinterpret_cast } } file.close();//关闭文件 temp.close(); ifstreamtemp1("delete.txt",ios: : in);//定义读文件 ofstreamfile1("TIS.txt",ios: : trunc);//定义写文件 temp1.seekg(0);//指针移到文件首 file1.seekp(0);//指针移到文件首 temp1.read(reinterpret_cast while(! temp1.eof()) { file1.write(reinterpret_cast temp1.read(reinterpret_cast } temp1.close(); file1.close(); } voidItem: : print()//按日期打印进货列表 { //loop5: system("cls"); chardate1[14]; cout<<"\t\t\t\t输入日期"< cin>>date1; fstreamfile("TIS.txt",ios: : in);//OpenFileForOutput/Read if(! file) { cout<<"\n\t\t\t\t错误无法打开文件\n"; getch(); exit (1); } charflag='a'; Itemp1; file.read(reinterpret_cast while(! file.eof()) { if(strcmp(p1.Item_date,date1)==0)//比较日期 { p1.showdata();//显示出一个商品 getch(); flag='z'; } file.read(reinterpret_cast } if(flag! ='z') { cout<<("\n\t\t\t\t商品未找到\n"); getch(); } } voidItem: : print2()//打印出货表 { //loop6: system("cls"); fstreamtemp2("delete2.txt",ios: : in);//OpenFileForOutput/Read if(! temp2) { cout<<"\n\t\t\t\t错误无法打开文件\n"; getch(); exit (1); } Itemp2; temp2.read(reinterpret_cast while(! temp2.eof()) { p2.showdata();//显示出货表 getch(); //读取下一商品 temp2.read(reinterpret_cast } temp2.close();//关闭文件 } //客户管理程序 voidmain() {system("cls"); system("colorf1"); Itemm; intchoice; while (1) { //clrscr(); cout<<"\n\t\t\t\t详细目录系统(TIS)"; cout<<"\n\n\t\t\t\t (1)增加商品品种\n\n\t\t\t\t (2)显示商品资料\n\n\t\t\t\t(3)搜索商品品种\n\n\t\t\t\t(4)删除商品\n\n\t\t\t\t(5)商品出货表\n\n\t\t\t\t(6)商品进货表\n\n\t\t\t\t(0)退出TIS"; cout<<"\n\n\t\t\t\t输入选择"; cin>>choice; switch(choice) { case1: m.add(); //system("cls"); //gotoloop1; break; case2: m.showab(); //gotoloop2; break; case3: m.search(); //gotoloop3; break; case4: m.remove(); //gotoloop4; break; case5: m.print2(); //gotoloop5; break; case6: m.print(); //gotoloop6; break; case0: { exit (1); } } } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 物资 管理 系统 c+