C++基础练习试题及答案英文版十二.docx

上传人:b****2 文档编号:2314656 上传时间:2023-05-03 格式:DOCX 页数:8 大小:15.71KB
下载 相关 举报
C++基础练习试题及答案英文版十二.docx_第1页
第1页 / 共8页
C++基础练习试题及答案英文版十二.docx_第2页
第2页 / 共8页
C++基础练习试题及答案英文版十二.docx_第3页
第3页 / 共8页
C++基础练习试题及答案英文版十二.docx_第4页
第4页 / 共8页
C++基础练习试题及答案英文版十二.docx_第5页
第5页 / 共8页
C++基础练习试题及答案英文版十二.docx_第6页
第6页 / 共8页
C++基础练习试题及答案英文版十二.docx_第7页
第7页 / 共8页
C++基础练习试题及答案英文版十二.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C++基础练习试题及答案英文版十二.docx

《C++基础练习试题及答案英文版十二.docx》由会员分享,可在线阅读,更多相关《C++基础练习试题及答案英文版十二.docx(8页珍藏版)》请在冰点文库上搜索。

C++基础练习试题及答案英文版十二.docx

C++基础练习试题及答案英文版十二

Section12.2TemplatesBasics

12.1 Whichofthefollowingstatementsiscorrect?

A.Templatesprovidethecapabilitytoparameterizetypesinfunctionsandclasses.

B.Withtemplates,youcandefineonefunctionoroneclasswithagenerictypethatcanbesubstitutedforaconcretetypebythecompiler.

C.Templatesfacilitatesdevelopingreusablesoftware.

D.Templatesimprovesperformance.

 

12.2 Thetemplateprefixmaybedefinedas_________.

A.template

B.template

 

12.3 Atemplateprefixfortwoparametersmaybedefinedas_____________.

A.template

B.template

C.template

D.template

 

12.4 Supposeatemplatefunctionisdefinedasfollows:

template

T maxValue(const T& value1, const T& value2)

{

  if(value1>value2)

    returnvalue1;

  else

    returnvalue2;

}

Which of the following statements are correct?

 

A.cout<

B.cout<

C.cout<

D.cout<

E.cout<

 

12.5 Supposeatemplatefunctionisdefinedasfollows:

template

T1 maxValue(const T1& value1, const T2& value2)

{

  if(value1>value2)

    returnvalue1;

  else

    returnvalue2;

}

Which of the following statements are correct?

 

A.cout<

B.cout<

C.cout<

D.cout<

E.cout<

 

12.6 Ifyoudefinetheswapfunctionasfollows:

template

void swap(T& var1, T& var2)

{

  Ttemp=var1;

  var1=var2;

  var2=temp;

}

You can invoke swap using ______.

 

A.swap(1,2)

B.intv1=1;intv2=2;swap(v1,v2);

C.intv1=1;intv2=2;swap(&v1,&v2);

D.intv1=1;doublev2=2;swap(v1,v2);

 

Section12.3Example:

AGenericSort

12.7 Supposeatemplatefunctionisdefinedasfollows:

template

void printArray(T list[], int arraySize)

{

  for(inti=0;i

  {

    cout<

  }

  cout<

}

Which of the following statements are correct?

 

A.intlist[]={1,2,3,4};printArray(list,4);

B.intlist[]={1,2.5,3,4};printArray(list,4);

C.doublelist[]={1,2,3,4};printArray(list,4);

D.stringlist[]={"Atlanta","Dallas","Houston","Chicago"};printArray(list,4);

 

Section12.4ClassTemplates

12.8 Supposeyoudefine

template

class Stack

{

  Stack();

  ...

};

Which of the following statements are correct?

 

A.Stacks;

B.Stacks;

C.Stack<>s;

D.Stacks;

E.Stacks;

 

12.9 Supposeyoudefine

template

class Stack

{

  Stack();

  ...

private:

  Telements[capacity];

  intsize;

};

Which of the following statements are correct?

 

A.Stacks;

B.Stacks;

C.Stack<50>s;

D.Stacks;

 

12.10 Whichofthefollowingstatementsaretrue?

A.Aclasstemplatecanbederivedfromaclasstemplate.

B.Aclasstemplatecanbederivedfromanontemplateclass.

C.Anontemplateclasscanbederivedfromaclasstemplatespecialization.d.Stacks;

D.Friendsareusedexactlythesamefortemplateandnontemplateclasses.

E.Youcandefinestaticmembersinatemplateclass.Eachtemplatespecializationhasitsowncopyofastaticdatafield.

 

12.11 IntheimplementationofImprovedStack.h,whichofthefollowingaretrue?

A.sizeneverreduces.

B.capacityneverreduces.

C.InsideStack,aregulararrayisusedtostoreelements.

D.Ifthecurrentcapacityequalstosize,capacityisdoubledwhenanewelementisaddedtoStack.

 

Section12.6TheC++vectorClass

12.12 Whichofthefollowingstatementsaretrue?

A.Thearraysizeisfixedintheclassdeclaration.

B.C++providesthevectorclassandyoucancreatevectorobjects.

C.Avectorobjectisjustlikeanarray,butavector?

ssizecangrowautomaticallyifneeded.

D.Avectorhasano-argconstructor.

 

12.13 Todeclareavectorforholdingintvalues,use__________.

A.vectorv;

B.vectorv;

C.vectorv;

D.vectorv();

 

12.14 Toaddanintvalue5toavectorvofintegers,use_________.

A.v.add(5);

B.v.insert(5);

C.v.push_back(5);

D.v.append(5);

 

12.15 Toobtainthesizeofthevectorv,use_______.

A.v.getSize();

B.v.length();

C.v.getLength();

D.v.size();

 

12.16 Todeletealltheelementsinavectorv,use_______.

A.v.deleteAll();

B.v.clear();

C.v.eraseAll();

D.v.delele();

 

12.17 Toobtainthefirstelementinavectorv,use_______.

A.v.at(0);

B.v[0];

C.v.at

(1);

D.v[1];

 

12.18 Whatiswronginthefollowingcode?

  #include

  #include

  usingnamespacestd;

  intmain()

  {

    vectorv;

    cout<

    return0;

  }

A.Theprogramhasacompileerroronv[0].

B.Theprogramhasaruntimeerroronv[0],becausethevectorisempty.

C.Theprogramhasacompileerroronvectorv.

D.Theprogramhasaruntimeerroronvectorv.

 

12.19 Whatiswronginthefollowingcode?

  vectorv;

  v.push_back("Beijing");

  v.push_back("Tokyo");

  v.push_back("Shanghai");

  v[3]="HongKong";

A.Thelastlineinthecodecausesaruntimeerrorbecausethereisnoelementatindex3inthevector.

B.Thelastlineinthecodehasacompileerrorbecausethereisnoelementatindex3inthevector.

C.Ifyoureplacethelastlinebyv[2]="HongKong",thecodewillcompileandrunfine.

D.Ifyoureplacethelastlinebycout<

E.Ifyoureplacethelastlinebycout<

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2