全国计算机等级考试二级C笔试试题.docx

上传人:b****6 文档编号:12065070 上传时间:2023-06-04 格式:DOCX 页数:28 大小:25.97KB
下载 相关 举报
全国计算机等级考试二级C笔试试题.docx_第1页
第1页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第2页
第2页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第3页
第3页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第4页
第4页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第5页
第5页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第6页
第6页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第7页
第7页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第8页
第8页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第9页
第9页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第10页
第10页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第11页
第11页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第12页
第12页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第13页
第13页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第14页
第14页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第15页
第15页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第16页
第16页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第17页
第17页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第18页
第18页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第19页
第19页 / 共28页
全国计算机等级考试二级C笔试试题.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

全国计算机等级考试二级C笔试试题.docx

《全国计算机等级考试二级C笔试试题.docx》由会员分享,可在线阅读,更多相关《全国计算机等级考试二级C笔试试题.docx(28页珍藏版)》请在冰点文库上搜索。

全国计算机等级考试二级C笔试试题.docx

全国计算机等级考试二级C笔试试题

2009年3月二级C++真题及参考答案

一、选择题(每小题2分,共70分)

 (11)对C++编译器区分重载函数无任何意义的信息是

   A)参数类型

   B)参数个数

   C)返回值类型

   D)常成员函数关键字coast   

 (12)有如下类定义和变量定义:

   classA{

   publie:

   A(){data=0;}

   ~A(){}

   intGetData()coast{returndata;}

   voidSetData(intn) {data=n;}

   private:

   intdata;

   };

   ccnstAa;

   Ab;

   下列函数调用中错误的是

   A)a.GetData();

   B)a.SetData(10);

   C)b.GetData();

   D)b.SetData(10);   

 (13)有如下类定义和变量定义:

   classParents{

   public:

   intpublicuata;

   private:

   intprivateData;

   };

   classChildA:

publicParents{/*类体略*/};

   classChildB:

privateParents{/*类体略*/);

   ChildAa;

   ChildBb;

   下列语句中正确的是

   A)cout<

   B)cout<

   C)cout<

   D)cout<

 (14)运算符重载时不需要保持的性质是

   A)操作数个数

   B)操作数类型

   C)优先级

   D)结合性   

 (15)下列关于函数模板的描述中,错误的是

   A)从模板实参表和从模板函数实参表获得信息矛盾时,以模板实参的信息为准

   B)对于常规参数所对应的模板实参,任何情况下都不能省略

   C)虚拟类型参数没有出现在模板函数的形参表中时,不能省略模板实参

   D)模板参数表不能为空   

 (16)要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是

   A)ifstreamfin=ifstream.open(“file.dat”);

   B)ifstream*fir.=newifstream(“file.dat”);

   C)ifstreamfin;fin.open(“file.dat”);

   D)ifstream*fin=newifstream();fin一>open(“file.dat”);   

 (17)下列描述中,不属于面向对象思想主要特征的是

   A)封装性

   B)跨平台性

   C)继承性

   D)多态性   

 (18)有如下程序段:

   Tnti=4;intj=l;

   intmain(){

   inti=8,j=i;

   cout<

   }

   运行时的输出结果是

   A)44            

   B)41           

   C)88          

   D)81   

 (19)有如下程序段:

   inti=5;

   while(inti=0){cout《'*';i--;}

   运行时输出“*”的个数是

   A)0             

   B)1            

   C)5           

   D)无穷   

 (20)己知有数组定义

   chara[3][4];

   下列表达式中错误的是

   A)a[2]=“WIN”

   B)strcpy(a[2],“WIN”)

   C)a[2][3]='W'

   D)a[0][1]=a[0][1]   

 (21)已知函数fun的原型为

   intfun(int,int,int);

   下列重载函数原型中错误的是

   A)charfun(int,int);

   B)double fun(int,int,double);

   C)intfun(int,char*);

   D)float fun(int,int,int);   

 (22)建立一个类对象时,系统自动调用

   A)析构函数

   B)构造函数

   C)静态函数

   D)友元函数   

 (23)通过派生类的对象可直接访问其

   A)公有继承基类的公有成员

   B)公有继承基类的私有成员

   C)私有继承基类的公有成员

   D)私有继承基类的私有成员   

 (24)己知表达式++a中的“++”是作为成员函数重载的运算符,则与十+a等效的运算符函数调用形式为

   A)a.orerator++

(1)

   B)operator++(a)

   C)operator++(a,l)

   D)a.operator++()   

 (25)在定义一个类模板时,模板形参表是用一对括号括起来的,所采用的括号是

   A)()

   B)[]

   C)<>

   D){}   

 (26)当使用ifstream流类定义一个流对象并打开一个磁盘文件时,文件的默认打开方式为

   A)ios_base:

