2011年软件设计师考试考前密卷(七)-下午试题

0
收藏   分享
  • 卷面总分:75分
  • 试卷类型:模拟考试
  • 测试费用:免费
  • 答案解析:是
  • 练习次数:12次
  • 作答时间:150分钟
试卷简介
2011年软件设计师考试考前密卷(七)-下午试题:1.2011年软件设计师考试全真模拟试卷-下午试题,考前复习的好帮手!2. 每道题都配有答案解析,强化复习效
试卷预览
1

●试题六

阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。

【程序6说明】

本程序实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数有:

createList():创建按指数降序链接的多项式链表,以表示多项式。

reverseList():将多项式链表的表元链接顺序颠倒。

multiplyList(List L1,List L2):计算多项式L1和多项式L2的乘积多项式。

【程序6】

#include

class List;

class ltem{

friend class List;

private:

double quot;

int exp;

Item*next;

public:

Item(double_quot,int_exp)

{ (1) ;}

};

class List{

private:

Item*list;

public:

List(){list=NULL;}

void reverseList();

void multiplyList(List L1,List L2);

void createList();

};

void List::createList()

{Item*p,*u,*pre;

int exp;

double quot;

list=NULL;

while (1) {

cout<<"输入多项式中的一项(系数、指数):"<

cin>>quot>>exp:

if(exp<0)break;//指数小于零,结束输入

if(quot==0)continue;

p=list;

while( (2) ){//查找插入点

pre=p;p=p->next;}

if(p!=NULL&&exp==p->exp){ p->quot+=quot;continue;}

u= (3) ;

if(p==list) list=u;

else pre->next=u;

u->next=p;}

}

void List::reverseList()

{Item*p,*u;

if(list==NULL)return;

p=list->next;list->next=NULL;

while(p!=NULL){

u=p->next;p->next=list;

list=p;p=u;}

}

void List::multiplyList(List L1,List L2)

{Item*pLl,*pL2,*u;

int k,maxExp;

double quot;

maxExp= (4) ;

L2.reverseList();list=NULL;

for(k=maxExp;k>=0;k--){

pL1=L1.list;

while(pL1!=NULL&&pL1->exp>k)pL1=pL1->next;

pL2=L2.list;

while(pL2!=NULL&& (5) pL2=pL2->next;

quot=0.0;

while(pL1!=NULL&&pL2!=NULL){

if(pL1->exp+pL2->exp==k){

 (6) ;

pL1=pL1->next;pL2=pL2->next;

}else if(pL1->exp+pL2->exp>k)pL1=pL1->next;

else pL2=pL2->next;

}

if(quot!=0.0){

u=new Item(quot,k);

u->next=list;list=u;}

}

reverseList();L2.reverseList():

}

void main()

{ListL1,L2,L;

cout<<"创建第一个多项式链表\n";L1.createList();

cout<<"创建第二个多项式链表\n";L2.createList();

L.multiplyList(L1,L2);

}

1

●试题五

阅读下列程序说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。

【程序5说明】

著名的四色定理指出任何平面区域图均可用四种颜色着色,使相邻区域着不同的颜色。本程序对给定的区域图找出所有可能的不超过四种颜色的着色方案。

程序中用1~4表示四种颜色。要着色的N个区域用0~N-1编号,区域相邻关系用adj[][]矩阵表示,矩阵的i行j列的元素为1,表示区域i与区域j相邻;矩阵的i行j列的元素为0,表示区域i与区域j不相邻。数组color[]用来存储着色结果,color[i]的值为区域i所着颜色。

【程序5】

#include

#define N 10

void output(int color[])/*输出一种着色方案*/

{int i;

for(i=0;i

printf("%4d",color[i]);

printf("\n");

}

int back(int*ip,int color[])/*回溯*/

{int c=4;

while(c==4){

if(*ip<=0)return 0;

--(*ip);

c= (1) ;

color[*ip]=-1;

}

return c;

}

/*检查区域i,对c种颜色的可用性*/

int color0k(int i,int c,int[][N],int color[]}

{int j;

for(j=0;j

if( (2) )

return 0;

return 1;

}

/*为区域i选一种可着的颜色*/

int select(int i,int c,int adj[][N],int color[])

{int k;

for(k=c;k<=4;k++)

if(colorOK( (3) ))

return k;

return 0;

}

int coloring(int adj[][N])/*寻找各种着色方案*/

{int color[N],i,c,cnt;

for(i=0;i

i=c=0;cnt=0;

while (1) {

if((c= (4) )==0){

c=back(&i,color);

if(c==0)return cnt;

}else{ (5) ;i++;

if(i==N){

output(color);

++cnt;

c=back(&i,color);

}else c=0;

}

}

}

void main()

{int adj[N][N]=

{{0,1,0,1,1,1,1,1,1,1},

{1,0,1,1,0,1,1,1,1,0},

{0,1,0,1,0,1,1,0,1,1},

{1,1,1,0,1,1,0,0,1,1},

{1,0,0,1,0,1,0,0,0,0},

{1,1,1,1,1,0,1,0,0,1},

{1,1,1,0,0,1,0,0,1,0},

{1,1,0,0,0,0,0,0,1,1},

{1,1,1,1,0,0,1,1,0,1},

{1,0,1,1,0,1,0,1,1,0}

};

printf("共有%d组解.\n",coloring(adj));

}

1

●试题四

阅读下列程序说明和C程序,将应填入(n)处的字句写在答卷纸的对应栏内。

【程序说明】

该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。

【程序】

#include

void strmerge(char*a,char*b,char*c)//将字符串a,b合并到字符串c中

   {

char t,*w;

w=c;

while( (1) )

 {

//找到字符串a,b当前字符中较小的字符

if(*a<*b)

{

t=*a;

 (2) ;

}

else if(*a>*b)

{

t=*b;

 (3) ;

}

else//字符串a,b当前字符相等

{

t=*a;

a++;

b++;

}

if( (4) )//开始,可直接赋值

*w=t;

else if(t!=*w)

//如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5) ;

 }

if(*a!=\′\0′)//如果字符串a还没有结束,则将a的剩余部分赋给c

while(*a!=′\0′)

if(*a!=*w)

{

*(++w)=*a;

a++;

}

else

 (6) ;

 if(*6!=′\0′)//如果字符串b还没有结束,则将b的剩余部分赋给c

while(*b!=′\0′)

if(*b!=*w)

{

*(++w)=*b;

b++;

}

else

b++;

 (7) ;

}

void strsort(char*s)//将字符串S中的字符排序

{

int i,j,n;

char t,*w;

W=S;

for(n=0;*w!=′\0′;n++)//得到字符串长度n

w++;

for(i=0;i

for(j=i+1;j

if( (8) )

{

t=s[i];s[i]=s[j]; (9) ;

}

}

void main()

{

char s1[100],s2[100],s3[100];printf("\nPlease,input the first string:");

scanf("%s",s1);

printf("\nPlease input the second string:");

scanf("%s",s2);

strsort(s1);//将字符串s1排序

strsort(s2);//将字符串s2排序

printf("%s\n",s1);

printf("%s\n",s2);

s3[0]=′\0′;//字符串s3的第一个字符先置′\0′结束标志

   (10) //将s1和s2合并,按照字母顺序排列,

 //且要删去相同字符,存入s3中

printf("%s",s3);

 }