#1554. GESP四级真题(202406)

GESP四级真题(202406)

C++ 四级 2024 年 06 ⽉

1 单选题(每题 2 分,共 30 分)

第 1 题 下列代码中,输出结果是( )

#include<iostream>
using namespace std;
int func(int x, int y)
{
	int a = x, b = y;
	int t;
	t = a;
	a = b;
	b = t;
	cout << a << " " << b << " ";
}
int main()
{
	int c, d;
	c = 12;
	d = 24;
	func(12, 24);
	cout << c << " " << d << endl; 
    return 0;
}

{{ select(1) }}

  • 12 24 24 12
  • 24 12 12 24
  • 12 12 24 24
  • 24 24 12 12

第 2 题 下⾯函数不能正常执⾏的是()

//代码A 
#include<iostream>
using namespace std;
int func()
{
	//...
}
int main()
{
	//...
}

//代码B
#include<iostream>
using namespace std;

int main()
{
	func();
}
int func()
{
	//...
}

//代码C
#include<iostream>
using namespace std;
int func()
{
	//...
}
int main()
{
	func();
}

//代码D
#include<iostream>
using namespace std;
int func();
int main()
{
	func();
}
int func()
{
	//...
}

{{ select(2) }}

  • 代码A
  • 代码B
  • 代码C
  • 代码D

第 3 题 下⾯程序输出的是()

#include<iostream>
using namespace std;
int func();
int main()
{
	int i = 2;
	cout << i << endl;
	for(int x = 0; x < 1; x++)
	{
		int i = 10;
		cout << i << endl;
	}
	i = i + 1;
	cout << i << endl;
	{
		i = i * i;
		cout << i << endl; 
	}
}

{{ select(3) }}

  • 2 2 3 9
  • 2 10 3 9
  • 2 10 11 121
  • 2 10 3 100

第 4 题 假设变量 a 的地址是0x6ffe14,下⾯程序的输出是( )。

#include<iostream>
using namespace std;
int main()
{
	int *p;
	int a = 10;
	p = &a;
	p++;
	cout << p << endl;
}

{{ select(4) }}

  • 10
  • 0x6ffe14
  • 0x6ffe15
  • 0x6ffe18

第 5 题 如果下列程序输出的地址是 0x6ffe00 ,则 cout<<a+1<<endl; 输出的是()

#include<iostream>
using namespace std;
int main()
{
	int a[2][3] = {0};
	cout << a << endl;
}

{{ select(5) }}

  • 0x6ffe04
  • 0x6ffe0C
  • 0x6ffe08
  • 0x6ffe00

第 6 题 C++中,关于⽂件路径说法错误的是()

{{ select(6) }}

  • "GESP.txt":指定与当前⼯作⽬录中的程序⽂件相同⽬录中的 GESP.txt ⽂件
  • "../data/GESP.txt":指定与当前⼯作⽬录中的程序⽂件上⼀级⽬录下的 data ⽬录中的 GESP.txt ⽂件
  • "./data/GESP.txt":指定与当前⼯作⽬录中的程序⽂件同级⽬录下的 data ⽬录中的 GESP.txt ⽂件
  • "GESP.txt"是绝对路径

第 7 题 关于直接插⼊排序,下列说法错误的是()

{{ select(7) }}

  • 插⼊排序的最好情况是数组已经有序,此时只需要进⾏ n1n-1 次⽐较,时间复杂度为O(n)O(n)
  • 最坏情况是数组逆序排序,此时需要进⾏ n(n1)n(n-1) 次⽐较以及 n1n-1 次赋值操作(插⼊)
  • 平均来说插⼊排序算法的复杂度为O(n2)O(n^2)
  • 空间复杂度上,直接插⼊法是就地排序,空间复杂度为O(n)O(n)

第 8 题 下列程序横线处,应该输⼊的是 ( )。

#include<iostream>
using namespace std;
int n, a[10001];
void swap(int &a, int &b)
{
	int t = a;
	a = b;
	b = t;
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = n; i > 1; i--)
		for(int j = 1; j < i; j++)
			if(a[j] > a[j + 1])
				___________________;
	for(int i = 1; i <= n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}

{{ select(8) }}

  • swap(a[j],a[j+1]);
  • swap(a[j-1],a[j]);
  • swap(a[j-1],a[j+1]);
  • swap(&a[j-1],&a[j+1]);

第 9 题 下⾯关于递推的说法不正确的是( )。

{{ select(9) }}

  • 递推表现为⾃⼰调⽤⾃⼰
  • 递推是从简单问题出发,⼀步步的向前发展,最终求得问题。是正向的
  • 递推中,问题的n要求是在计算中确定,不要求计算前就知道n
  • 斐波那契数列可以⽤递推实现求解

第 10 题 关于⼏种排序算法的说法,下⾯说法错误的是( )。

