软考试题分析
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软考试题分析相关的知识,希望对你有一定的参考价值。
软件设计师下午最后一题分析:
namespace ConsoleApplication { #region 2016软考下半年下午最后一题 class Invoice { public virtual void printInvoice() { System.Console.WriteLine("This is invoice content"); } } abstract class Print : Invoice { public Invoice inv; public Print(Invoice t) { inv = t; } public override void printInvoice() { if (inv != null) { //..... inv.printInvoice(); } } } class HeadPrint : Print { public HeadPrint(Invoice t) : base(t) { } public override void printInvoice() { System.Console.WriteLine("This is invoice head"); //... inv.printInvoice(); } } class FootPrint : Print { public FootPrint(Invoice t) : base(t) { } public override void printInvoice() { //... inv.printInvoice(); System.Console.WriteLine("This is invoice foot"); } } #endregion #region 2012软考上半年下午最后一题 abstract class Beverage //饮料 { public string description = "Unknown Beverage"; public virtual string getDescription() { return description; } public abstract int cost(); } abstract class CondimentDecorator : Beverage //配料 { public Beverage beverage; } class Espresso : Beverage //蒸馏咖啡 { private int ESPRESSO_PRICE = 25; public Espresso() { description = "Espresso"; } public override int cost() { return ESPRESSO_PRICE; } } class DarkRoast : Beverage //深度烘培咖啡 { private int DARKROAST_PRICE = 20; public DarkRoast() { description = "DarkRoast"; } public override int cost() { return DARKROAST_PRICE; } } class Mocha : CondimentDecorator //深度烘培咖啡 { private int MOCHA_PRICE = 10; public Mocha(Beverage beverage) { this.beverage = beverage; } public override string getDescription() { return beverage.getDescription() + ", Mocha"; } public override int cost() { return MOCHA_PRICE + beverage.cost(); } } class Whip : CondimentDecorator //奶泡 { private int WHIP_PRICE = 8; public Whip(Beverage beverage) { this.beverage = beverage; } public override string getDescription() { return beverage.getDescription() + ", Whip"; } public override int cost() { return WHIP_PRICE + beverage.cost(); } } #endregion class Program { static void Main(string[] args) { //Beverage beverage = new DarkRoast(); //beverage = new Mocha(beverage); //beverage = new Whip(beverage); //System.Console.WriteLine(beverage.getDescription() + " ¥" + beverage.cost()); Invoice t = new Invoice(); Print second; second = new HeadPrint(t); second.printInvoice(); System.Console.WriteLine("---------"); second = new FootPrint(second); second.printInvoice(); System.Console.ReadKey(); } } }
以上是关于软考试题分析的主要内容,如果未能解决你的问题,请参考以下文章
系统架构设计师软考简介 ( 软考好处 | 职称晋升 | 工作居住证 | 积分落户 | 系统架构设计师与系统分析师备考及难度 | 软考报名考试注意事项 )
系统架构设计师软考简介 ( 软考好处 | 职称晋升 | 工作居住证 | 积分落户 | 系统架构设计师与系统分析师备考及难度 | 软考报名考试注意事项 )
片段(Java) | 机试题+算法思路+考点+代码解析 2023