[问题] TQC+ 练习题,请协助解题意

楼主: gamegear (小伟伟)   2015-08-01 12:02:03
各位大大好:
本人预计报名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;
}
}
}
}
====程式码结束================
作者: GoalBased (Artificail Intelligence)   2015-08-02 22:02:00
如果你答案是对的,那你理解应该没问题只是这样的写法符不符合考试要求就不清楚

Links booklink

Contact Us: admin [ a t ] ucptt.com