[問題] TQC+ 練習題,請協助解題意

看板C_Sharp作者 (小偉偉)時間8年前 (2015/08/01 12:02), 8年前編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
各位大大好: 本人預計報名TQC+ C#程式設計,並購買參考書,在練習的時候有一題練習題, 本人一直不是很了解題意,雖然答案同參考答案顯示畫面,但因無參考原始碼 ,不確定是否符合題意,可否請各位協助解題意? 在此先謝過了。 ===TQC + 題目========== 2. 設計說明: (1) 程式內已定義四種不同市場的 CustomerType 列舉值,分別為 Standard、 Small and Medium Business、 Enterprise、 Government。 (2) 不同市場的定價方式為: 市 場 售價率 Standard(一般) 25% Small and Medium Business(中小企業) 20% Enterprise(企業) 15% Government(政府) 10% (3) 請撰寫 PriceCalculator 類別,類別中包含一個 CustomerType 屬性( CustomerType列舉值)以及 CalculatePrice()方法。 (4) 假設成本皆為$150,000 元,傳入此成本,依不同市場輸出不同的價格。 (5) 價格必須格式化為貨幣格式(例如$150,000)。 4. 評分項目: 項 目 配分 (1)編寫 PriceCalculator 類別,計算不同市場的價格 8 (2)以貨幣格式輸出 2 總 分 10 ===本人試解程式碼==== using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSD03 { public enum CustomerType { Standard, SmallAndMediumBusiness, Enterprise, Government } class Program { static void Main(string[] args) { int amount = 150000; var price = new PriceCalculator(); price.CType = CustomerType.Standard; price.CalculatePrice(amount); price.CType = CustomerType.SmallAndMediumBusiness; price.CalculatePrice(amount); price.CType = CustomerType.Enterprise; price.CalculatePrice(amount); price.CType = CustomerType.Government; price.CalculatePrice(amount); Console.ReadLine(); } } // TODO: write PriceCalculator class to implement required function. public class PriceCalculator { public CustomerType CType { get; set; } public void CalculatePrice(int amount) { switch ( CType ) { case CustomerType.Standard: Console.WriteLine("Standard Price: {0}",((double)(amount*1.25)).ToString("C2")); break; case CustomerType.SmallAndMediumBusiness: Console.WriteLine("SMB Price: {0}",((double)(amount*1.20)).ToString("C2")); break; case CustomerType.Enterprise: Console.WriteLine("Enterprise Price: {0}" , ( (double)( amount * 1.15 ) ).ToString("C2")); break; case CustomerType.Government: Console.WriteLine("Government Price: {0}" , ( (double)( amount * 1.10 ) ).ToString("C2")); break; default: break; } } } } ====程式碼結束================ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.160.182.135 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1438401740.A.8F8.html ※ 編輯: gamegear (118.160.182.135), 08/01/2015 12:02:50

08/02 22:02, , 1F
如果你答案是對的,那你理解應該沒問題
08/02 22:02, 1F

08/02 22:02, , 2F
只是這樣的寫法符不符合考試要求就不清楚
08/02 22:02, 2F
文章代碼(AID): #1Ll4JCZu (C_Sharp)