面向对象考试题参考.docx

上传人:b****5 文档编号:8310434 上传时间:2023-01-30 格式:DOCX 页数:11 大小:46.44KB
下载 相关 举报
面向对象考试题参考.docx_第1页
第1页 / 共11页
面向对象考试题参考.docx_第2页
第2页 / 共11页
面向对象考试题参考.docx_第3页
第3页 / 共11页
面向对象考试题参考.docx_第4页
第4页 / 共11页
面向对象考试题参考.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

面向对象考试题参考.docx

《面向对象考试题参考.docx》由会员分享,可在线阅读,更多相关《面向对象考试题参考.docx(11页珍藏版)》请在冰豆网上搜索。

面向对象考试题参考.docx

面向对象考试题参考

面向对象考试题(参考)

一、单选

1。

程序设计中,首先在问题域中识别出若干个()

A。

函数 B。

类 C。

文件 D。

过程

2。

定义类模板用关键字()

A。

const B.new C.delete D.template

3。

运算结果类型相同的()

A. 9.0/2.0 9.0/2

B. 9/2.0 9/2

C. 9.0/2 9/2

D. 9/2 9.0/2.0

4。

已知f1 f2同一类两个成员函数,但f1不能调用f2,说明()

a.f1 f2都是静态函数

b.f1是静态,f2不是

c.f1不是,f2是静态

d.f1 f2都不是静态函数

5。

调用一成员函数时,使用动态联编的情况是()

A.通过对象调用一虚函数 B。

通过指针或引用调用一虚函数

C。

通过对象调用静态函数 D。

通过指针或引用调用一静态函数

6。

假定一个类构造函数为:

“A(int aa=1,int bb=0){a=aa;b=bb;}则执行"A x(4)"后,x.a和x.b值分别是:

()

A。

1,0 B。

1,4 C。

4,0 D。

4,1

7。

在派生类中能直接访问基类的()

A。

公有成员,私有成员 B。

保护成员,私有成员 

C。

不可访问成员,私有成员 D。

公有成员,保护成员

8。

不具访问权限属性的是:

A。

非类成员 B。

类成员 C。

数据成员 D。

函数成员

9。

类定义中private,protected,public 出现次数为()

A。

任意多次 B。

至多一次 C。

public 至少一次 D。

至少一次

10。

C++鼓励程序员将()

A。

数据操作分别封装 B。

不同类型数据封装 

C。

数据操作封装在一起 D。

不同作用操作封装在一起。

二、填空

1。

C++中,最好用()代替malloc。

2。

函数模板中template之后尖括号的类型参数冠以保留字()。

3。

在IOS类中定义的用于格式控制的枚举变量中十、八、十六进制是dec,oct,()。

4。

如果重载了运算符+,则相应运算函数名是()。

5。

由static修饰的数据成员为该类的所有对象()。

6。

为了实现多态性,派生类需要重新定义基类中的()。

7。

编译时多态性通过()函数实现。

8。

派生类中实现基类成员初始化,需由派生类的构造函数调用()来完成。

9。

C++中访问指令所指对象的成员使用运算符()。

10。

重载函数在参数类型或参数个数上不同但()相同。

 

voidmain()

{

inta[5]={1,2,3,4,5};

doubled[6]={1.1,2.2,3.3,4.4,5.5};

f(a,5);

f(d,6);

for(inti=0;i<5;i++)cout<

cout<

for(i=0;i<6;i++)cout<

cout<

}

2。

使类定义完整

classline;

classbox

{

private:

intcolor;

intupx,upy;

intlowx,lowy;

public:

friendintsame_color(linel,_______);

voidset_color(intc){color=c;}

voiddefine_box(intx1,inty1,intx2,inty2)

{upx=x1;upy=y1;lowx=x2;lowy=y2;}

};

classline

{

private:

intcolor;

intstartx,starty;

intendx,endy;

public:

_______intsame_color(linel,boxb);

voidset_color(intc){color=c;}

voiddefine_line(intx1,inty1,intx2,inty2)

{startx=x1;starty=y1;endx=x2;endy=y2;}

}

intsame_color(linel,boxb)

{

if(l.color==b.color)returnl;

return0;

}

 

3。

A为抽象类,输出为:

this is class B printing

this is class C printing

#include

classA

{

public:

______________________;

};

classB:

publicA

{

public:

voidprintMe(){cout<<"thisisclassBprinting"<

};

classC:

publicB

{

voidprintMe(){cout<<"thisisclassCprinting"<

};

voidprint(___________){a.printMe();}

voidmain()

{

Bb;

Cc;

print(b);

print(c);

}

4。

使类完整

classA

{

int*a;

intn;

public:

A():

a(0),n(0){}

A(intnn)

{

_________//用NN初始化N

__________//用A指向长度为N的动态数组空间

};

 

5。

使类完整

class base

{

protected:

 int a;

public:

 base(){a=0;}

 base(int i){a=i}

 base(base&b){a=b.a}

};

class derived:

public base

{

 private:

 int d;

 public:

 derived(){d=0;}

 derived(int i,int j):

__________{d=j;}

    derived(derived&b):

__________{d=b.d;} 

};

五、运行结果

1、

#include

classshownumtype

{

public:

voidshow(int);

voidshow(float);

};

voidshownumtype:

:

show(inti)

{cout<<"thisisanint"<

voidshownumtype:

:

show(floatf)

{cout<<"thisisfloat"<

voidmain()

{

inta=0;floatf=1.0;

shownumtypesnt;

snt.show(a);

snt.show(f);

}

 

2、

#include

classA

{

public:

virtualvoidpr(){cout<<"1"<

};

classB:

publicA

{

voidpr(){cout<<"2"<

};

voidp1(A&a){a.pr();}

voidp2(Aa){a.pr();}

voidmain()

{

Bb;

p1(b);

p2(b);

}

 

3、

#include

classA

{

public:

A(inti=0){a=i;}

voidprint(){cout<

private:

inta;

};

classB:

publicA

{

public:

B(){b1=b2=0;}

B(inti){b1=i;b2=0;}

B(inti,intj,intk):

A(i),b1(j),b2(k){}

voidprint(){A:

:

print();cout<

private:

intb1,b2;

};

 

voidmain()

{

Bd1,d2(5),d3(4,5,6);

d1.print();d2.print();d3.print();

}

4、

#include

classgoods

{

private:

staticinttotalweight;

intweight;

public:

goods(intw)

{

weight=w;

totalweight+=weight;

}

goods(goods&gd)

{

weight=gd.weight;

totalweight+=weight;

}

~goods()

{totalweight-=weight;}

staticintgettotal()

{returntotalweight;}

};

intgoods:

:

totalweight=0;

voidmain()

{

goodsg1(50);

cout<

:

gettotal()<

goodsg2(100);

cout<

}

 

5、

#include

template

voidf(T*a,intn)

{

intk;

Tt;

for(inti=0;i

{

k=i;

for(intj=i+1;j

if(a[k]>a[j])k=j;

t=a[i];a[i]=a[k];a[k]=t;

}

}

voidmain()

{

doubled[5]={12.3,4.5,-23.4,-90.4,0};

chara[5]={'B','F','A','x','E'};

f(a,5);

f(d,5);

for(inti=0;i<5;i++)

cout<

}

6、

#include

voidmain()

{

cout<

六、编程

 

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

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1