面向对象程序设计(C++)智慧树知到课后章节答案2023年下北方工业大学_第1页
面向对象程序设计(C++)智慧树知到课后章节答案2023年下北方工业大学_第2页
面向对象程序设计(C++)智慧树知到课后章节答案2023年下北方工业大学_第3页
面向对象程序设计(C++)智慧树知到课后章节答案2023年下北方工业大学_第4页
面向对象程序设计(C++)智慧树知到课后章节答案2023年下北方工业大学_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

面向对象程序设计(C++)智慧树知到课后章节答案2023年下北方工业大学北方工业大学

第一章测试

下列哪个不是面向对象技术的特点()

答案:

逻辑

C++中关于class和struct的说法正确的是()

答案:

struct的成员默认是公有的,而类的成员默认是私有的

有以下类的定义:

classEx{

intx;

public:

voidsetx(intt=0);

};

若在类外定义成员函数setx(),以下定义形式中正确的是()

答案:

voidEx::setx(intt){...}

#include<stdio>

classTest{

intx;

};

intmain()

{

Testt;

printf(“%d”,t.x);

return0;

}

以上代码运行结果是()

答案:

编译错误

类就是c语言中的结构类型。()

答案:

Amemberfunctioncanalwaysaccessthedatain()

答案:

theclassofwhichitismember

Whatdoesyourclasscanhold?()

答案:

Botha&b

Whatpurposedoclassesserve?()

答案:

alloftheabove

Whichofthefollowingisavalidclassdeclaration?()

答案:

classA{intx;};

OOPstandsfor()

答案:

ObjectOrientedProgramming

第二章测试

有关函数重载的正确说法是()

答案:

函数名相同,但参数的个数不同或参数的类型不同

使用运算符.可以访问名字空间里的函数。()

答案:

作用域运算符“::”的功能是()

答案:

指出作用域的范围的

适宜采用inline定义函数情况是()

答案:

函数代码少、频繁调用

类A有如下成员函数:

intA::fun(doublex){return(int)x/2;}

intA::fun(intx){returnx*2;}

设a为类A的对象,在主函数中执行语句ints=a.fun(6)+a.fun(2.0)后的s值()

答案:

13

Whichofthefollowingisavalidinlineforfunctionfoo?()

答案:

inlinevoidfoo(){}

#include<iostream>

usingnamespacestd;

intfun(intx=0,inty=0,intz)

{

return(x+y+z);

}

intmain()

{

printf("%d",fun(10));

return0;

}

Output?()

答案:

CompilerError

#include<iostream>

usingnamespacestd;

intfun(int=0,int=0)

{

return(x+y);

}

intmain()

{

printf("%d",fun(5));

return0;

}

Output?()

答案:

5

WhichofthefollowinginObjectOrientedProgrammingissupportedbyFunctionoverloadinganddefaultargumentsfeaturesofC++.()

答案:

Polymorphism

#include<iostream>

usingnamespacestd;

namespaceT{

classA{

public:

voidshow(){

printf("Go");

}

};

}

intmain(){

T::Aobj;

obj.show();

return0;

}

Output?()

答案:

Go

第三章测试

引用就是变量的别名,声明引用时必须同时对它初始化。()

答案:

this指针是成员函数中的特殊指针,它指向调用成员函数的对象起始地址。()

答案:

voidfun(int*m,long&n);

inta;

longb;

则以下调用合法的是()

答案:

fun(&a,b);

若Sample类中的一个成员函数说明如下:voidset(Sample&a),则Sample&a的含义是()

答案:

a是类Sample的对象引用,用来作函数set()的形参

设有以下函数:voidfun(intn,char*s){......}则下面对函数指针的定义和赋值均正确的是?()

答案:

void(*pf)(int,char*);pf=&fun;

classcard{

public:

ints;

};

carda;

card*p;

wecanuse_________toaccessthemembervariables.()

答案:

p->s

Whenlocalvariable'snameissameasmember'sname,wecanaccessmemberusingthispointer.()

