摘要:2016年下半年軟件設計師考試下午真題第三部分。
>>>【希賽】2016年下半年軟考分數早知道,希賽網解析真題
軟考歷年真題是考生備考的法寶,希賽軟考網整理了2016年下半年軟件設計師考試真題之下午題,供大家參考學習。以下為2016年下半年軟件設計師下午真題第三部分。
試題五(共15分)
閱讀下列說明和C++-代碼,將應填入(n)處的字句寫在答題紙的對應欄內。
【說明】
某發票(lnvoice)由抬頭(Head)部分、正文部分和腳注(Foot)部分構成。現采用裝飾(Decorator)模式實現打印發票的功能,得到如圖5-1所示的類圖。

【C++代碼】
#include<iostream>
using namespace std;
class invoice{
public:
(1){
cout<<"This is the content of the invoice!"<<endl;
}
};
class Decorator:public invoice{
Invoice*ticket;
public:
Decorator(lnvoice*t){ticket=t;}
void printinvoice(){
if(ticket!=NULL)
(2);
}
};
class HeadDecorator:public Decorator{
public:
HeadDecorator(lnvoice*t):Decorator(t){}
void printinvoice0{
cout<<"This is the header of the invoice!"<<endl;
(3);
}
};
class FootDecorator:public Decorator{
public:
FootDecorator(invoice*t):Decorator(t){}
void printlnvoice(){
(4);
cout<<"This is the footnote of the invoice!"<<endl;
}
};
int main(void){
Invoice t;
FootDecorator f(&t);
HeadDecorator h(&f);
H.printlnvoice();
cout<<“_____”<<endl;
FootDecorator a(NULL);
HeadDecorator b((5));
B.printinvoice();
return 0;
}
程序的輸出結果為:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
試題六(共15分)
閱讀下列說明和Java代碼,將應填入(n)處的字句寫在答題紙的對應欄內。
【說明】
某發票(lnvoice)由抬頭(Head)部分、正文部分和腳注(Foot)部分構成。現采用裝飾(Decorator)模式實現打印發票的功能,得到如圖6-1所示的類圖。

【java代碼】
class invoice{
public void printInvoice(){:
System.out.println("This is the content of the invoice!");
}
}
class Decorator:extends Invoice{
protected Invoice ticket;
public Decorator(lnvoice t){
ticket=t;
}
public void printinvoice(){
if(ticket!=NULL)
(1);
}
}
class FootDecorator extends Decorator{
public FootDecorator(lnvoice t){
super(t);
}
public void printinvoice(){
Systent.out.println("This is the header of the invoice!");
(2);
}
}
class FootDecorator extends Decorator{
public FootDecorator(invoice t):{
super(t);
}
public void printlnvoice(){
(3);
Systent.out.println("This is the header of the invoice!");
}
}
Class test{
public static void main(string[]args){
Invoice t=new invioce();
Invoice ticket;
Ticket=(4);
Ticket.Printinvoice();
Systent.out.println(“--------------“)
Ticket=(5);
Ticket.Printinvoice();
}
}
程序的輸出結果為:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
>>>返回目錄:2016年下半年軟件設計師考試真題(下午題)
相關推薦:
軟考不知道考啥科目?掃碼測最適合你的報考科目

通關資源:軟考各科歷年真題 | 各科學習資料匯總 | 在線試題庫【點擊刷題】
免費課程:系統架構設計師報考指南 | 2026年高項備考指導課及精講試聽
熱門活動: 新年新起點,大額滿減有驚喜![]()
軟考備考資料免費領取
去領取
專注在線職業教育25年