




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 對象數組的使用 題目要求:實現超市購物結算并輸出購物小票功能。首先顯示所有商品信息,然后輸入購物的商品編號和數量進行購物結算,最后輸出購物小票。程序運行結果如圖4.12所示。要求如下:商品單價顯示為兩位小數,商品的小計和總計顯示為貨幣形式,保留兩位小數購物小票的四列均為左對齊,商品名稱列寬度為8,后三列寬度為4參考代碼:商品類: / <summary> / 商品類 / </summary> class Goods int _id; / <summary> / 商品編號 / </summary> public int Id get return
2、_id; set _id = value; string _name; / <summary> / 商品名稱 / </summary> public string Name get return _name; set _name = value; double _price; / <summary> / 商品價格 / </summary> public double Price get return _price; set _price = value; 購物類: / <summary> / 購物類 / </summary>
3、; class Shopping string _list; Goods goodsList; / <summary> / 初始化商品信息 / </summary> private void Initial() this.goodsList = new Goods3; this.goodsList0 = new Goods(); this.goodsList0.Name = "農夫山泉" this.goodsList0.Price = 1.025; this.goodsList1 = new Goods(); this.goodsList1.Name
4、 = "今麥郎碗面" this.goodsList1.Price = 3.5; this.goodsList2 = new Goods(); this.goodsList2.Name = "雙匯火腿腸" this.goodsList2.Price = 12.6; / <summary> / 顯示商品信息 / </summary> private void ShowGoodsInfo() Console.WriteLine("0,-4t1,-8t2:0.00","編號","商品名稱&
5、quot;,"單價"); for (int i = 0; i < this.goodsList.Length; i+) Console.WriteLine("0,-4t1,-8t2:0.00", i + 1, this.goodsListi.Name, this.goodsListi.Price); / <summary> / 打印購物小票 / </summary> public void PrintList() this.Initial(); / 初始化商品信息 this.ShowGoodsInfo(); / 顯示商品信息
6、 double sum = 0; / 購物金額 this._list = "nn-歡迎光臨光輝超市-" this._list = string.Format("0n1,-8t2,-4:F2t3,-4t4,-4:F2", this._list, "商品名稱", "單價", "數量", "小計"); do Console.Write("n輸入商品編號:"); int num = int.Parse(Console.ReadLine(); if (num >
7、; 3 | num < 1) Console.WriteLine("請重新選擇商品編號!"); continue; Console.Write("輸入購買數量:"); int amount = int.Parse(Console.ReadLine(); / 添加購物信息到購物小票 this._list = string.Format("0n1,-8t2,-4:F2t3,-4t4,-4:C2", this._list, this.goodsListnum - 1.Name, this.goodsListnum - 1.Price, amount, this.goodsListnum - 1.Price * amount); / 計算購物總額 sum += this.goodsListnum - 1.Price * amount; Console.Write("輸入e停止購物,輸入其他任意鍵繼續購物:"); if (Console.ReadLine() = "e") break; while (true); / 添加購物總額到購物小票 this._list = string.Format(&qu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國倉儲式雙柱雙面書架市場調查研究報告
- 2025年解除勞動合同簡易范本
- 2025年農村環保改廁項目合同書
- 2025濟南市事業單位勞動合同書
- 2025設備采購合同示范文本格式
- 2025大連市家具銷售合同范本
- 2025建筑材料采購合同版
- 2025中外合資企業醫療保險合同
- 2025機械制造有限公司設備維修合同協議書
- 2025股權轉讓合同書
- 2025-2030工程塑料行業市場深度分析及發展策略研究報告
- 2025-2030中國涂料設備行業市場發展趨勢與前景展望戰略研究報告
- 業務員合同范本與業務員和公司的合同6篇
- 2025年大學生學習鄉村振興知識競賽題庫及答案(共60道題)
- 2025年廣東廣州市高三二模高考英語試卷試題(含答案詳解)
- 期中考試質量分析會上校長引用6個關鍵詞講話:深耕、融合、賦能、深耕、創新、協同、堅守
- JJF 2230-2025混凝土電阻率測試儀校準規范
- 【9數一模】2025年安徽合肥市第四十五中學九年級中考一模數學試卷(含答案)
- 掛靠法人免責協議書
- 煤炭加工中的選煤技術與選煤機械考核試卷
- 2025年中石油政工師理論考試題庫(含答案)
評論
0/150
提交評論