#6733. 智汇少年的选择和判断题模拟卷2(高)
智汇少年的选择和判断题模拟卷2(高)
一、判断题
- 枚举法和模拟法只能单独使用,不能结合在一起解决问题。 {{ select(1) }}
- 正确
- 错误
- 执行代码
int arr[4]={2,4,6,8};
int sum=0;
for(int i=0;i<4;i++)
{
if(arr[i]==6) continue;
sum+=arr[i];
}
cout<<sum;
会输出20。 {{ select(2) }}
- 正确
- 错误
- 模拟法解决随机事件问题时,多次运行程序的结果可能不同。 {{ select(3) }}
- 正确
- 错误
- 执行语句 char str[10]="abc"; strcat(str,"def"); cout<<str; 会输出abcdef。 {{ select(4) }}
- 正确
- 错误
- 递归函数的调用深度不受栈空间的限制。 {{ select(5) }}
- 正确
- 错误
- 函数重载的多个函数,必须在同一个作用域中定义。 {{ select(6) }}
- 正确
- 错误
- 二维数组 int mat[3][3] = {{1},{2,3},{4,5,6}}; 中mat[2][1]的值是5。 {{ select(7) }}
- 正确
- 错误
- switch语句中,case后面的常量值可以重复。 {{ select(8) }}
- 正确
- 错误
- 执行语句 char a='A'; int b=a+32; cout<<(char)b; 会输出小写字母'a'。 {{ select(9) }}
- 正确
- 错误
- ifstream打开文件时,若文件不存在,会自动创建该文件。 {{ select(10) }}
- 正确
- 错误
二、单选题
- 下列代码中,能正确计算一维数组所有元素和的是() {{ select(11) }}
- int arr[5]={1,2,3,4,5}; int sum=0; for(int i=0;i<5;i++) sum+=arr[i]; cout<<sum;
- int arr[5]={1,2,3,4,5}; int sum=0; for(int i=1;i<=5;i++) sum+=arr[i]; cout<<sum;
- int arr[5]={1,2,3,4,5}; int sum=0; for(int i=0;i<4;i++) sum+=arr[i]; cout<<sum;
- int arr[5]={1,2,3,4,5}; int sum=1; for(int i=0;i<5;i++) sum+=arr[i]; cout<<sum;
- 定义函数 void change(int a[], int n){a[n]=a[n]*2;},调用int arr[3]={1,2,3};change(arr,1);后,arr[1]的值是() {{ select(12) }}
- 2
- 4
- 6
- 8
- 下列关于模拟法的说法,错误的是() {{ select(13) }}
- 模拟法需要还原实际问题的流程
- 模拟法常使用随机数模拟随机事件
- 模拟法的结果一定是确定的
- 模拟法可用于解决实际生活中的流程性问题
- 执行代码
int mat[3][2]={{1,2},{3,4},{5,6}};
int cnt=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
if(mat[i][j]>3) cnt++;
}
}
cout<<cnt;
输出结果是() {{ select(14) }}
- 2
- 3
- 4
- 5
- 下列关于递归和非递归的说法,正确的是() {{ select(15) }}
- 所有递归函数都可以转换为非递归函数
- 递归函数的代码量一定比非递归多
- 递归函数的执行效率一定更高
- 非递归函数不需要终止条件
- 下列关于字符数组的初始化,合法的是() {{ select(16) }}
- char str[5] = "hello";
- char str[] = {'h','e','l','l','o'};
- char str[10]; str = "hello";
- char str[6] = "hello";
- 执行代码
int i=0;
while(i<7)
{
i++;
if(i%3==0) continue;
if(i==5) break;
cout<<i;
}
输出结果是() {{ select(17) }}
- 124
- 1246
- 1234
- 12345
- 下列隐式类型转换中,不会发生数据丢失的是() {{ select(18) }}
- double a=3.9; int b=a;
- int a=100; double b=a;
- char a=128; int b=a;
- long a=1000000; int b=a;
- 下列代码中,能正确向文件data.txt中写入字符串"hello c++"的是( ) {{ select(19) }}
- #include using namespace std; int main(){ ofstream fout; fout.open("data.txt"); fout<<"hello c++"; fout.close(); return 0; }
- #include using namespace std; int main(){ ifstream fout; fout.open("data.txt"); fout<<"hello c++"; fout.close(); return 0; }
- #include using namespace std; int main(){ ofstream fout; fout.open("data.txt"); fout<<"hello c++"; return 0; }
- #include using namespace std; int main(){ ofstream fout; fout<<"hello c++"; fout.close(); return 0; }
- 定义函数 int mul(int a, int b=3){return a*b;},调用mul(4,5)的结果是() {{ select(20) }}
- 12
- 15
- 20
- 60
- 下列关于多层循环的代码,语法正确且输出123456的是() {{ select(21) }}
- for(int i=1;i<=2;i++){ for(int j=3i-2;j<=3i;j++){ cout<<j; } }
- for(int i=1;i<=2;i++){ for(int j=1;j<=3;j++){ cout<<j; } }
- for(int i=0;i<2;i++){ for(int j=1;j<=3;j++){ cout<<i+j; } }
- for(int i=1;i<=3;i++){ for(int j=1;j<=2;j++){ cout<<i+j; } }
- 执行语句 int a=22, b=5; cout<<(a-b)%b + a/b; 输出结果是( ) {{ select(22) }}
- 4
- 5
- 6
- 7
- 下列关于枚举法的说法,正确的是() {{ select(23) }}
- 枚举法不需要判断条件
- 枚举范围越大,执行效率越高
- 枚举法可解决答案有限的问题
- 枚举法的代码实现比其他算法复杂
- 执行代码
int num[4]={8,6,4,2};
int *p=num+1;
cout<<*(p+2);
输出结果是() {{ select(24) }}
- 8
- 6
- 4
- 2
- 下列问题中,适合用模拟法解决的是() {{ select(25) }}
- 求 100 以内的所有偶数
- 模拟骰子投掷 100 次统计点数分布
- 求两个数的最大公约数
- 枚举所有三位数的水仙花数
- 使用数学函数 abs(-7.5) 计算绝对值,需包含的头文件是() {{ select(26) }}
<cmath><cstring><iostream><fstream>
- 下列函数中,用于字符串拼接的是() {{ select(27) }}
- strcpy()
- strlen()
- strcat()
- strcmp()
- 执行语句 char s[]="program"; cout<<strlen(s); 输出结果是() {{ select(28) }}
- 6
- 7
- 8
- 9
- 递归函数 int g(int n){if(n<=2) return n; return g(n-1)+g(n-2);},调用g(5)的结果是() {{ select(29) }}
- 5
- 8
- 13
- 21
- 下列关于函数值传递的说法,错误的是() {{ select(30) }}
- 形参和实参占用不同的内存空间
- 形参是实参的一个副本
- 函数内部修改形参会影响实参值
- 基本数据类型默认采用值传递
- 执行代码
int i=1, res=0;
do
{
res+=i*2;
if(i==3) break;
i++;
} while(i<=5);
cout<<res;
输出结果是() {{ select(31) }}
- 12
- 18
- 20
- 30
- 定义二维数组 int arr[2][3] = {{5},{6,7}}; 则arr[0][2]的值是() {{ select(32) }}
- 5
- 6
- 0
- 7
- 下列代码中,多层if-else逻辑执行后输出2的是() {{ select(33) }}
- int x=5; if(x>10) cout<<1; else if(x>3) cout<<2; else cout<<3;
- int x=2; if(x>10) cout<<1; else if(x>3) cout<<2; else cout<<3;
- int x=15; if(x>10) cout<<1; else if(x>3) cout<<2; else cout<<3;
- int x=0; if(x>10) cout<<1; else if(x>3) cout<<2; else cout<<3;
- 执行语句 int a=9, b=2; double c=(double)a/b; cout<<c; 输出结果是() {{ select(34) }}
- 4
- 4.5
- 5
- 9.2
- 下列关于C++文件关闭的说法,正确的是() {{ select(35) }}
- 文件关闭可调用close()函数
- 程序结束后文件会自动关闭,无需手动操作
- close()函数可以重复调用多次
- ofstream文件写入后无需关闭,内容会自动保存
三、多选题
- 下列关于函数参数传递的说法,正确的有() {{ multiselect(36) }}
- 数组作为函数参数时,传递的是数组首元素的地址
- 引用传递的参数需要在参数名前加&
- 引用传递的形参修改会影响实参
- 函数的默认参数可以放在参数列表的任意位置
- 以下代码用于计算所有满足 i * j < 1000 的 (i, j) 对数,且 i 和 j 均为正整数。关于代码的优化,下列说法正确的有:
int count = 0;
for (int i = 1; i <= 1000; i++)
for (int j = 1; j <= 1000; j++)
if (i * j < 1000)
count++;
{{ multiselect(37) }}
- 可以将内层循环的条件改为 j <= 999 / i 来减少循环次数
- 仅交换内外层循环、不修改循环边界,总循环次数不变
- 交换内外层循环后,也能通过调整边界实现优化
- 该代码无法通过调整循环边界进行优化
- 下列关于枚举法的执行步骤,正确的有() {{ multiselect(38) }}
- 确定枚举的对象和范围
- 明确问题的判断条件
- 逐一列举所有可能的解
- 验证每个解是否符合判断条件
- 下列关于头文件函数的使用,正确的有() {{ multiselect(39) }}
- strcpy(str1,str2)将str2的内容复制到str1
- strcmp(str1,str2)若返回 0,表示str1和str2相等
- strcat(str1,str2)将str2拼接到str1末尾,会覆盖str1的'\0'
- strlen(str)计算的长度包含'\0'
- 下列关于递归函数的递推和回归阶段,说法正确的有() {{ multiselect(40) }}
- 递推阶段是从原问题向终止条件推进
- 回归阶段是从终止条件向原问题回推计算
- 所有递归函数的递推和回归阶段都必须存在
- 递推阶段会不断调用自身,直到触发终止条件
- 下列关于函数重载的说法,正确的有() {{ multiselect(41) }}
- 函数重载要求函数名相同
- 函数重载的参数个数必须不同
- 函数重载的参数类型必须不同
- 函数的返回值类型不同不能作为重载的依据
- 下列关于二维数组的遍历,代码正确的有() {{ multiselect(42) }}
- int mat[2][2]={{1,2},{3,4}}; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ cout<<mat[i][j]; } }
- int mat[2][2]={{1,2},{3,4}}; for(int i=0;i<4;i++){ cout<<mat[i/2][i%2]; }
- int mat[2][2]={{1,2},{3,4}}; int k=0; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ cout<<mat[k++][0]; } }
- int mat[2][2]={{1,2},{3,4}}; for(int i=1;i<=2;i++){ for(int j=1;j<=2;j++){ cout<<mat[i-1][j-1]; } }
- 下列关于switch语句和多层分支的说法,正确的有() {{ multiselect(43) }}
- switch语句的条件可以是整型或字符型
- switch语句可以通过break实现多层分支的逻辑
- 所有的if-else多层分支都可以转换为switch语句
- switch语句的default分支可以省略
- 下列关于显式类型转换的说法,正确的有() {{ multiselect(44) }}
- 显式类型转换需手动指定转换类型
- 显式类型转换可以避免隐式转换的意外数据丢失
- 显式类型转换的语法为(类型名)变量
- 显式类型转换不会造成任何数据丢失
- 下列关于C++文件打开方式的说法,正确的有() {{ multiselect(45) }}
- ios::in表示以读方式打开文件
- ios::out表示以写方式打开文件,会覆盖原有内容
- ios::app表示以追加方式打开文件,内容写在文件末尾
- ios::binary表示以二进制方式打开文件