题号123456789101112131415
答案DBABBAACAAADCAC
C++ 六级
2024 年 06 月
1单选题(每题 2 分,共 30 分)
第 1 题 面向对象的编程思想主要包括( )原则。
A. 贪心、动态规划、回溯
B. 并发、并行、异步
C. 递归、循环、分治
D. 封装、继承、多态
第 2 题 运行下列代码,屏幕上输出( )。
A. 1 1 1
#include <iostream>
using namespace std;
class my_class {
public:
static int count;
my_class() {
count++;
}
~my_class() {
count--;
}
static void print_count() {
cout << count << " ";
}
};
int my_class::count = 0;
int main() {
my_class obj1;
my_class::print_count();
my_class obj2;
obj2.print_count();
my_class obj3;
obj3.print_count();
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
B. 1 2 3
C. 1 1 2
D. 1 2 2
第 3 题 运行下列代码,屏幕上输出( )。
#include <iostream>
using namespace std;
class shape {
protected:
int width, height;
public:
shape(int a = 0, int b = 0) {
width = a;
height = b;
}
virtual int area() {
cout << "parent class area: " <<endl;
return 0;
}
};
class rectangle: public shape {
public:
rectangle(int a = 0, int b = 0) : shape(a, b) { }
int area () {
cout << "rectangle area: ";
return (width * height);
}
};
class triangle: public shape {
public:
triangle(int a = 0, int b = 0) : shape(a, b) { }
int area () {
cout << "triangle area: ";
return (width * height / 2);
}
};
int main() {
shape *pshape;
rectangle rec(10, 7);
triangle tri(10, 5);
pshape = &rec;
pshape->area();
pshape = &tri;
pshape->area();
return 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
A. rectangle area: triangle area:
B. parent class area: parent class area:
C. 运行时报错
D. 编译时报错
第 4 题 向一个栈顶为hs的链式栈中插入一个指针为s的结点时,应执行( )。
A. hs->next
GESP 6月认证 C++ 六级真题,2024年6月GESP认证C++编程六级真题试卷及答案,gesp真题,c++真题,少儿编程题库