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