海小星AI平台海小星AI平台
理论卷2024年6月GESP等级认证(C++) · 六级

GESP C++ 6级 2024.06

满分 100 · 及格 60 · 时长 60 分钟 · 共 27 题 (单选15 / 判断10 / 编程题2)
本卷含 2 道编程题——可以先到「编程」专栏单独练习: 不计时、不关联卷面分,提交后按测例判分。
试卷阅览 · 免费预览前 10 题 · 交卷后可查看答案与解析
1
单选题号 #12321
分值 2

面向对象的编程思想主要包括( )原则。

A

贪心、动态规划、回溯

B

并发、并行、异步

C

递归、循环、分治

D

封装、继承、多态

2
单选题号 #12322
分值 2

运行下列代码,屏幕上输出( )。

#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;
}
A

1 1 1

B

1 2 3

C

1 1 2

D

1 2 2

3
单选题号 #12323
分值 2

运行下列代码,屏幕上输出( )。

#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;
}
A

rectangle area: triangle area:

B

parent class area: parent class area:

C

运行时报错

D

编译时报错

4
单选题号 #12324
分值 2

向一个栈顶为 hshs 的链式栈中插入一个指针为 ss 的结点时,应执行( )。

A

hs->next = s;

B

s->next = hs; hs = s;

C

s->next = hs->next; hs->next = s;

D

s->next = hs; hs = hs->next;

5
单选题号 #12325
分值 2

在栈数据结构中,元素的添加和删除是按照什么原则进行的?

A

先进先出

B

先进后出

C

最小值先出

D

随机顺序

6
单选题号 #12326
分值 2

要实现将一个输入的十进制正整数转化为二进制表示,下面横线上应填入的代码为( )。

#include <iostream>
using namespace std;

stack<int> ten2bin(int n) {
    stack<int> st;
    int r, m;
	
    r = n % 2;
    m = n / 2;
    st.push(r);
	
    while (m != 1) {
        r = m % 2;
        st.push(r);
	m = m / 2;
    }
    st.push(m);
    return st;
}

int main() {
    int n;
    cin >> n;
    stack<int> bin;
    bin = ten2bin(n);
    while (!bin.empty()) {
        ____________________ // 在此处填入代码
    }
    return 0;
}
A

cout << bin.top(); bin.pop();

B

bin.pop(); cout << bin.top();

C

cout << bin.back(); bin.pop();

D

cout << bin.front(); bin.pop();

7
单选题号 #12327
分值 2

下面定义了一个循环队列的类,请补全判断队列是否满的函数,横向上应填写( )。

#include <iostream>

using namespace std;

class circular_queue {
private:
    int *arr; // 数组用于存储队列元素
    int capacity; // 队列容量
    int front; // 队头指针
    int rear; // 队尾指针
	
public:
    circular_queue(int size) {
	capacity = size + 1; // 为了避免队列满时与队列空时指针相等的情况,多预留一个空间
	arr = new int[capacity];
	front = 0;
	rear = 0;
    }
	
    ~circular_queue() {
	delete[] arr;
    }
	
    bool is_empty() {
        return front == rear;
    }
	
    bool is_full() {
        ________________ // 在此处填入代码
    }
	
    void en_queue(int data) {
	if (is_full()) {
	    cout << "队列已满,无法入队!" << endl;
	    return -1;
	}
	arr[rear] = data;
	rear = (rear + 1) % capacity;
	return 1;
    }

    int de_queue() {
	if (is_empty()) {
	    cout << "队列为空,无法出队!" << endl;
	    return -1; // 出队失败,返回一个特殊值
	}
	int data = arr[front];
	front = (front + 1) % capacity;
	return data;
    }
};
A

return (rear + 1) % capacity == front;

B

return rear % capacity == front;

C

return rear == front;

D

return (rear + 1) == front;

8
单选题号 #12328
分值 2

对 “classmycls” 使用哈夫曼(Huffman)(Huffman)编码,最少需要( )比特。

A

1010

B

2020

C

2525

D

3030

9
单选题号 #12329
分值 2

二叉树的( )第一个访问的节点是根节点。

A

先序遍历

B

中序遍历

C

后序遍历

D

以上都是

10
单选题号 #12330
分值 2

一棵 55 层的满二叉树中节点数为( )。

A

3131

B

3232

C

3333

D

1616

🔒

已解锁前 10 题

第 11~27 题(共 17 题)注册用户即可作答(每题 1 积分)
本卷为普通试卷:注册用户每题扣 1 积分(每日登录送 30 体验积分),交卷后查看答案与解析