答案:

#include<stdio.h>

intadd(intfirst,intsecond)

{

returnfirst+second+15;

}

intoperation(intfirst,intsecond,int(*functocall)(int,int))

{

return(*functocall)(first,second);

}

intmain()

{

inta;

int(*plus)(int,int)=add;

a=operation(15,10,plus);

printf("%d",a);

return0;

}

Output?()

答案:

40

#include<stdio.h>

usingnamespacestd;

classFoo

{

public:

Foo(inti=0){_i=i;}

voidf()

{

printf("Executed\n");

}

private:

int_i;

};

intmain()

{

Foo*p;

p->f();

}

Output?()

答案:

Executed

#include<stdio.h>

intmain()

{

inta=9;

int&aref=a;

a++;

printf("%d",aref);

return0;

}

Output?()

答案:

10

第四章测试

以下不属于构造函数特征的是()

答案:

构造函数必须指定返回类型

在下面有关析构函数特征的描述中,正确的是()

答案:

析构函数不能指定返回类型

构造函数是在()时被执行的()

答案:

创建对象

假定C为一个类,则执行Cx;语句时将自动调用该类的()

答案:

无参构造函数

利用类Image定义一个指针变量p_img,并为p_img动态获取10个内存空间的语句为p_img=newImage[10];要释放p_img所指向的动态内存,应使用语句delete[]p_img;()

答案:

Ifdefaultconstructorisnotdefined,thenhowtheobjectsoftheclasswillbecreated?()

答案:

Compilerprovidesitsdefaultconstructortobuildtheobject

#include<stdio.h>

classData{

public:

intx;

Data(){

printf("Hello");

}

};

voidmain(){

Datad;

}

Output?()

答案:

Hello

#include<stdio.h>

classTest

{

public:

Test(){x=5;}

intx;

};

voidmain()

{

Test*t=newTest;

printf("%d",t->x);

}

Output?()

答案:

5

#include<stdio.h>

classsample{

public:

sample(){

printf("Hi");

}

~sample(){

printf("Bye");

}

};

intmain(){

sample*obj=newsample();

delete(obj);

return0;

}

Output?()

答案:

HiBye

第五章测试

派生类不能继承基类中访问属性为private的数据成员。()

答案:

一个派生类可以作为另一个派生类的基类。()

答案:

设置虚基类的目的是()

答案:

解决多继承造成的二义性问题

派生类的对象可以访问它的基类成员中的()

答案:

公有继承的公有成员

#include<stdio.h>

classBase{

public:

Base(){

printf("1");

}

~Base(){

printf("2");

}

};

classDerived:publicBase{

public:

Derived(){

printf("3");

}

~Derived(){

printf("4");

}

};

intmain(){

Derivedx;

}

Output?()

答案:

1342

第六章测试

虚继承主要作用是解决多重继承中二义性的问题。()

答案:

以下成员函数表示纯虚函数的是()

答案:

virtualvoidvf()=0;

若一个类中含有纯虚函数,则该类称为()

答案:

抽象类

在派生类中,编写一个虚函数时,要求函数名、参数的个数、参数的类型、参数的顺序和函数的返回值()

答案:

相同

基类指针可以指向派生类对象,派生类指针也可指向基类对象。()

答案:

Whenaclassisderivedfromaclasswithapurevirtualfunctionandnodefinitionissuppliedforthatpurevirtualfunctioninthederivedclass,thatderivedclassisalsoanabstractclass.()

答案:

Choosethecorrectstatement?()

答案:

AbstractclassisaclasswhichcontainsatleastonePureVirtualfunctioninit.

#include<stdio.h>

classBase{

public:

virtualvoidshow(){printf("InBase;");}

};

classDerived:publicBase{

public:

voidshow(){printf("InDerived;");}

};

voidmain(){

Base*bp=newDerived;

bp->show();

}

Output?()

答案:

InDerived;

第七章测试

若classB中定义了一个classA的类成员Aa,则在类B的成员函数中可以访问A类的保护数据成员。()

