理论卷2024年6月GESP等级认证(C++) · 六级
GESP C++ 6级 2024.06
满分 100 · 及格 60 · 时长 60 分钟 · 共 27 题 (单选15 / 判断10 / 编程题2)
本卷含 2 道编程题——可以先到「编程」专栏单独练习: 不计时、不关联卷面分,提交后按测例判分。
试卷阅览 · 免费预览前 10 题 · 交卷后可查看答案与解析
1
单选题号 #12321
分值 2面向对象的编程思想主要包括( )原则。
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;
}
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;
}
4
单选题号 #12324
分值 2向一个栈顶为 的链式栈中插入一个指针为 的结点时,应执行( )。
5
单选题号 #12325
分值 2在栈数据结构中,元素的添加和删除是按照什么原则进行的?
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;
}
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;
}
};
8
单选题号 #12328
分值 2对 “classmycls” 使用哈夫曼编码,最少需要( )比特。
9
单选题号 #12329
分值 2二叉树的( )第一个访问的节点是根节点。
10
单选题号 #12330
分值 2一棵 层的满二叉树中节点数为( )。
🔒
已解锁前 10 题
第 11~27 题(共 17 题)注册用户即可作答(每题 1 积分)
本卷为普通试卷:注册用户每题扣 1 积分(每日登录送 30 体验积分),交卷后查看答案与解析