:

in

   B)ios_base:

:

in|ios_base:

:

out

   C)ios_base:

:

out

   D)ios_base:

:

in&ios_base:

:

out   

 (27)有如下程序:

   #include

   #include

   usingnamespacestd;

   classXCD{

   char*a;

   intb;

   public:

   XCD(char*aa,intbb){

   a=newchar[strlen(aa)+1];

   strcpty(a,aa);

   b=bb;

   }

   Char* Geta(){returna;)

   int Getb(){returnb;}

   };

   intmain(){

   char*pl=“abcd”,*p2=“weirong”;

   intdl=6,d2=8;

   XCDx(pl,dl),Y(p2,d2);

   cout<

   return0;

   }

   运行时的输出结果是

   A)12

   B)16

   C)14

   D)11   

 (28)有如下程序:

   #include

   #include

   usingnamespacestd;

   classXCF{

   inta;

   public:

   XCF(intaa=0):

a(aa){cout<<“1”;}

   XCF(XCF&x){a=x.a; cout<<“2”;)

   ~XCF(){cout<

   int Geta(){returna;}

   };

   intmain(){

   XCFdl(5),d7(dl);

   XCF*pd=newXCF(8);

   cout<Geta();

   deletepd;

   return0;

   }

   运行时的输出结果是

   A)121SS88

   B)12188SS

   C)12185

   D)128512   

 (29)已知类MyClass声明如下:

   classMyClass{

   intn;

   public;

   MyClass(intk):

n(k){}

   intgetValue()const{returnn;}

   };

   在下列数组定义中正确的是

   A)MyClassx1[2];

   B)MyClassx2[2]={newMyClass

(1),newMyClass

(2)};

   C)MyClass*x3[2];

   D)MyClass*x4[2]={MyClass

(1),MyClass

(2)};   

 (30)有如下程序:

   #include

   usingnamespacestd;

   class AA{

   lilt  k;

   protected:

   int   n;

   voidsetK(intk){this->k=k;}

   public:

   voidsetN(intn){this->n=n;}

   };

   classBB:

public}{/*类体略*/};

   intmain(){

   BBx_;             //1

   x.n=1;             //2

   x.setN

(2);          //3

   x.k=3;             //4

   x.setK(4);

   return0;

   }

   在标注号码的四条语句中正确的是

   A)1

   B)2

   C)3

   D)4   

 (31)有如下类定义:

   classXX{

   int xx;

   public:

   XX():

xx(0){cout<<'A';}

   XX(int n):

xx(n){tout<<'B';}

   };

   ClassYY:

publicXX{

   Intyy;

   public:

   YY():

yy(0){cout+yy;}

   YY(intn):

XX(n+1),yy(n){cout<

   YY(int m,  int n):

XX(m),yy(n){cout<

   };

   下列选项中,输出结果为A0的语句是

   A)YYy1(0,0);

   B)YYy2

(1);

   C)YY y3(0);

   D)YY y4;   

 (32)有如下程序:

   #include

   Usingnamespacestd;

   classA{

   public:

   virtualvoidf(){cout+1;}

   voidg(){cout<<2;}

   };

   classB:

publicA{

   public:

   virtualvoidf(){cout<<3;}

   voidg(){ecut<<4;}

   };

   voidshow(A&a){a.f();a.g();}

   intmain(){

   Bb;

   show(b);

   return0;

   }

   运行时的输出结果是

   A)12

   B)34

   C)14

   D)32   

 (33)有如下程序:

   #include

   usingnamespacestd;

   classPair{

   intm;

   intn;

   public:

   Pair(inti,intj):

m(i),n(j){}

   bootoperator>(pairp)const;  //须在类体外给出定义

   };

   intmain(){

   PairAl(3,4),p2(4,3);p3(4,5);

   Cout<<(pl>p2)<<(P2>P1)<<(p2>p3)<<(p3>p2);

   return0;

   }

   运算符函数。

operator>的功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。

比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n,n大者为大。

程序输出0101,下列对运算符重载函数的正确定义是

   A)boolPair:

:

operator>(Pairp)const

   {if(m!

=p.m)returnm>p.m;returnn>p.n;}

   B)boolPair:

;operator>(Pairp)

   {if(m!

=p.m)returnm>p.m;returnn>p.n;}

   C)boolPair:

:

operator>(Pairp)const

   {if(m>p.m)returntrue;returnn>p.n;}

   D)boolPair:

