2023年下半年軟件設(shè)計(jì)師實(shí)行機(jī)考,考試時(shí)間為11月4日、5日開(kāi)考(分批考試,不同批次考試時(shí)間不同),臨近考試,每天刷刷題保持題感是有必要的,同時(shí)遇到不會(huì)的也可以查漏補(bǔ)缺,信管網(wǎng)將在考前為大家提供一些試題,供大家刷題練習(xí)。
2023年下半年軟件設(shè)計(jì)師案例分析真題模擬試題演練(5)
				試題一:
【說(shuō)明】 
某發(fā)票(lnvoice)由抬頭(Head)部分、正文部分和腳注(Foot)部分構(gòu)成?,F(xiàn)采用裝飾( Decorator)模式實(shí)現(xiàn)打印發(fā)票的功能,得到如圖5-1所示的類(lèi)圖。
 
 
【C++代碼】 
#include
using namespace std; 
class Invoice{ public: 
(1)    { 
cout<<"This is the content of the invoice!"<
}; 
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 printInvoice() { 
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.printInvoice(); 
cout<<”------------------------”<
HeadDecorator b(     (5)    ); 
b.printInvoice(); 
return 0; 
} 
程序的輸出結(jié)果為: 
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!
查看答案
				試題二:閱讀下列說(shuō)明和C代碼,回答問(wèn)題1至問(wèn)題3,將解答寫(xiě)在答題紙的對(duì)應(yīng)欄內(nèi)。
【說(shuō)明】
n-皇后問(wèn)題是在n行n列的棋盤(pán)上放置n個(gè)皇后,使得皇后彼此之間不受攻擊,其規(guī)則是任意兩個(gè)皇后不在同一行、同一列和相同的對(duì)角線上。
擬采用以下思路解決n-皇后問(wèn)題:第i個(gè)皇后放在第i行。從第一個(gè)皇后開(kāi)始,對(duì)每個(gè)皇后,從其對(duì)應(yīng)行(第i個(gè)皇后對(duì)應(yīng)第i行)的第一列開(kāi)始嘗試放置,若可以放置,確定該位置,考慮下一個(gè)皇后;若與之前的皇后沖突,則考慮下一列;若超出最后一列,則重新確定上一個(gè)皇后的位置。重復(fù)該過(guò)程,直到找到所有的放置方案。
【C代碼】
下面是算法的C語(yǔ)言實(shí)現(xiàn)。
(1)常量和變量說(shuō)明
pos:一維數(shù)組,pos[i]表示第i個(gè)皇后放置在第i行的具體位置
count:統(tǒng)計(jì)放置方案數(shù)
i,j,k:變量
N:皇后數(shù)
(2)C程序
#include 
#include 
#define N4
/*判斷第k個(gè)皇后目前放置位置是否與前面的皇后沖突*/
in isplace(int pos[], int k) {
int i;
for(i=1; i
return 0;
}
}
return 1;
}
int main() {
int i,j,count=1;
int pos[N+1];
//初始化位置
for(i=1; i<=N; i++) {
pos[i]=0;
}
(2)    ;
while(j>=1) {
pos[j]= pos[j]+1;
/*嘗試擺放第i個(gè)皇后*/
while(pos[j]<=N&& (3)_) {
pos[j]= pos[j]+1;
}
/*得到一個(gè)擺放方案*/
if(pos[j]<=N&&j══ N) {
printf("方案%d: ",count++);
for(i=1; i<=N; i++){
printf("%d  ",pos[i]);
}
printf("\n");
}
/*考慮下一個(gè)皇后*/
if(pos[j]<=N&& (4) ) {
j=j+1;
} else{ //返回考慮上一個(gè)皇后
pos[j]=0;
(5)    ;
}
}
return 1;
}
【問(wèn)題1】(10分)
根據(jù)以上說(shuō)明和C代碼,填充C代碼中的空(1)~(5)。
【問(wèn)題2】(2分)
根據(jù)以上說(shuō)明和C代碼,算法采用了    (6)   設(shè)計(jì)策略。
【問(wèn)題3】(3分)
上述C代碼的輸出為:
(7)   。
查看答案
參考答案:
參考解析:www.tent-cn.com/st/3815415695.html
信管網(wǎng)考友試題答案分享:
					信管網(wǎng)cnitpm493877469991: 
(1)pos[k]==pos[i] (2)pos[1]=1 (3)isplace(pos,j)==1(4)isplace(pos,j)==0  (5)j=j-1
(6)回溯 (7)1
				
閱讀推薦:
2023年下半年軟件設(shè)計(jì)師準(zhǔn)考證打印時(shí)間
【考后估分/對(duì)答案收藏】2023年下半年軟件設(shè)計(jì)師真題及答案(綜合、案例)
 
										信管網(wǎng)訂閱號(hào)
 
										信管網(wǎng)視頻號(hào)
 
										信管網(wǎng)抖音號(hào)
                                         溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,信管網(wǎng)網(wǎng)站提供的以上信息僅供參考,如有異議,請(qǐng)以權(quán)威部門(mén)公布的內(nèi)容為準(zhǔn)!
                                        溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,信管網(wǎng)網(wǎng)站提供的以上信息僅供參考,如有異議,請(qǐng)以權(quán)威部門(mén)公布的內(nèi)容為準(zhǔn)!
                                    
信管網(wǎng)致力于為廣大信管從業(yè)人員、愛(ài)好者、大學(xué)生提供專業(yè)、高質(zhì)量的課程和服務(wù),解決其考試證書(shū)、技能提升和就業(yè)的需求。
信管網(wǎng)軟考課程由信管網(wǎng)依托10年專業(yè)軟考教研傾力打造,教材和資料參編作者和資深講師坐鎮(zhèn),通過(guò)深研歷年考試出題規(guī)律與考試大綱,深挖核心知識(shí)與高頻考點(diǎn),為學(xué)員考試保駕護(hù)航。面授、直播&錄播,多種班型靈活學(xué)習(xí),滿足不同學(xué)員考證需求,降低課程學(xué)習(xí)難度,使學(xué)習(xí)效果事半功倍。
| 發(fā)表評(píng)論 查看完整評(píng)論 | |