GESP CCF C++ 六级认证真题 2024年6月

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

A. 贪心、动态规划、回溯

B. 并发、并行、异步

C. 递归、循环、分治

D. 封装、继承、多态

第 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 题  运行下列代码,屏幕上输出( )。
#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 题  向一个栈顶为hs的链式栈中插入一个指针为s的结点时,应执行( )。

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 题 在栈数据结构中,元素的添加和删除是按照什么原则进行的?

A. 先进先出

B. 先进后出

C. 最小值先出

D. 随机顺序

第 6 题  要实现将一个输入的十进制正整数转化为二进制表示,下面横线上应填入的代码为( )。
#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 题  下面定义了一个循环队列的类,请补全判断队列是否满的函数,横向上应填写( )。
#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 题  对“classmycls”使用哈夫曼(Huffman)编码,最少需要( )比特。

A.10

B.20

C. 25

D. 30

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

A. 先序遍历

B. 中序遍历

C. 后序遍历

D. 以上都是

第 10 题  一棵5层的满二叉树中节点数为( )。

A.31

B.32

C. 33

D. 16

第 11 题  在求解最优化问题时,动态规划常常涉及到两个重要性质,即最优子结构和( )。

A.重叠子问题
B. 分治法

C. 贪心策略

D. 回溯算法

================================================

答案和更多内容请查看网站:【试卷中心 -- C/C++ 其它】

网站链接 

青少年软件编程历年真题模拟题实时更新

================================================

  • 14
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

No0d1es

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值