#1163. GESP C++ 四 级 2024年12月真题 · 单选题

GESP C++ 四 级 2024年12月真题 · 单选题

GESP C++ 四 级 2024年12月真题(120 分钟,总分 100 分)

单选题(共 15 题,每题 2 分,共 30 分)

1. 下面的语句中,( )正确定义了一个计算浮点数 的平方(x2=x*x)的函数,并成功调用该函数。

{{ select(1) }}

  • float square(float x) {
        return x * x;
    }
    float area = square(2);
  • square(float x) {
        return x * x;
    }
    float area = square(2);
  • void square(float x) {
        return x * x;
    }
    area = square(2.0);
  • void square(float x) {
        x * x;
        return;
    }
    area = square(2);

2. 下面代码的描述中,正确的是( )。

{{ select(2) }}

  • 代码执行结束后, times 的值为0
  • n 是形参, times 是实参
  • n 是实参, times 是形参
  • 代码最后一行换成 n_chars(times, my_char); 也可以

3. 给定以下代码,执行下述代码后,变量 a 的值为( )

{{ select(3) }}

  • 5
  • 10
  • 15
  • 20

4. 运行下面代码,屏幕上输出是( )。

{{ select(4) }}

  • 0.2
  • 0.5
  • 1.2
  • 1.5

5. 运行下面代码片段后, x 和 *p 的结果分别是( )。

{{ select(5) }}

  • 20 20
  • 20 22
  • 22 20
  • 22 22

6. 下面的描述中,( )不能正确定义一个名为 Student 的结构体以及一个包含20个元素的结构数组。

{{ select(6) }}

7. 假定整型是32位,对一个 2 行 3 列的二维整数数组 array ,假设数组第一个元素在内存中的地址为 0x7ffee4065820 ,则第2行第2个元素的地址 &array[1][1] 为( )。

{{ select(7) }}

  • 0x7ffee4065824
  • 0x7ffee4065828
  • 0x7ffee406582c
  • 0x7ffee4065830

8. 下面( )正确定义二维数组。

{{ select(8) }}

  • int a[3][];
  • int a[][];
  • int a[][4];
  • int a[][2] = {{1,2},{1,2},{3,4}};

9. 下面代码采用递推算法来计算斐波那契数列f(n)=f(n-1)+f(n-2),则横线上应填写( )。

{{ select(9) }}

  • result = f1 + f2;
    f1 = f2;
    f2 = result;
  • result += f1 + f2;
    f1 = f2;
    f2 = result;
  • result += f1 + f2;
    f2 = result;
    f1 = f2;
  • result = f1 + f2;
    f2 = result;
    f1 = f2;

10. 下面关于排序算法(冒泡排序、插入排序和选择排序)的描述中,不正确的是( )。

{{ select(10) }}

  • 冒泡排序基于元素交换实现,需借助临时变量,共涉及3个单元操作;而插入排序基于元素赋值实现,仅需1个单元操作。因此冒泡排序的计算开销通常比插入排序更高。
  • 选择排序在任何情况下的时间复杂度都为O(n2)。
  • 冒泡排序在任何情况下的时间复杂度都为 O(n2)。
  • 如果给定数据部分有序,插入排序通常比选择排序效率更高。

11. 冒泡排序的第一轮操作是从左到右遍历数组,通过两两比较相邻元素,将当前最大的元素移动到末尾。给

定数组 arr[]={4, 1, 3, 1, 5, 2} ,执行第一轮冒泡排序后数组 arr 中的内容为( )。

{{ select(11) }}

  • 1, 4, 3, 1, 5, 2
  • 1, 3, 1, 4, 2, 5
  • 1, 4, 3, 1, 2, 5
  • 4, 1, 3, 1, 5, 2

12. 给定如下代码,其时间复杂度为( )。

{{ select(12) }}

  • O(n2)
  • O(2n)
  • O(1)
  • O(n)

13. 下面代码实现了插入排序函数,则横线上应填写( )。

{{ select(13) }}

  • int base = nums[i], j = i - 1;
  • int base = nums[i], j = i;
  • int base = nums[0], j = i - 1;
  • int base = nums[0], j = i;

14. 下面哪种方式不能实现将字符串"Welcome to GESP!"输出重定向到文件 log.txt ( )。

{{ select(14) }}

  • freopen("log.txt", "w", stdout);
    cout << "Welcome to GESP!" << endl;
    fclose(stdout);
  • std::ofstream outFile("log.txt");
    outFile << "Welcome to GESP!" << endl;
    outFile.close();
  • std::ofstream outFile("log.txt");
    cout << "Welcome to GESP!" << endl;
    outFile.close();
  • ofstream log_file("log.txt");
    streambuf* org_cout = cout.rdbuf();
    cout.rdbuf(log_file.rdbuf());
    cout << "This output will go to the log file." << endl;
    cout.rdbuf(oorg_cout);

15. 运行下面的代码,将出现什么情况?( )

{{ select(15) }}

  • 屏幕上输出 Caught: Runtime error occurred
  • 屏幕上输出 Caught an unknown exception
  • 程序调用 std::terminate()
  • 编译错误