{{ select(10) }}

  • 选择排序不是⼀个稳定的排序算法
  • 冒泡排序算法不是⼀种稳定的排序算法
  • 插⼊排序是⼀种稳定的排序算法
  • 如果排序前2个相等的数在序列中的前后位置顺序和排序后它们2个的前后位置顺序相同,则称为⼀种稳定的排序算法

第 11 题 数组{45,66,23,1,10,97,52,88,5,33}进⾏从⼩到⼤冒泡排序过程中,第⼀遍冒泡过后的序列是( )。

{{ select(11) }}

  • {45,23,1,10,66,52,88,5,33,97}
  • {45,66,1,23,10,97,52,88,5,33}
  • {45,66,23,1,10,52,88,5,33,97}
  • {45,66,23,1,10,97,52,88,33,5}

第 12 题 下⾯的排序算法程序中,横线处应该填⼊的是( )。

int a[8]={ 2,3, 4, 5, 6,2,3,1};
for (int i=1;i<8;i++)
{
    int key = a[i];
    int j=i-1;
    while(a[j]>key && j>=0)
    {
        ________;
        j -= 1;
    }
    a[j + 1]= key;
}

{{ select(12) }}

  • a[j]=a[j-1];
  • a[j]=a[j+1];
  • a[j+1]=a[j-1];
  • a[j+1]=a[j];

第 13 题 下⾯的程序中,如果输⼊ 10 0 ,会输出( )。

#include<iostream>
using namespace std;

double Division(int a, int b)
{
	if(b == 0)
		throw "Division by zero condition!";
	else
		return ((double)a / (double)b);
}

void func()
{
	int len, time;
	cin >> len >> time;
	cout << Division(len, time) << endl;
}

int main()
{
	try{
		func();
	}
	catch(const char* errmsg)
	{
		cout << errmsg << endl;
	}
	catch(const int errmsg)
	{
		cout << errmsg << endl;
	}
	return 0;
}

{{ select(13) }}

  • Division by zero condition!
  • 0
  • 10
  • 100

第 14 题 10条直线,最多可以把平⾯分为多少个区域( )。

{{ select(14) }}

  • 55
  • 56
  • 54
  • 58

第 15 题 下⾯程序中,如果语句 cout<<p<<endl; 输出的是 0x6ffe00 ,则 cout<<++p<<endl; 输出的是()

int x[10][10][10]={{0}};
int *p;
p=&x[0][0][0];
cout<<p<<endl;
cout<<++p<<endl;

{{ select(15) }}

  • 0x6ffe0c
  • 0x6ffe09
  • 0x6ffe06
  • 0x6ffe04

2 判断题(每题 2 分,共 20 分)

第 1 题 int& a&a 是⼀样的,都是取 a 的地址。

{{ select(16) }}

第 2 题 以下代码不能够正确执⾏。

#include<iostream>
using namespace std;
int main()
{
	int a = 20;
	int& ra;
	ra = &a;
	cout << ra << endl;
	return 0;
}

{{ select(17) }}

第 3 题 引⽤是⼀个指针常量。

{{ select(18) }}

第 4 题 下⾯程序两个输出结果是⼀样的。

#include<iostream>
using namespace std;
int main()
{
	int a[2][3] = {0};
	cout << a << endl;
	cout << &a[0][0] << endl;
	return 0;
}

{{ select(19) }}

第 5 题 函数不可以调⽤⾃⼰。

{{ select(20) }}

第 6 题 函数参数传递过程中,如果传常量值、常量引⽤和常量指针都是不能被修改的,它们可以防⽌函数对实参的值或地址进⾏修改。

{{ select(21) }}

第 7 题 下⾯代码输出的值等于0。

#include<iostream>
using namespace std;
int main()
{
	int *p = NULL;
	cout << p << endl;
	return 0;
}

{{ select(22) }}

第 8 题 在下⾯这个程序⾥, a[i][j] 和⼀个普通的整型变量⼀样使⽤。

#include<iostream>
using namespace std;
int main()
{
	int a[10][10] = {0};
	for(int i = 0; i < 10; i++)
	{
		for(int j = 0; j < 10; j++)
		{
			if(i == j)
			{
				a[i][j] = 1;
			}
		}
	}
	return 0;
}

{{ select(23) }}

第 9 题 ⼀个⼀维数组,⾄少含有⼀个⾃然数N,是⼀个合法的数列。可以在⼀维数组末尾加⼊⼀个⾃然数M,M不能超过⼀维数组末尾元素的⼀半,形成⼀个新的合法的⼀维数组,如果N=6,那么可以有6个不同的合法数组。

{{ select(24) }}

第 10 题 插⼊排序算法中,平均时间复杂度是O(n2)O(n^2) ,最坏的情况逆序情况下,达到最⼤时间复杂度。

{{ select(25) }}