题目编号
语言
全部语言
等级
全部等级
知识点
选择知识点 (0)
找到 1260 道单选题
EXY-SC-0495
第 766 题

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

double hmean(double a, double b) {
    if (a == -b)
        throw runtime_error("Runtime error occurred");
    return 2.0*a*b/(a + b);
}

int main() {
    double x = 10;
    double y = -10;

    try {
        int result = hmean(x, y);
        cout << "hmean: " << result << endl;
    }
    catch (const runtime_error& e) {
        cout << "Caught: " << e.what() << endl;
    }
    catch (...) {
        cout << "Caught an unknown exception." << endl;
    }
    return 0;
}
A

屏幕上输出 Caught: Runtime error occurred

B

屏幕上输出 Caught an unknown exception

C

程序调用 std::terminate()

D

编译错误

语言: C++
GESP真题 四级
2024.12
单选题号: 15
EXY-SC-0494
第 767 题

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

A
freopen("log.txt", "w", stdout);
cout << "Welcome to GESP!" << endl;
fclose(stdout);
B
std::ofstream outFile("log.txt");
outFile << "Welcome to GESP!" << endl;
outFile.close();
C
std::ofstream outFile("log.txt");
cout << "Welcome to GESP!" << endl;
outFile.close();
D
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(org_cout);
语言: C++
GESP真题 四级
2024.12
单选题号: 14
EXY-SC-0493
第 768 题

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

void insertion_sort(vector<int> &nums) {
    for (int i = 1; i < nums.size(); i++) {
        ________________________ {  // 在此处填入代码
            while (j >= 0 && nums[j] > base)
                nums[j + 1] = nums[j];
                j--;
        }
        nums[j + 1] = base;
    }
}
A

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

B

int base = nums[i], j = i;

C

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

D

int base = nums[0], j = i;

语言: C++
GESP真题 四级
2024.12
单选题号: 13
EXY-SC-0492
第 769 题

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

int cellRecur(int n) {
    if (n == 1)
        return 1;
    return cellRecur(n - 1) + cellRecur(n - 1) + 1;
}
A

$O(n^2)$

B

$O(2^n)$

C

$O(1)$

D

$O(n)$

语言: C++
GESP真题 四级
2024.12
单选题号: 12
EXY-SC-0491
第 770 题

冒泡排序的第一轮操作是从左到右遍历数组,通过两两比较相邻元素,将当前最大的元素移动到末尾。给定数组 arr[]={4, 1, 3, 1, 5, 2},执行第一轮冒泡排序后数组 arr 中的内容为( )。

A

1, 4, 3, 1, 5, 2

B

1, 3, 1, 4, 2, 5

C

1, 4, 3, 1, 2, 5

D

4, 1, 3, 1, 5, 2

语言: C++
GESP真题 四级
2024.12
单选题号: 11
当前页显示 766 - 770 ,共 1260 道单选题