答案:

B类中有对象A作为成员,那么当创建B对象时,则先调用A的构造函数,后调用B的构造函数。()

答案:

若有以下类T说明,则函数fFriend的错误定义是()

classT{

inti;

friendvoidfFriend(T&,int);

};

答案:

voidT::fFriend(T&objT,intk){k+=objT.i;}

关于C++中的友元函数说法正确的是()

答案:

友元函数没有this指针

IfclassAisfriendofclassBandifclassBisfriendofclassC,whichofthefollowingistrue?()

答案:

Noneoftheabove

#include<stdio.h>

classBox{

intcapacity;

public:

Box(intcap){

capacity=cap;

}

friendvoidshow();

};

voidshow(){

Boxb(10);

printf("Valueofcapacityis%d",b.capacity);

}

voidmain(){

show();

}

Output?()

答案:

Valueofcapacityis:10

#include<stdio.h>

classBox{

intcapacity;

public:

Box(intcap){

capacity=cap;

}

friendvoidshow();

};

voidBox::show(){

Boxb(10);

printf("Valueofcapacityis%d",b.capacity);

}

voidmain(){

show();

}

Output?()

答案:

Error

Whydoweneedrelationshipsbetweenclasses?()

答案:

Allofthementioned

第八章测试

静态成员函数不必通过该类的对象调用,可以直接用类名以及作用域运算符::进行调用。()

答案:

关于类的静态成员的不正确描述是()

答案:

只有静态成员函数可以操作静态数据成员

若有以下说明,则对n的正确访问语句是()

classY{

public:

staticintn;

};

intY::n;

YobjY;

答案:

Y::n=1;

const表示常量,类的const数据成员初始化只能在成员初始化列表里。()

答案:

constint*p说明不能修改()

答案:

p指针指向的变量;

Thelifetimeofastaticmembervariableissameas___()

答案:

Lifetimeoftheprogram

#include<stdio.h>

classTest{

staticintx;

public:

Test(){x++;}

staticintgetX(){returnx;}

};

intTest::x=0;

voidmain(){

printf("%d",Test::getX());

Testt[5];

printf("%d",Test::getX());

}

Output?()

答案:

05

#include<stdio.h>

classPlayer{

private:

intid;

staticintnext_id;

public:

intgetID(){returnid;}

Player(){id=next_id++;}

};

intPlayer::next_id=1;

voidmain(){

Playerp1;

Playerp2;

Playerp3;

printf("%d",p1.getID());

printf("%d",p2.getID());

printf("%d",p3.getID());

}

Output?()

答案:

123

#include<stdio.h>

intmain(){

constintx;

x=10;

printf("%d",x);

return0;

}

Output?()

答案:

Error

#include<stdio.h>

classPoint{

intx,y;

public:

Point(inti=10,intj=10){

x=i;

y=j;

}

intgetX()const{

returnx;

}

intgetY(){

returny;

}

};

voidmain(){

constPointt;

printf("%d%d",t.getX(),t.getY());

}

Output?()

答案:

Compileerror

第九章测试

在运算符重载中,operator++(int);实现前置++的重载。()

答案:

双目运算符用成员函数重载时参数表中只需要一个参数。()

答案:

类的转换构造函数可以将其它类型转换为本类对象。()

答案:

假设OneClass为一个类,则该类的拷贝初始化构造函数的声明语句为()

答案:

OneClass(OneClass&p);

Whatisabinaryoperator?()

答案:

Operatorthatperformsitsactionontwooperand

Inthecaseoffriendoperatoroverloadedfunctionshowmanymaximumobjectargumentsaunaryoperatoroverloadedfunctioncantake?()

答案:

1

Howmanyparametersdoesaconversionoperatormaytake?()

答案:

0

Thecopyconstructorscanbeusedto________()

答案:

Copyanobjectsothatitcanbepassedtoafunction

第十章测试

C++语言中模板分为函数模板和类模板两种。()

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论