版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、-1-模擬超市的收銀系統(tǒng)一、系統(tǒng)分析與設計。隨著計算機的發(fā)展, 計算機技術已經(jīng)融入到社會生活的各個角落, 把人們從以前繁瑣的 手工操作中解放出來, 從而使信息的管理大大簡便起來。 超市日常有大量的數(shù)據(jù)需要進行處 理,包括收銀員收銀時輸入的消費者購買信息、 管理員輸入的入庫商品信息、 管理員輸入的 人員信息、 日常銷售額的統(tǒng)計等等。 面對如此大的信息量, 就需要有相應的計算機管理系統(tǒng) 來提高工作的效率和系統(tǒng)管理的安全性。 通過這樣的系統(tǒng), 超市就可以由收銀員方便的在收 銀柜臺進行銷售額的錄入, 管理員也可以方便地進行管理, 從而減小手工操作的工作量, 本 設計就是為了模擬超市的收銀系統(tǒng)。從需求分
2、析的角度來看,這個超市管理系統(tǒng)的需求如下所示:該系統(tǒng)的功能主要是模擬超市的收銀的過程, 所以不需要設計數(shù)據(jù)庫, 當進入 系統(tǒng),就會顯示倉庫里的所有貨物,當管理員輸入貨物編號(索引號)時,就會提示 你需要買的數(shù)量,輸入完成就會提示你購買成功。再就是付款。根據(jù)系統(tǒng)需求,這個版本的超市管理系統(tǒng)是一個簡單的管理系統(tǒng), 三、主要程序清單(見附錄)/* /*main.cpp系統(tǒng)主文件*#include counter.h/創(chuàng)建一個商店CStore* PrepareStore()/創(chuàng)建一個空商店CStore *pStore = new CStore();/為商店配貨CGoods *pGoods = new
3、CGoods(1, 西瓜, 4.50); pStore-AddGoods(pGoods, 1000);pGoods = new CGoods(2, 雞蛋, 5.00); pStore-AddGoods(pGoods, 1000);pGoods = new CGoods(3, 牛肉, 12.00); pStore-AddGoods(pGoods, 1000);pGoods = new CGoods(4, 香蕉, 4.10);pStore-AddGoods(pGoods, 1000);pGoods = new CGoods(5, 空調(diào), 3000.00); pStore-AddGoods(pGoo
4、ds, 100);pGoods = new CGoods(6, 大米, 1.00); pStore-AddGoods(pGoods, 10000);-2-pGoods = new CGoods(7, 葡萄, 5.00); pStore-AddGoods(pGoods, 1000);pGoods = new CGoods(8, 面包, 6.00); pStore-AddGoods(pGoods, 1000);pGoods = new CGoods(9, 火腿, 15.00); pStore-AddGoods(pGoods, 1000);return pStore;void usage() cou
5、tnn; cout.width(35); cout.fill(*); coutrightUSAGE; cout.width(35);coutleft*endl; cout*請您按照請示來購買商品,祝您消費愉快!n; cout*輸入-1,完成購買,去收銀臺n; cout.width(35); cout.fill(*); coutrightUSAGE;cout.width(35); coutleft*endl;cout.fill( ); coutPrint();usage();/ iIndex-用戶欲購買商品的索引, iNum-用戶欲購買商品的數(shù)目int iIndex = 0, iNum = 0;
6、do coutiIndex) ) coutGetGoods( iIndex );/沒有此類商品if (pSE = NULL) coutn很抱歉,本商店沒有索引號為iIndex的商品nn; continue;/購買數(shù)量cout請輸入要購買數(shù)量:;cout-歡迎光臨美特好超市cout*本超市共有以下商品,歡-nnendl;迎您的選購*iNum) ) coutQueryGoods( iIndex );if (iStoreNum = 0) cout很抱歉,你要購買的pGoods-GetName() iStoreNum ) cout很 抱 歉,本 商 店 目 前 僅 有pGoods-GetName()i
7、StoreNumpGoods-Clone();pBasket-AddGoods( pMyGoods, iStoreNum ); /加入購物籃pSE-iNum = 0; /賣光了elsecout恭喜你,成功購買:n;cout商 品: pGoods-GetName()件 數(shù):iNumnpGoods-Clone();pBasket-AddGoods( pMyGoods, iNum );/加入購物籃pSE-iNum= iStoreNum - iNum;/超市剩余-5- while(true);if (pBasket-GetAllGoods()-size() = 0) coutnn嗨,什么都沒買到,白來
8、一趟;(nn;goto CELEAN;else coutPrint();coutnn您好,您本次共計消費Counter.Bill()元n; coutdCash;while ( Counter.Count(dCash) 0 ) cout 還差: -Counter.Count(0) 元n; cout dCash;coutnn共收取您現(xiàn)金:Counter.GetCash()元n; cout應交納金額:Counter.Bill()元n;cout應找零:Counter.Count(0)元nn;/*商品類的成員函數(shù)定義/*CGoods:CGoods( int iIndex, string strName,
9、 double dUnitPrice )cout*歡迎您再次光臨本店CELEAN:delete pStore;delete pBasket; return;/ counter.cpp: implementation of the supermarket class./#include counter.h#include *-6-/初始化商品m_iIndex = iIndex; m_strName = strName; m_dUnitPrice = dUnitPrice;CGoods:CGoods()/attributes and operationsint CGoods:GetIndex(vo
10、id) const return m_iIndex;string CGoods:GetName(void) constreturn m_strName;double CGoods:GetUnitPrice(void) const return m_dUnitPrice;void CGoods:SetUnitPrice(double dUnitPrice) m_dUnitPrice = dUnitPrice;CGoods *CGoods:Clone()return new CGoods(m_iIndex, m_strName, m_dUnitPrice);/*/*商品類的成員函數(shù)定義結(jié)束/*/*
11、/*儲藏室類的成員函數(shù)定義/*CStore:CStore()-7-CStore:CStore()DeleteAllGoods();/往儲藏室種添加貨物bool CStore:AddGoods(CGoods *pGoods, int iNum)assert( pGoods != NULL );int size = m_vStore.size();bool bIsExist = false;for(int i=0; ipGoods != NULL & pSE-pGoods-GetIndex() pGoods-GetIndex() ) bIsExist = true;pSE-iNum +=
12、iNum ;break;/儲藏室沒有同類商品,直接增加此類商品if ( !bIsExist )PSTOREELEMENT p = new STOREELEMENT; p-pGoods= pGoods;p-iNum= iNum;m_vStore.push_back( p );return true;/清空整個儲藏室void CStore:DeleteAllGoods()int size = m_vStore.size();for(int i=0; ipGoods != NULL )delete pSE-pGoods;/刪除商品-8-pSE-pGoods = NULL;delete pSE;/刪除
13、儲藏室元素pSE = NULL;/刪除名為strName的貨物,iNum為刪除數(shù)量int CStore:DeleteGoods(const string &strName, intiNum)int size = m_vStore.size();for(int i=0; ipGoods != NULL & pSE-pGoods-GetName() = strName )if ( iNum iNum pGoods; pSE-iNum =0;delete pSE;/刪除儲藏室元素pSE = NULL;return 0;elsepSE-iNum -= iNum; return pSE-
14、iNum;return 0;/刪除索引號為iIndex的貨物,iNum為刪除數(shù)量int CStore:DeleteGoods(int iIndex, intiNum)int size = m_vStore.size();for(int i=0; ipGoods != NULL & pSE-pGoods-GetIndex() = iIndex ) if ( iNum iNum pGoods; pSE-iNum = 0;delete pSE;/刪除儲藏室元素pSE = NULL;return 0;elsepSE-iNum -= iNum;return pSE-iNum;-10-return
15、 0;/獲取貨物清單vector* CStore:GetAllGoods(void)return &m_vStore;/獲取某類貨物PSTOREELEMENT CStore:GetGoods(int iIndex)int size = m_vStore.size();for(int i=0; ipGoods != NULL & pSE-pGoods-GetIndex() = iIndex ) return pSE;return NULL;/獲取某類貨物PSTOREELEMENT CStore:GetGoods(const string &strName)int size
16、 = m_vStore.size();for(int i=0; ipGoods != NULL & pSE-pGoods-GetName() = strName ) returnpSE;-11-return NULL;/查詢貨物int CStore:QueryGoods(const string &strName)int size = m_vStore.size();for(int i=0; ipGoods != NULL & pSE-pGoods-GetName() = strName ) returnpSE-iNum;return 0;/查詢貨物int CStore
17、:QueryGoods(int iIndex)int size = m_vStore.size();for(int i=0; ipGoods != NULL & pSE-pGoods-GetIndex() = iIndex ) returnpSE-iNum;return 0;/打印水單void CStore:Print() string strTitle4; strTitle0 = 索引號; strTitle1 = 商品名;strTitle2 = 數(shù)量;strTitle3 = 單價;for (int i=0; i4; i+) cout.width(16); coutleftstrTit
18、lei;-12-coutnendl;/獲取商品種類int size = m_vStore.size();for (i=0; isize; i+)cout.width(16); coutleftpGoods-GetIndex();cout.width(16);coutpGoods-GetName();cout.width(16);coutiNum;cout.width(16);cout.precision(2);coutfixedpGoods-GetUnitPrice()n;/*/*儲藏室類的成員函數(shù)定義結(jié)束/*/*/*收銀臺類的成員函數(shù)定義/*CCounter:CCounter(CStore *pBasket)m_pBasket = pBasket;m_dCash= 0.0;CCounter:CCounter()/獲取帳單double CCounter:Bill(void)dou
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度醫(yī)院醫(yī)療廢物處理設施建設合同4篇
- 2025年度個人創(chuàng)業(yè)貸款合同示范文本8篇
- 二零二五年度美容院美容護膚品生產(chǎn)股份合作合同4篇
- 二零二五版木質(zhì)家具定制設計與生產(chǎn)加工合同3篇
- 二零二五年度電子商務平臺標志設計及用戶體驗合同3篇
- 二零二五年度托盤租賃與供應鏈金融結(jié)合合同范本3篇
- 二零二五年度昌平區(qū)食堂員工激勵與績效考核合同3篇
- 2025年度汽車租賃與品牌合作推廣合同范本3篇
- 二零二五年度城市綠化工程承包合同14篇
- 2025年度線上線下聯(lián)動大型促銷活動合作合同3篇
- 項目前期選址分析報告
- 急性肺栓塞搶救流程
- 《統(tǒng)計學-基于Python》 課件全套 第1-11章 數(shù)據(jù)與Python語言-時間序列分析和預測
- 《形象價值百萬》課件
- 紅色文化教育國內(nèi)外研究現(xiàn)狀范文十
- 中醫(yī)基礎理論-肝
- 小學外來人員出入校門登記表
- 《土地利用規(guī)劃學》完整課件
- GB/T 25283-2023礦產(chǎn)資源綜合勘查評價規(guī)范
- 《汽車衡全自動智能稱重系統(tǒng)》設計方案
- 義務教育歷史課程標準(2022年版)
評論
0/150
提交評論