#5234. [GESP202512四级]模拟测试二-客观题

[GESP202512四级]模拟测试二-客观题

一.单选题(每题2分,共30分)

  1. 下列代码中,输出结果是( )。

{{ select(1) }}

  • 12 24 24 12
  • 24 12 12 24
  • 12 12 24 24
  • 24 24 12 12
  1. 下面函数不能正常执行的是 ( )。

{{ select(2) }}

  1. 下面程序输出的是( )。

{{ select(3) }}

  • 2 2 3 9
  • 2 10 3 9
  • 2 10 11 121
  • 2 10 3 100
  1. 下面这段代码会输出 ( )
01 int add(int a, int b = 1); // 函数声明
02
03 int main() {
04     cout << add(2) << " " << add(2, 3);
05     return 0;
06 }
07
08 int add(int a, int b) { // 函数定义
09     return a + b;
10 }

{{ select(4) }}

  • 3 5
  • 编译失败:定义处少了默认参数
  • 运行错误
  • 链接失败:未定义引用
  1. 下面这段代码会输出 ( )
01 int x = 5;
02 
03 void foo() {
04     int x = 10;
05     cout << x << " ";
06 }
07 
08 void bar() {
09     cout << x << " ";
10 }
11 
12 int main() {
13     foo();
14     bar();
15 }

{{ select(5) }}

  • 5 5
  • 10 10
  • 5 10
  • 10 5
  1. 下面程序运行的结果是 ( )
01 void increaseA(int x) {
02     x++;
03 }
04 void increaseB(int* p) {
05     (*p)++;
06 }
07 int main() {
08     int a = 5;
09     increaseA(a);
10     cout << a << " ";
11     increaseB(&a);
12     cout << a;
13 }

{{ select(6) }}

  • 6 7
  • 6 6
  • 5 6
  • 5 5
  1. 下面C++代码执行以后输出的是( )。

{{ select(7) }}

  • 0
  • 1
  • 6
  • 不确定
  1. 下面C++函数中采用的算法是( )

{{ select(8) }}

  • 递推
  • 递归
  • 迭代
  • 循环
  1. 插入排序在最好情况下的时间复杂度是( )。

{{ select(9) }}

  • O(1)O(1)
  • O(N/2)O(N/2)
  • O(N)O(N)
  • O(N2)O(N^2)
  1. 下面代码试图实现选择排序,使其能对数组 nums 排序为升序,则横线上应分别填写 ( )
01 void selectionSort(vector<int>& nums) {
02     int n = nums.size();
03     for (int i = 0; i < n - 1; ++i) {
04         int minIndex = i;
05         for (int j = i + 1; j < n; ++j) {
06             if ( __________ ) { // 在此处填入代码
07                 minIndex = j;
08             }
09         }
10         ____________________; // 在此处填入代码
11     }
12 }

{{ select(10) }}

  • 01 nums[j] < nums[minIndex]
    02 swap(nums[i], nums[minIndex])
    
  • 01 nums[j] > nums[minIndex]
    02 swap(nums[i], nums[minIndex])
    
  • 01 nums[j] <= nums[minIndex]
    02 swap(nums[j], nums[minIndex])
    
  • 01 nums[j] <= nums[minIndex]
    02 swap(nums[i], nums[j])
    
  1. 给定如下算法,其时间复杂度为( )
01 bool f(int arr[], int n, int target) {
02     for (int i = 0; i < n; i++) {
03         int sum = 0;
04         for (int j = 0; j < n; j++) {
05             if (i & (1 << j)) {
06                 sum += arr[j];
07             }
08         }
09         if (sum == target) return true;
10     }
11     return false;
12 }

{{ select(11) }}

  • O(n)O(n)
  • O(n2)O(n^2)
  • O(n3)O(n^3)
  • O(2n)O(2^n)
  1. 下述斐波那契数列计算的时间复杂度是( )
01 int fibonacci(int n) {
02     if (n == 0) return 0;
03     if (n == 1) return 1;
04     return fibonacci(n - 1) + fibonacci(n - 2);
05 }

{{ select(12) }}

  • O(n)O(n)
  • O(n2)O(n^2)
  • O(n3)O(n^3)
  • O(2n)O(2^n)
  1. 关于下面 C++ 程序的描述 ( ) 最准确。
01 ifstream in("data.txt");
02 string line;
03 while (getline(in, line)) {
04     cout << line << endl;
05 }

{{ select(13) }}

  • 将从标准输入读取每行,并输出到屏幕
  • 程序无法运行,因为 getline 只能读取 cin
  • data.txt 中的每一行读取并输出到屏幕
  • 程序将创建 data.txt 并写入默认文本
  1. C++ 中,异常处理机制 (try-catch块) 的主要目的是 ( )

{{ select(14) }}

  • 提高程序的运行速度
  • 在程序发生运行时错误时,提供一种结构化的错误处理方式
  • 确保程序在编译时没有错误
  • 减少程序的内存占用
  1. 关于异常处理,以下说法错误的是 ( )

{{ select(15) }}

  • try 块中的代码可能会抛出异常
  • catch 块可以有多个,处理不同类型的异常
  • throw 语句用于抛出异常
  • 所有异常都必须被捕获,否则程序会崩溃

二.判断题(每题2分,共20分)

  1. int& a 和 &a 是一样的,都是取 a 的地址。

{{ select(16) }}

  • 正确
  • 错误
  1. 以下代码不能够正确执行。

{{ select(17) }}

  • 正确
  • 错误
  1. 定义变量int a=5, 则cout << &++a会输出 6 。( )

{{ select(18) }}

  • 正确
  • 错误
  1. 两个函数之间可以使用全局变量来传递数据。( )

{{ select(19) }}

  • 正确
  • 错误
  1. 定义数组int a[2024][3][16]={2,0,2,4,3,1,6},则cout << a[2023][2][15]的结果不确定。( )

{{ select(20) }}

  • 正确
  • 错误
  1. 递推是在给定初始条件下,已知前一项 (或前几项) 求后一项的过程。

{{ select(21) }}

  • 正确
  • 错误
  1. 虽然插入排序的时间复杂度为 O(n2)O(n^2),但由于单元操作相对较少,因此在小数据量的排序任务中非常受欢迎。

{{ select(22) }}

  • 正确
  • 错误
  1. 对整数数组 {4, 1, 3, 1, 5, 2} 进行冒泡排序 (将最大元素放到最后),执行一轮之后是 {4, 1, 3, 1, 2, 5}

{{ select(23) }}

  • 正确
  • 错误
  1. 如果一个异常在 trytry 块中抛出但没有任何 catchcatch 匹配,它将在编译时报错。

{{ select(24) }}

  • 正确
  • 错误
  1. 下面 C++ 代码实现将 HelloHello 写入 data.txtdata.txt
01 ofstream out("data.txt");
02 out << "Hello";
03 out.close();

{{ select(25) }}

  • 正确
  • 错误