c倉庫管理系統_第1頁
c倉庫管理系統_第2頁
c倉庫管理系統_第3頁
c倉庫管理系統_第4頁
c倉庫管理系統_第5頁
已閱讀5頁,還剩18頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

c++庫房管理系統#include<iostream>#include<fstream>usingnamespacestd;constintm=100;//定義常量mclassStore//定義類{private:intnum;//編號charname[20];//名稱doubleprice;//價錢intquantity;//數目intamount;//數目public:voidInput( );intInput_2( );voidDig( );voidChange( );voidSearch_num( );voidSearch_name( );voidShow( );voidShort( );voidDelete( );}goods[m];voidStore::Input( )//創(chuàng)立表單{inti,n;cout<<"請輸入貨物總數:";cin>>amount;cout<<endl;for(i=0;i<amount;i++){cout<<"這是第"<<(i+1)<<"貨物信息"<<endl;goods[i].num=i+1;cout<<"貨物名:";cin>>goods[i].name;cout<<"單價:";cin>>goods[i].price;cout<<"庫存量:";cin>>goods[i].quantity;cout<<endl;}cout<<"\n輸入的信息:"<<endl;for(i=0;i<amount;i++){cout<<"貨號:"<<goods[i].num<<ends;cout<<"貨物名:"<<goods[i].name<<ends;cout<<"單價:"<<goods[i].price<<ends;cout<<"庫存量:"<<goods[i].quantity<<ends<<endl;}ofstreamos("goods.txt",ios_base::out|ios_base::binary);//創(chuàng)立、翻開文件for(n=0;n<amount;n++){os.write(reinterpret_cast<char*>(&(goods[n])),sizeof(Store));//導出文件}os.close( );//封閉文件}intStore::Input_2( )//文件讀入{inti,n;ifstreamis("goods.txt",ios_base::in|ios_base::binary);if(!is){cout<<"翻開失敗"<<endl;return0;}for(i=0;is.read(reinterpret_cast<char*>(goods+i),sizeof(Store));i++)amount=i;cout<<"導入的表單:"<<endl;for(n=0;n<amount;n++){cout<<"貨號:"<<goods[n].num<<ends;cout<<"貨物名:"<<goods[n].name<<ends;cout<<"單價:"<<goods[n].price<<ends;cout<<"庫存量:"<<goods[n].quantity<<ends<<endl;}return1;}voidStore::Dig( )//插入信息{inti,n,m;cout<<"請輸入增添的貨物總數:";cin>>n;cout<<endl;for(i=0;i<n;i++){cout<<"這是第"<<(i+1)<<"貨物信息"<<endl;goods[amount+i].num=amount+i+1;cout<<"貨物名:";cin>>goods[amount+i].name;cout<<"單價:";cin>>goods[amount+i].price;cout<<"庫存量:";cin>>goods[amount+i].quantity;}cout<<"\n輸入的信息"<<endl;for(i=0;i<amount+n;i++){cout<<"貨號:"<<goods[i].num<<ends;cout<<"貨物名:"<<goods[i].name<<ends;cout<<"單價:"<<goods[i].price<<ends;cout<<"庫存量:"<<goods[i].quantity<<ends<<endl;}amount=amount+n;ofstreamos("goods.txt",ios_base::out|ios_base::binary);//創(chuàng)立、翻開文件for(m=0;m<amount;m++){os.write(reinterpret_cast<char*>(&(goods[m])),sizeof(Store));//導出文件}os.close( );//封閉文件};voidStore::Change( )//改正信息{intn,i,m;cout<<"要改正第幾個貨物的信息(輸入貨號):";cin>>n;cout<<endl;cout<<"請輸入改正的信息"<<endl;cout<<"貨物名:";cin>>goods[n-1].name;cout<<"單價:";cin>>goods[n-1].price;cout<<"庫存量:";cin>>goods[n-1].quantity;cout<<endl;cout<<"改正后的信息:"<<endl;for(i=0;i<amount;i++){cout<<"貨號:"<<goods[i].num<<ends;cout<<"貨物名:"<<goods[i].name<<ends;cout<<"單價:"<<goods[i].price<<ends;cout<<"庫存量:"<<goods[i].quantity<<ends<<endl;}ofstreamos("goods.txt",ios_base::out|ios_base::binary);//創(chuàng)立、翻開文件for(m=0;m<amount;m++){os.write(reinterpret_cast<char*>(&(goods[m])),sizeof(Store));//導出文件}os.close( );//封閉文件}voidStore::Search_num( )//按編號查{intn;cout<<"請輸入貨號:";do{cin>>n;cout<<endl;if(n<=amount){cout<<"貨號:"<<goods[n-1].num<<ends;cout<<"貨物名:"<<goods[n-1].name<<ends;cout<<"單價:"<<goods[n-1].price<<ends;cout<<"庫存量:"<<goods[n-1].quantity<<ends<<endl;}elseif(n>amount){cout<<"輸入錯誤,請從頭輸入:"<<ends;}}while(n>amount);};voidStore::Search_name( )//按名稱查{intflag=0;inti;charx[20];cout<<"請輸入貨物名:";do{cin>>x;cout<<endl;for(i=0;i<amount;i++){if(strcmp(goods[i].name,x)==0)//strcmp用來比較字符串.tname和x{flag=1;cout<<"貨號:"<<goods[i].num<<ends;cout<<"貨物名:"<<goods[i].name<<ends;cout<<"單價:"<<goods[i].price<<ends;cout<<"庫存量:"<<goods[i].quantity<<ends<<endl;}else;}if(flag==0)cout<<"輸入錯誤,請從頭輸入:"<<ends;}while(flag==0);};voidStore::Show( )//顯示信息{inti;for(i=0;i<amount;i++){cout<<"貨號:"<<goods[i].num<<ends;cout<<"貨物名:"<<goods[i].name<<ends;cout<<"單價:"<<goods[i].price<<ends;cout<<"庫存量:"<<goods[i].quantity<<ends<<endl;}};voidStore::Short( )//查問不足貨物{intflag=0;inti;inty;cout<<"請查問庫存量:";do{cin>>y;cout<<endl;for(i=0;i<amount;i++){if(goods[i].quantity<=y){flag=1;cout<<"貨號:"<<goods[i].num<<ends;cout<<"貨物名:"<<goods[i].name<<ends;cout<<"單價:"<<goods[i].price<<ends;cout<<"庫存量:"<<goods[i].quantity<<ends<<endl;}else;}if(flag==0)cout<<"沒有貨物,請從頭輸入:"<<ends;}while(flag==0);};voidStore::Delete( )//刪除貨物{chary[20];intn,m;cout<<"請輸入要刪除的貨物名:";cin>>y;for(inti=0;i<amount;i++){if(strcmp(goods[i].name,y)==0)//strcmp用來比較字符串.tname和y{for(;i<amount;i++){goods[i]=goods[i+1];goods[i].num=i+1;}amount=amount-1;//貨物數減一}}cout<<"刪除后貨單:"<<endl;for(m=0;m<amount;m++){cout<<"貨號:"<<goods[m].num<<ends;cout<<"貨物名:"<<goods[m].name<<ends;cout<<"單價:"<<goods[m].price<<ends;cout<<"庫存量:"<<goods[m].quantity<<ends<<endl;}ofstreamos("goods.txt",ios_base::out|ios_base::binary);//創(chuàng)立、翻開文件for(n=0;n<amount;n++){os.write(reinterpret_cast<char*>(&(goods[n])),sizeof(Store));//導出文件}os.close( );//封閉文件};voidClear( )//清屏函數{chara;a=getchar( );system("cls");}voidmenuPrint( )//主菜單{cout<<"\t*****庫房管理*****"<<endl;cout<<"\t*1.輸入貨物信息*"<<endl;cout<<"\t*2.查問貨物信息*"<<endl;cout<<"\t*3.顯示貨物信息*"<<endl;cout<<"\t*4.顯示不足貨物*"<<endl;cout<<"\t*5.刪除貨物信息*"<<endl;cout<<"\t*6.退出系統*"<<endl;cout<<"\t**********************"<<endl;cout<<"請輸入你要進行的操作(1~6):"<<endl;}intmain( )//主函數{StoreGoods;//定義對象intn;do{menuPrint( );//調用主菜單cin>>n;cout<<endl;switch(n){case1://輸入貨物信息{inta;cout<<"輸入方式"<<endl;cout<<"1.創(chuàng)立表單"<<endl;cout<<"2.從文件導入"<<endl;cout<<"3.插入信息"<<endl;cout<<"4.改正信息"<<endl;cout<<"5.返回主菜單"<<endl;cin>>a;cout<<endl;switch(a){case1://調用創(chuàng)立函數Goods.Input( );break;case2://調用文件讀入函數Goods.Input_2( );break;case3://調用增添函數Goods.Dig( );break;case4://調用增添函數Goods.Change( );break;case5:break;default:cout<<"您的輸入有誤,請從頭選擇"<<endl;break;}break;}case2://查問{inta;cout<<"查問方式"<<endl;cout<<"1.按編號查問"<<endl;cout<<"2.按名稱查問"<<endl;cout<<"3.返回主菜單"<<endl;cin>>a;cout<<endl;switch(a){case1://調用函數(按貨號查)Goods.Search_num( );break;case2:/

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論