}
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<