;operator>(Pairp)

   {if(m>p.m)returntrue;returnn>p.n;}   

 (34)假定下列语句都是程序运行后首次执行的输出语句,其中输出结果与另外三条语句不同的语句是

   A)cout<

   B)cout<

   C)cout<<123<

   D)cout<

 (35)有如下程序:

   #include

   usingnamespacestd;

   classONE{

   intc;

   public:

   ONE():

c(0){cout<<1;}

   ONE(intn):

c(n){cout<<2;}

   };

   classTWO{

   ONEonel;

   ONEone2;

   public:

   TWO(intm):

one2(m){cout<<3;}

   };

   intmain()t

   TWOt(4)

   return0

   }

   运行时的输出结果是

   A)3

   B)23

   C)123

   D)213   

 二、填空题(每空2分,共30分)    

 (6)有如下程序段:

   intx=1,Y=2,z=3;

   x=x^z;

   y=y^z;

   z=x^y;

   cout<

   执行这个程序段的输出是【6】。

   

 (7)有如下程序段:

   fer(inti=1;i<=50;i++){

   if(i%3!

=0)

   continue;

   else

   if(i%5!

=0)

   continue;

   tout<

   }

   执行这个程序段的输出是【7】。

   

 (8)有如下程序段:

   Char c[20]=“examination”;

   c[4]=0;

   cout<

   执行这个程序段的输出是【8】。

   

 (9)下面的函数利用递归实现了求1+2+3+……+n的功能:

   intsum(intn){

   if(n==0)

   return0;

   else

   returnn+sum(n-1);

   }

   在执行sum(10)的过程中,递归调用sum函数的次数是【9】。

   

 (10)非成员函数应该声明为类【10】函数才能访问该类的私有成员。

 (11)有如下程序:

   #include

   usingnamespacestd;

   classMonitor{

   public:

   Monitor(chart):

type(t){}

   voidprint()const

   {cout<<“Thetypeofmonitoris”<

   private:

   chartype;

   };

   classComputer{

   public:

   Computer(inti,charc):

【11】{}

   voidPrint()const

   {cout<<“Thecomputeris”<

   private:

   intid;

   Monitormon;

   };

   constComputermyComputer(101,'B‘);

   myComputer.Print();

   return0;

   }

   请将程序补充完整,使程序在运行时输出:

   Thecomputeris101

   'Thetypeofmonitori.s8   

 (12)有如下程序:

   #include

   usingnamespacestd

   classAnimal{

   public:

   virtualchar*getType()const{return“Animal”;}

   virtualchar*getVoice()const{return“Voice”;}

   };

   ClassDog:

publicAnimal{

   public:

   char*getType()const{return“Dog”;}

   char*getVoice()const{return“Woof”}

   };

   voidtype(Animal&a){cout<

   voidspeak(Animala){cout<

   intmain(){

   Dogd;type(d);cout<<“speak”;speak(d);cout<

   return0;

   }

   运行时的输出结果是【12】。

   

 (13)补充完整下面的类定义:

   constdoublePI=3.14;

   classCircle{  //圆形物体的抽象基类

   protected:

   doubler;     //半径

   public:

   Circle(doubleradius=0):

r(radius){}

   【13】;//计算圆形物体表面积的纯虚函数声明

   };

   classCylinder:

publicCircle{ //圆柱体类

   doubleh;      //高度

   public:

   Cylindr(doubleradius=0,doubliheight=0):

   Circle(radius),h(height){}

   VirtualdoubleArea(){//计算圆柱体的表面积

   return2*PI*r*(r+h);

   }

   };   

 (14)补充完整下面的类定义:

   classXCH{

   char*a;

   public:

   XCH(char*as){//构造函数

   a=newchar[strlen(aa)+1];

   strcpy(a,aa);

   }

   XCH&operator=(constXCH&x)    //重载赋值函数

   Delele[]a;

   A=newchar[strlen(x.a)+l];

   strcpy(a,x.a)

   【14】;

   }

   ~XCH(){delete[]a;}

   };   

 (15)补充完整下面的模板定义:

   template //Type为类型参数

   classXtwo{   //由两个Type类型的数据成员构成的模板类

   Typea;

   Typeb;

   public:

   Xtwe(Typeaa=0,Typebb=0):

a(aa),b(bb){}

   intCcmpare (){//比较a和b的大小

   if(a>b)returm1;

   elseif(a==b)return0;

   elsereturn-1;

   }

   TypeSnm(){returna+b;}//返回a和b之和

   TypeMult();        //函数声明,返回a和b之乘积

   };

   Template

   【15】:

Mult(){returna*b;}//Mult函数的类外定义   

 

    参考答案

  一、 选择题:

(11)D   (12)B   (13)A   (14)B   (15)B  (16)A   (17)B   (18)C   (19) A    (20)D  (21)D   (22)B   (23)A   (24)B    (25)C  (26)B   (27)A   (28)B   (29)C   (30)B  (31)D   

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

当前位置:首页 > IT计算机 > 电脑基础知识

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

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