#481. 2026信息素养C++模拟题(三)

2026信息素养C++模拟题(三)

单选题(每题 5 分,共 100 分)

  1. 商队记录了丝绸之路 55 个驿站的海拔(米):1200120015001500180018002100210024002400。以下数组定义正确的是? {{ select(1) }}
  • int altitude[4] = {1200, 1500, 1800, 2100, 2400};
  • int altitude[] = {1200, 1500, 1800, 2100, 2400};
  • int altitude(5) = {1200, 1500, 1800, 2100, 2400};
  • float altitude[5] = {1200, 1500, 1800, 2100, 2400};
  1. 驿站数组存储货物重量。执行以下代码后,arr[4] 的值是多少?
int arr[5] = {10, 20, 30, 40};

{{ select(2) }}

  • 00
  • 1010
  • 4040
  • 未定义
  1. 商队需要计算货物总重量。以下代码的输出是什么?
int weight[] = {50, 80, 120, 70};
int sum = 0;
for(int i = 0; i < 4; i++) {
    sum += weight[i];
}
cout << sum;

{{ select(3) }}

  • 5050
  • 120120
  • 240240
  • 320320
  1. 驿站需要找出平均海拔。以下代码的输出是什么?
int h[] = {1000, 1500, 2000};
float avg = (h[0] + h[1] + h[2]) / 3.0;
cout << avg;

{{ select(4) }}

  • 15001500
  • 1500.01500.0
  • 1500.331500.33
  • 1500.671500.67
  1. 商队定义函数计算路程。以下哪个函数声明正确?(假设需要返回整数类型的总路程) {{ select(5) }}
  • calculate(int a, int b);
  • int calculate(int a, b);
  • int calculate(int a, int b);
  • void calculate(int a, int b);
  1. 驿站函数计算两数最大值。以下代码的输出是什么?
int max(int a, int b) {
    if(a > b) return a;
    else return b;
}
int main() {
    cout << max(35, 48);
    return 0;
}

{{ select(6) }}

  • 3535
  • 4848
  • 8383
  • 00
  1. 商队递归计算阶乘。以下代码中,factorial(5) 的返回值是多少?
int factorial(int n) {
    if(n <= 1) return 1;
    else return n * factorial(n-1);
}

{{ select(7) }}

  • 55
  • 2424
  • 120120
  • 720720
  1. 驿站需要交换两个变量的值。以下代码执行后,ab 的值分别是?
int a = 10, b = 20;
int temp = a;
a = b;
b = temp;

{{ select(8) }}

  • a=10, b=20
  • a=20, b=10
  • a=10, b=10
  • a=20, b=20
  1. 商队使用二维数组存储仓库库存。以下数组元素个数正确的是?
int inventory[3][4];

{{ select(9) }}

  • 77
  • 1212
  • 3434
  • 33
  1. 驿站统计货物数量超过 100100 的仓库个数。以下代码的输出是什么?
int stock[] = {80, 120, 95, 150, 70};
int count = 0;
for(int i = 0; i < 5; i++) {
    if(stock[i] > 100) count++;
}
cout << count;

{{ select(10) }}

  • 11
  • 22
  • 33
  • 44
  1. 商队需要查找特定货物。以下代码的输出是什么?
int items[] = {5, 10, 15, 20, 25};
bool found = false;
for(int i = 0; i < 5; i++) {
    if(items[i] == 15) { 
        found = true; 
        break;
    }
}
cout << (found ? "找到" : "未找到");

{{ select(11) }}

  • 未找到
  • 找到
  • 33
  • 1515
  1. 驿站函数判断是否为闰年。以下代码的输出是什么?
bool isLeapYear(int year) {
    return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {
    cout << isLeapYear(2024);
    return 0;
}

{{ select(12) }}

  • 00
  • 11
  • true
  • false
  1. 商队需要冒泡排序。以下哪趟排序后数组变为 {10, 20, 30, 50, 40}?原数组:{10, 30, 40, 20, 50} {{ select(13) }}
  • 第1趟
  • 第2趟
  • 第3趟
  • 第4趟
  1. 驿站使用函数计算数组元素和。以下代码的输出是什么?
int sumArray(int arr[], int n) {
    int sum = 0;
    for(int i = 0; i < n; i++) {
        sum += arr[i];
    }
    return sum;
}
int main() {
    int data[] = {100, 200, 300};
    cout << sumArray(data, 3);
return 0;
}

{{ select(14) }}

  • 100100
  • 200200
  • 300300
  • 600600
  1. 商队二维数组存储每日行程(公里)。以下代码的输出是什么?
int route[2][3] = {{10, 20, 30}, {40, 50, 60}};
cout << route[1][2];

{{ select(15) }}

  • 1010
  • 2020
  • 5050
  • 6060
  1. 驿站需要计算指数。以下函数的返回值是多少?
int power(int base, int exp) {
    int result = 1;
    for(int i = 0; i < exp; i++) {
        result *= base;
    }
    return result;
}

power(2, 10)

{{ select(16) }}

  • 1010
  • 2020
  • 10241024
  • 100100
  1. 商队使用引用参数交换值。以下代码执行后,ab 的值分别是?
void swap(int &x, int &y) {
    int temp = x;
    x = y;
    y = temp;
}
int main() {
    int a = 5, b = 8;
    swap(a, b);
    cout << a << " " << b;
    return 0;
}

{{ select(17) }}

  • 55 88
  • 88 55
  • 88 88
  • 55 55
  1. 驿站计算最大公约数(GCD)。以下代码中,gcd(48, 18) 的返回值是多少?
int gcd(int a, int b) {
    while(b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

{{ select(18) }}

  • 22
  • 33
  • 66
  • 99
  1. 商队定义常量表示丝绸之路驿站总数。以下哪个定义正确? {{ select(19) }}
  • int STATIONS = 10;
  • const int STATIONS = 10;
  • #define STATIONS 10
  • B和C都正确
  1. 驿站需要查找数组中的最大值和最小值。以下代码的输出是什么?
int values[] = {25, 75, 50, 100, 125};
int max = values[0], min = values[0];
for(int i = 1; i < 5; i++) {
    if(values[i] > max) max = values[i];
    if(values[i] < min) min = values[i];
}
cout << max - min;

{{ select(20) }}

  • 2525
  • 7575
  • 100100
  • 125125