第一章 单元测试

1、 问题:下列哪个不是面向对象技术的特点( )
选项:
A:封装
B:逻辑
C:多态
D:抽象
答案: 【
逻辑

2、 问题:C++中关于class和struct的说法正确的是( )
选项:
A:二者没有区别
B:二者默认成员都公有的
C:二者默认成员都私有的
D:struct的成员默认是公有的,而类的成员默认是私有的
答案: 【
struct的成员默认是公有的,而类的成员默认是私有的

3、 问题:有以下类的定义:
class Ex{
int x;
public:
void setx(int t=0);
};
若在类外定义成员函数setx(),以下定义形式中正确的是( )
选项:
A:void setx(int t) { … }
B:void Ex::setx(int t) { … }
C:Ex::void setx(int t) { … }
D:void Ex::setx(){ … }
答案: 【
void Ex::setx(int t) { … }

4、 问题:#include<stdio>
class Test {
int x;
};
int main()
{
Test t;
printf(“%d”, t.x);
return 0;
}
以上代码运行结果是( )
选项:
A:0
B:x
C:任意数值
D:编译错误
答案: 【
编译错误

5、 问题:类就是c语言中的结构类型。( )
选项:
A:对
B:错
答案: 【

6、 问题:A member function can always access the data in ( )
选项:
A:the class of which it is member
B:the object of which it is a member
C:the public part of its class
D:the private part of its class
答案: 【
the class of which it is member

7、 问题:What does your class can hold? ( )
选项:
A:Data
B:Functions
C:Both a & b
D:None of the mentioned
答案: 【
Both a & b

8、 问题:What purpose do classes serve? ( )
选项:
A:data encapsulation
B:providing a convenient way of modeling real-world objects
C:simplifying code reuse
D:all of the above
答案: 【
all of the above

9、 问题:Which of the following is a valid class declaration? ( )
选项:
A:class A { int x; };
B:class B { }
C:public class A { }
D:object A { int x; };
答案: 【
class A { int x; };

10、 问题:OOP stands for ( )
选项:
A:Object to Object Programming
B:Object Oriented Programming
C:Online Objects Programming
D:Object Oriented Processes
答案: 【
Object Oriented Programming

第二章 单元测试

1、 问题:有关函数重载的正确说法是 ( )
选项:
A:函数名不同,但参数的个数和类型相同
B:函数名相同,但参数的个数不同或参数的类型不同
C:函数名相同,参数的个数和类型相同
D:函数名相同,函数的返回值不同,而与函数的参数和类型无关
答案: 【
函数名相同,但参数的个数不同或参数的类型不同

2、 问题:使用运算符 . 可以访问名字空间里的函数。( )
选项:
A:对
B:错
答案: 【

3、 问题:作用域运算符“::”的功能是 ( )
选项:
A:标识作用域的级别的
B:指出作用域的范围的
C:给定作用域的大小的
D:标识成员是属于哪个类或哪个命名空间
答案: 【
指出作用域的范围的

4、 问题:适宜采用inline定义函数情况是 ( )
选项:
A:函数体含有循环语句
B:函数体含有递归语句
C:函数代码少、频繁调用
D:函数代码多、不常调用
答案: 【
函数代码少、频繁调用

5、 问题:类A有如下成员函数:
int A::fun(double x){return (int) x/2;}
int A::fun(int x){return x*2;}
设a为类A的对象,在主函数中执行语句int s = a.fun(6) + a.fun(2.0)后的s值 ( )
选项:
A:13
B:4
C:5
D:7
答案: 【
13

6、 问题:Which of the following is a valid inline for function foo? ( )
选项:
A:inline void foo() {}
B:void foo() inline {}
C:inline:void foo() {}
D:None of the above
答案: 【
inline void foo() {}

7、 问题:#include<iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z)
{
return (x + y + z);
}
int main()
{
printf(“%d”, fun(10));
return 0;
}
Output? ( )
选项:
A:10
B:0
C:20
D:Compiler Error
答案: 【
Compiler Error

8、 问题:#include <iostream>
using namespace std;
int fun(int=0, int = 0)
{
return (x+y);
}
int main()
{
printf(“%d”, fun(5));
return 0;
}
Output? ( )
选项:
A:Compiler Error
B:5
C:0
D:10
答案: 【
5

9、 问题:Which of the following in Object Oriented Programming is supported by Function overloading and default arguments features of C++. ( )
选项:
A:Inheritance
B:Polymorphism
C:Encapsulation
D:None of the above
答案: 【
Polymorphism

10、 问题:#include <iostream>
using namespace std;
namespace T{
class A {
public:
void show() {
printf(“Go”);
}
};
}
int main(){
T::A obj;
obj.show();
return 0;
}
Output? ( )
选项:
A:0
B:Go
C:No output
D:Compilation Error
答案: 【
Go

第三章 单元测试

1、 问题:引用就是变量的别名,声明引用时必须同时对它初始化。( )
选项:
A:对
B:错
答案: 【


本门课程剩余章节答案为付费内容
本文章不含期末不含主观题!!
本文章不含期末不含主观题!!
支付后可长期查看
有疑问请添加客服QQ 2356025045反馈
如遇卡顿看不了请换个浏览器即可打开
请看清楚了再购买哦,电子资源购买后不支持退款哦