CCF GESP 2024年6月认证 C++ 3级

单选题
共 15 道 每题 2 分 共计 30 分
第 1 题

小杨父母带他到某培训机构给他报名参加 CCF 组织的 GESP 认证考试的第 1 级,那他可以选择的认证语言有( )种。

A

1

B

2

C

3

D

4

第 2 题

下面流程图在 yr 输入 2024 时,可以判定 yr 代表闰年,并输出 2月是29天,则图中菱形框中应该填入( )。

A

(yr%400==0) || (yr%4==0)

B

(yr%400==0) || (yr%4==0 && yr%100!=0)

C

(yr%400==0) && (yr%4==0)

D

(yr%400==0) && (yr%4==0 && yr%100!=0)

第 3 题

一般默认 64 位计算机系统中整型变量(int)还是 32 位,则整数能够表示的数据范围是( )。

A

$0$ ~ $2^{32}$

B

$0$ ~ $2^{64}$

C

$-2^{31}$ ~ $(2^{31}) - 1$

D

$-2^{63}$ ~ $(2^{63}) - 1$

第 4 题

下列代码将十进制转化成八进制,则横线上应填入( )。

#include <iostream>

using namespace std;

void decimal2octal(int decimal) {
    int oct_number[100];
    int i = 0;

    while (decimal > 0) {
        ________________________  // 在此处填入代码
    }

    for (int j = i - 1; j >= 0; j--) {
        cout << oct_number[j];
    }
    cout << endl;
}
A

oct_number[i] = decimal % 8; decimal /= 8;

B

oct_number[i] = decimal / 8; decimal %= 8;

C

oct_number[i++] = decimal % 8; decimal /= 8;

D

oct_number[i++] = decimal / 8; decimal %= 8;

第 5 题

二进制数 101.11 对应的十进制数是( )。

A

6.5

B

5.5

C

5.75

D

5.25

第 6 题

下列流程图的输出结果是( )。

A

5

B

10

C

20

D

30

第 7 题

下列代码的输出结果是( )。

#include <iostream>
using namespace std;

int main() {
    int a = 12;
    int result = a >> 2;
    cout << result << endl;
    return 0;
}
A

12

B

6

C

3

D

1

第 8 题

下列代码的输出结果是( )。

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 10;

    a = a ^ b;
    b = a ^ b;
    a = a ^ b;

    cout << "a = " << a << ", b = " << b << endl;
    return 0;
}
A

a = 5, b = 10

B

a = 5, b = 5

C

a = 10, b = 5

D

a = 10, b = 10

第 9 题

如果字符串定义为 char str[] = "GESP";,则字符数组 str 的长度为( )。

A

0

B

4

C

5

D

6

第 10 题

在下列代码的横线处填写( ),可以使得输出是“7”。

#include <iostream>
using namespace std;

int main() {
    int array[5] = {3, 7, 5, 2, 4};

    int max = 0;
    for(int i=0; i<5; i++)
        if(___________) // 在此处填入代码
            max = array[i];

    cout << max << endl;
    return 0;
}
A

max > array[i]

B

max < array[i]

C

max = array[i]

D

以上均不对

第 11 题

小杨在做数学题,题目要求找出从 1 到 35 中能被 7 整除的数字,即 [7, 14, 21, 28, 35],则横线处应填入哪个代码?( )

#include <iostream>
using namespace std;

int main() {
    int arr[35];

    int count = 0;
    for (int i = 1; i <= 35; i++) {
        if (i % 7 == 0)
            ________________ // 在此处填入代码
    }

    for (int i = 0; i < count; i++)
        cout << arr[i] << endl;

    return 0;
}
A

arr[count++] = i;

B

arr[i] = count++;

C

arr[i] = count;

D

arr[count] = count++;

第 12 题

已知字符 '0' 的ASCII编码的十进制表示为 48,则执行下面 C++ 代码后,输出是( )。

#include <iostream>
using namespace std;

int main() {
    string s = "0629";

    int n = s.length();
    int x = 0;
    for(int i = 0; i < n; i++)
        x += s[i];

    cout << x << endl;
    return 0;
}
A

17

B

158

C

209

D

316

第 13 题

某小学男子篮球队招募新成员,要求加入球队的成员身高在 135 厘米以上(不含 135 厘米)。本次报名的人员有 10 人,他们的身高分别是 125、127、136、134、137、138、126、135、140、145。完善以下代码,求出本次球队能够招募到新成员的人数?( )

#include <iostream>
using namespace std;

int main() {
    int arr[10] = {125, 127, 136, 134, 137, 138, 126, 135, 140, 145};

    int count = 0;
    for(int i=0; i<10; i++)
        ________________ // 在此处填入代码

    cout << count << endl;
    return 0;
}
A

count = arr[i]>135? 1: 0;

B

count += arr[i]>135? 1: 0;

C

count++;

D

以上都不对

第 14 题

下面可以正确输出 They're planning a party for their friend's birthday. 的 C++ 语句是?( )

A

cout << 'They\'re planning a party for their friend\'s birthday.' << endl;

B

cout << "They\'re planning a party for their friend's birthday."<< endl;

C

cout << 'They're planning a party for their friend's birthday.'<< endl;

D

cout << "They\'re planning a party for their friend\'s birthday." << endl;

第 15 题

如果执行下面 C++ 代码后,输出的结果是“gesp ccf org cn”,则横线上应填入哪个代码?( )

#include <iostream>
using namespace std;

int main() {
    string str = "gesp.ccf.org.cn";

    string delimiter = ".";
    string result = "";
    string token;
    size_t found = str.find(delimiter);
    while (found != string::npos) {
        token = str.substr(0, found);
        result += token;
        result += " ";
        ________________ // 在此处填入代码
        found = str.find(delimiter);
    }

    //最后一部分
    result += str;
    result += " ";

    cout << result << endl;
    return 0;
}
A

str = str.substr(found + delimiter.length(), str.length() - 1);

B

str = str.substr(found, str.length());

C

str = str.substr(found, str.length() -1);

D

以上都不对

单选题部分已到底了。