源代码.docx
- 文档编号:27773828
- 上传时间:2023-07-04
- 格式:DOCX
- 页数:20
- 大小:17.99KB
源代码.docx
《源代码.docx》由会员分享,可在线阅读,更多相关《源代码.docx(20页珍藏版)》请在冰豆网上搜索。
源代码
#ifndef_MYGOODS_
#define_MYGOODS_
classGOODS
{
private:
chargoodsId[20];
chargoodsName[20];
DATEgoodsDate;
chargoodsType[20];
floatgoodsPrice;
intgoodsMonths;
staticintcount;
public:
voidshowGoodssPrice(void);
voidshowGoodssmonths(void);
voidshowGoodssdate(void);
voidshowGoodsstype(void);
voidshowGoodssName(void);
voidmodifySurface(void);
voidshowSurface(void)const;
voiddelSurface(void);
voidgetSum(void);
voidaddGoods(void);
voidmodifyGoods(void);
voiddeleteGoods(void);
voidshowGoods(void);
voidshowAllGoods(void);
voidshowGoodssId(void);
voidsortGoods(void);
voidoverdueGoods(void);
voidstatistics(void);
voiddeleteAllGoods(void);
staticvoidGoodscount(void);
};
intGOODS:
:
count=0;
voidGOODS:
:
showGoodsstype(void)
{
system("cls");
fstreamfile;
intcount=0;
intflag=1;
chartypes[20];
cout<<"请输入物品类型:
";
cin>>types;
system("cls");
cout<<"所查询到的信息一下:
"< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) if(! strcmp(types,goodsType)) { flag=0; count++; showGoods(); } file.close(); cout< if(flag) { cout<<"没有您所输入的数据,按任意键返回! "< } else { cout<<"按任意键返回! "< } getch(); } voidGOODS: : showGoodssName(void) { system("cls"); fstreamfile; intcount=0; intflag=1; charnames[20]; cout<<"请输入名字: "; cin>>names; system("cls"); cout<<"所查询到的信息一下: "< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) { if(! strcmp(names,goodsName)) { flag=0; count++; showGoods(); } } file.close(); cout< if(flag) { cout<<"没有您所输入的数据,按任意键返回! "< } else { cout<<"按任意键返回! "< } getch(); } voidGOODS: : showGoodssmonths(void) { system("cls"); fstreamfile; intcount=0; intflag=1; intmonths; cout<<"请输入保质期: "; cin>>months; system("cls"); cout<<"所查询到的信息一下: "< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) if(months==goodsMonths) { flag=0; count++; showGoods(); } file.close(); cout< if(flag) cout<<"没有您所输入的数据,按任意键返回! "< else cout<<"按任意键返回! "< getch(); return; } voidGOODS: : showGoodssdate(void) { system("cls"); fstreamfile; intyears,months,days; intcount=0; intflag=1; cout<<"请输入日期: "< cout<<"请输入年: "; cin>>years; cout<<"请输入月: "; cin>>months; cout<<"请输入天: "; cin>>days; system("cls"); cout<<"所查询到的信息一下: "< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) if(goodsDate.year==years&&months==goodsDate.month&&goodsDate.day==days) { flag=0; count++; showGoods(); } file.close(); cout< if(flag) cout<<"没有您所输入的数据,按任意键返回! "< else cout<<"按任意键返回! "< getch(); } voidGOODS: : showGoodssPrice(void) { system("cls"); fstreamfile; intcount=0; intflag=1; intprice; cout<<"请输入价格: "; cin>>price; system("cls"); cout<<"所查询到的信息一下: "< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) if(price==goodsPrice) { flag=0; count++; showGoods(); } file.close(); cout< if(flag) cout<<"没有您所输入的数据,按任意键返回! "< else cout<<"按任意键返回! "< getch(); } voidGOODS: : modifySurface(void) { GOODSgoods; intchooice; while (1) { system("cls"); intflag=0; cout<<"\n********************************************************************************\n"; cout<<"修改个人物品数据\n"; cout<<"\n********************************************************************************\n"; cout<<"1.按照你输入您的编号修改\n"; cout<<"2.返回上级菜单\n"; cout<<"0.退出\n"; cout<<"\n________________________________________________________________________________\n"; cout<<"请选择<0~3>: \n"; cin>>chooice; switch(chooice) { case1: goods.modifyGoods();break; case2: flag=1;break; case0: exit (1); } if(flag) break; } cout<<"按任意键返回"< } voidGOODS: : deleteAllGoods(void) { system("cls"); fstreamfile; file.open(filename,ios: : trunc); file.close(); cout<<"删除成功,按任意键返回"< getch(); } voidGOODS: : delSurface(void) { GOODSgoods; intchooice; while (1) { system("cls"); intflag=0; cout<<"\n********************************************************************************\n"; cout<<"删除个人物品数据\n"; cout<<"\n********************************************************************************\n"; cout<<"1.按照你输入您的编号删除\n"; cout<<"2.删除所有的物品\n"; cout<<"3.返回上级菜单\n"; cout<<"0.退出\n"; cout<<"\n________________________________________________________________________________\n"; cout<<"请选择<0~3>: \n"; cin>>chooice; switch(chooice) { case1: goods.deleteGoods();break; case2: goods.deleteAllGoods();break; case3: flag=1;break; case0: exit (1); } if(flag) { break; } } cout<<"按任意键返回"< } voidGOODS: : showSurface(void)const { GOODSgoods; intchooice; while (1) { system("cls"); intflag=0; cout<<"\n********************************************************************************\n"; cout<<"查询个人物品数据\n"; cout<<"\n********************************************************************************\n\n"; cout<<"1.按照你输入编号查询具体信息\n\n"; cout<<"2.按照你输入名字查询具体信息\n\n"; cout<<"3.按照你输入类型查询具体信息\n\n"; cout<<"4.按照你输入日期查询具体信息\n\n"; cout<<"5.按照你输入保质期查询具体信息\n\n"; cout<<"6.按照你输入价格查询具体信息\n\n"; cout<<"7.查询所有的物品具体信息\n\n"; cout<<"8.查询过期或月内将过期的物品具体信息\n\n"; cout<<"9.返回上级菜单\n\n"; cout<<"0.退出\n"; cout<<"\n________________________________________________________________________________\n"; cout<<"请选择<0~3>: \n"; cin>>chooice; switch(chooice) { case1: goods.showGoodssId();break; case2: goods.showGoodssName();break; case3: goods.showGoodsstype();break; case4: goods.showGoodssdate();break; case5: goods.showGoodssmonths();break; case6: goods.showGoodssPrice();break; case7: goods.showAllGoods();break; case8: goods.overdueGoods();break; case9: flag=1;break; case0: exit (1); } if(flag) break; } cout<<"按任意键返回"< } voidGOODS: : Goodscount(void) { cout<<"总物品件数: "< } voidGOODS: : showAllGoods(void) { system("cls"); fstreamfile; intcount=0; cout<<"所查询到的信息一下: "< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) { count++; showGoods(); } file.close(); cout< cout<<"按任意键返回"< getch(); } voidGOODS: : getSum(void) { system("cls"); charid[20],type[20],name[20]; intyears,months,days; floatprice; intmon; cout<<"个人物品编号: "; cin>>id; strcpy(goodsId,id); cout<<"个人物品名称: "; cin>>name; strcpy(goodsName,name); cout<<"个人物品生产日期(年): "; cin>>years; goodsDate.year=years; cout<<"个人物品生产日期(月): "; cin>>months; goodsDate.month=months; cout<<"个人物品生产日期(日): "; cin>>days; goodsDate.day=days; cout<<"个人物品保质期(月): "; cin>>mon; goodsMonths=mon; cout<<"个人物品价格: "; cin>>price; goodsPrice=price; cout<<"个人物品类型: "; cin>>type; strcpy(goodsType,type); } voidGOODS: : addGoods(void) { system("cls"); cout<<"\n********************************************************************************\n"; cout<<"添加个人物品数据\n"; cout<<"\n********************************************************************************\n"; count++; fstreamfile; file.open(filename,ios: : out|ios: : app); getSum(); file.write((char*)this,sizeof(GOODS)); file.close(); } voidGOODS: : modifyGoods(void) { system("cls"); fstreamfile; intj=0; charid[20]; cout<<"请输入编号: "; cin>>id; system("cls"); file.open(filename,ios: : in|ios: : out); file.seekg(0,ios: : beg); while(file.read((char*)this,sizeof(GOODS))) { if(strcmp(id,goodsId)) j++; else break; } if(! strcmp(id,goodsId)) { intlocation=j*sizeof(GOODS); if(file.eof()) file.clear(); file.seekg(location); getSum(); file.write((char*)this,sizeof(GOODS))< ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? file.close(); } else cout<<"没有您所输入的数据,按任意键返回! "< } voidGOODS: : deleteGoods(void) { system("cls"); fstreamfile; fstreamtemp; charid[20]; cout<<"请输入编号: "; cin>>id; system("cls"); temp.open(Tfilename,ios: : out); file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) if(strcmp(id,goodsId)) temp.write((char*)this,sizeof(GOODS)); file.close(); temp.close(); temp.open(Tfilename,ios: : in); file.open(filename,ios: : out); if(file.eof()) file.clear(); temp.seekg(0,ios: : beg); file.seekg(0,ios: : beg); while(temp.read((char*)this,sizeof(GOODS))) file.write((char*)this,sizeof(GOODS)); file.close(); temp.close(); } voidGOODS: : showGoodssId(void) { system("cls"); fstreamfile; intcount=0; intflag=1; charid[20]; cout<<"请输入编号: "; cin>>id; system("cls"); cout<<"所查询到的信息一下: "< file.open(filename,ios: : in); while(file.read((char*)this,sizeof(GOODS))) if(! strcmp(id,goodsId)) { flag=0; count++; showGoods(); } file.close(); cout< if(flag) cout<<"没有您所输入的数据,按任意键返回! "< else cout<<"按任意键返回! "< getch(); } voidGOODS: : showGoods(void) { cout<<"编号: "< "< "生产日期: "< goodsDate.day< "<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 源代码