0 of 25 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 25 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
第 1 题 下的语句中,( )正确定义了个计算浮点数x的平方(x^2=x*x )的函数,并成功调该函数。
A.
float square(float x) {
return x * x;
}
float area = square(2);
——————————————————————————————————
B.
square(float x) {
return x * x;
}
float area = square(2);
________________________________
C.
void square(float x) {
return x * x;
}
area = square(2.0);
_________________________________
D.
void square(float x) {
x * x;
return;
}
area = square(2);
第 2 题 以下代码的描述中,正确的是( )。
void n_chars(char c, int n) {
while (n-- > 0)
cout << c;
}
char my_char = 'w';
int times = 5;
n_chars(my_char, times);
第 3 题 给定以下代码,执行代码后,变量 a 的值为( )。
void func(int& x) {
x = x * 2;
}
int a = 5;
func(a);
第 4 题 运行以下代码,屏幕上输出是( )
double* p_arr = new double [3];
p_arr[0] = 0.2;
p_arr[1] = 0.5;
p_arr[2] = 0.8;
p_arr += 1;
cout << p_arr[0] << endl;
p_arr -= 1;
delete p_arr;
第 5 题 运行以下代码段后, x 和 *p 的结果分别是( )。
int x = 20;
int* p = &x;
*p = *p + 2;
第 6 题 下的描述中,( )不能正确定义一个名为 Student 的结构体以及个包含20个元素的结构数组。
A.
struct Student {
string name;
int age;
float score;
};
struct Student students[20];
__________________________________
B.
struct Student {
string name;
int age;
float score;
};
Student students[20];
_____________________________________
C.
struct Student {
string name;
int age;
float score;
};
Student* students = new Student[20];
_______________________________________
D.
struct Student {
string name;
int age;
float score;
};
Student students = new Student[20];
第 7 题 假定整型是32位,对一个2行3列的二维整数数组 array ,假设数组第一个元素在内存中的地址为 0x7ffee4065820 ,则第2行第2个元素的地址 &array[1][1] 为( )。
int array[2][3] = {
{0, 1, 2},
{3, 4, 5}
};
第 8 题 下( )正确定义二维数组。
第 9 题 下代码采递推算法来计算斐波那契数列 ,则横线上应填写( )
int fib(int n) {
if (n == 0 || n == 1)
return n;
int f1 = 0;
int f2 = 1;
int result = 0;
for (int i = 2; i <= n; i++) {
________________________________ // 在此处填入代码
}
return result;
}
_________________________________________
A.
result = f1 + f2;
f1 = f2;
f2 = result;
________________________________________
B.
result += f1 + f2;
f1 = f2;
f2 = result;
________________________________________
C.
result += f1 + f2;
f2 = result;
f1 = f2;
________________________________________
D.
result = f1 + f2;
f2 = result;
f1 = f2;
第 10 题 下关于排序算法(冒泡排序、插排序和选择排序)的描述中,不正确的是( )。
第 11 题 冒泡排序的第一轮操作是从左到右遍历数组,通过两两较相邻元素,将当前最大的元素移动到末尾。给定数组 arr[]={4, 1, 3, 1, 5, 2} ,执行第一轮冒泡排序后数组 arr 中的内容为( )。
第 12 题 给定如下代码,其时间复杂度为( )。
int cellRecur(int n) {
if (n == 1)
return 1;
return cellRecur(n - 1) + cellRecur(n - 1) + 1;
}
第 13 题 下代码实现了插排序函数,则横线上应填写( )
void insertion_sort(vector &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; } }
第 14 题 下哪种式不能实现将字符串”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(oorg_cout);
第 15 题 运下的代码,将出现什么情况?( )
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;
}
第 16 题 在 C++ 中,下代码可以正确定义指针和初始化指针。
int* ptr;
*ptr = 10;
第 17 题 个函数必须在调之前既声明又定义。
第 18 题 函数参数可以通过值传递、引用传递和指针传递,这样函数内对参数的修改可以直接修改传变量的值。
第 19题 int arr[3][] 是个正确的维数组的声明。
第 20 题 递推是种通过已知的初始值和递推公式,逐步求解标值的算法。
第 21 题 某算法的递推关系式为T(n)=T(n–1)+n ( n为正整数)及T(0)=1 ,则该算法的时间复杂度为O(n^2) 。
第 21 题 冒泡排序的平均时间复杂度为O(n^2) ,但最优情况下为O(n) 。
第 23 题 冒泡排序和插排序都是稳定的排序算法。
第 24题 选择排序是稳定的排序算法。
第 25 题 在 C++语中,如果个函数可能抛出异常,那么定要在try 句调这个函数。