#P50002. 中学组选择题

中学组选择题

信阳市中小学人工智能教育创意大赛中学组选择题(C++)

题目描述

本试卷共20道单项选择题,考察计算机基础知识、C++基本语法、程序阅读和理解能力。

第1题
在计算机中,RAM代表什么?

{{ select(1) }}

  • 随机存取存储器
  • 只读存储器
  • 硬盘存储器
  • 中央处理器

第2题
下列哪个是操作系统软件?

{{ select(2) }}

  • Microsoft Word
  • Windows 10
  • Adobe Photoshop
  • Google Chrome

第3题

C++中,浮点数默认的类型是? {{ select(3) }}

  • float
  • double
  • long double
  • int

第4题
以下哪个是合法的C++变量名?

{{ select(4) }}

  • 123abc
  • my var
  • myVar123
  • int

第5题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int i = 5;
    cout << i++ << " " << i;
    return 0;
}

{{ select(5) }}

  • 5 6
  • 6 5
  • 5 5
  • 6 6

第6题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int i = 5;
    cout << ++i << " " << i;
    return 0;
}

{{ select(6) }}

  • 6 6
  • 5 6
  • 6 5
  • 5 5

第7题

以下哪种强制类型转换是C++风格的? {{ select(7) }}

  • static_cast(3.14)
  • int(3.14)
  • (int)3.14
  • int 3.14

第8题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int a = 10, b = 3;
    cout << a / b << " " << a % b;
    return 0;
}

{{ select(8) }}

  • 3 1
  • 3 0
  • 3.33 1
  • 编译错误

第9题
在C++中,用于声明常量的关键字是?

{{ select(9) }}

  • const
  • final
  • static
  • constant

第10题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int x = 5;
    int y = 2;
    cout << (x > y ? "A" : "B");
    return 0;
}

{{ select(10) }}

  • A
  • B
  • 5
  • 2

第11题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int i = 3;
    if (i = 5) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

{{ select(11) }}

  • Yes
  • No
  • 编译错误
  • 运行错误

第12题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int a = 5;
    int b = 2;
    a += b;
    cout << a << " " << b;
    return 0;
}

{{ select(12) }}

  • 7 2
  • 5 2
  • 7 7
  • 5 7

第13题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 2; j++) {
            cout << i << j << " ";
        }
        cout << endl;
    }
    return 0;
}

{{ select(13) }}

  •  11 12   
     21 22      
     31 32 
    
  • 11 12 13   
    21 22 23
    
  • 11 21 31
    12 22 32
    
  • 11 12 21 22 31 32
    
    

第14题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    int sum = 0;
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= i; j++) {
            sum++;
        }
    }
    cout << sum;
    return 0;
}

{{ select(14) }}

  • 6
  • 5
  • 4
  • 3

第15题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (i == j) {
                cout << "1 ";
            } else {
                cout << "0 ";
            }
        }
        cout << endl;
    }
    return 0;
}

{{ select(15) }}

  • 1 0 0 
    0 1 0 
    0 0 1
    
  • 0 0 0 
    0 0 0 
    0 0 0
    
  • 1 1 1 
    1 1 1 
    1 1 1
    
  • 0 1 0 
    1 0 1 
    0 1 0
    
    

第16题
以下代码的输出结果是什么?

#include <iostream>
using namespace std;
int main() {
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 3; j++) {
            cout << i * j << " ";
        }
        cout << endl;
    }
    return 0;
}

{{ select(16) }}

  • 1 2 3 
    2 4 6
    
  • 1 2 
    2 4 
    3 6
    
  • 1 2 3 2 4 6
    
  • 1 2 2 4 3 6
    
    

第17题
请补全下面的代码,使其能够计算1到10之间所有偶数的和:

#include <iostream>
using namespace std;
int main() {
    int sum = 0;
    for (int i = 1; i <= 10; i++) {
        if (______) { // 填空处
            sum += i;
        }
    }
    cout << sum;
    return 0;
}

{{ select(17) }}

  • i % 2 == 0
  • i % 2 == 1
  • i / 2 == 0
  • i > 5

第18题
请补全下面的代码,使其能够输出一个5行的直角三角形:

#include <iostream>
using namespace std;
int main() {
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= ______; j++) { // 填空处
            cout << "*";
        }
        cout << endl;
    }
    return 0;
}

{{ select(18) }}

  • i
  • 5
  • i + 1
  • 5 - i

第19题
请补全下面的代码,使其能够正确交换两个变量的值:

#include <iostream>
using namespace std;
int main() {
    int a = 10, b = 20;
    int temp = a;
    a = b;
    ______ // 填空处
    cout << a << " " << b;
    return 0;
}

{{ select(19) }}

  • b = temp;
  • temp = b;
  • a = temp;
  • b = a;

第20题
请补全下面的代码,使其能够计算1!+2!+3!+4!+5!的值:

#include <iostream>
using namespace std;
int main() {
    int sum = 0;
    for (int i = 1; i <= 5; i++) {
        int fact = 1;
        for (int j = 1; j <= i; j++) {
            fact = ______; // 填空处
        }
        sum += fact;
    }
    cout << sum;
    return 0;
}

{{ select(20) }}

  • fact * j
  • fact * i
  • fact + j
  • fact + i