Multiple Choice Questions
Question 1: The “memory” we usually refer to belongs to the () in a computer.
A. Output device
B. Input device
C. Storage device
D. Printing device
[Answer] C
Question 2: The following C++ cannot be used as a variable name () .
A. redStar
B. RedStar
C. red_star
D. red star
[Answer] D
Question 3: The value of the C++ expression 2 – 1 && 2 % 10 is () .
A. 0
B. 1
C. 2
D. 3
[Answer] B
Question 4: The output after executing the following C++ code segment is () .
int a = 3, b = 4;
cout << “a+b=”<< a+b;
A. 3+4= 7
B. 3+4=7
C. a+b=7
D. a+b=a+b
[Answer] C
Question 5: In C++ language, the values of int type variables x, y, z are 2, 4, 6 respectively. The following expression that evaluates to true is () .
A. x > y || x > z
B. x != z – y
C. z > y + x
D. x < y || !x < z
[Answer] D
Question 6: For int type variables a, b, c, the following statement does not conform to C++ syntax is () .
A. c += 5;
B. b = c % 2.5;
C. a = (b = 3, c = 4, b + c);
D. a -= a = (b = 6) / (c = 2);
[Answer] B
Question 7: The output after executing the following C++ code is () .
int m = 14;
int n = 12;
if (m % 2 == 0 && n % 2 == 0)
cout <<“Both are even”;
else if (m % 2 == 1 && n % 2 == 1)
cout <<“Both are odd”;
else
cout <<“Not both even or odd”;
A. Both are even
B. Both are odd
C. Not both even or odd
D. None of the above statements are correct
[Answer] A
Question 8: The output after executing the following C++ code is () .
int m = 14;
int n = 12;
if (m % 2 && n % 2)
cout <<“Both are even”;
else if (m % 2 == 1 && n % 2 == 1)
cout <<“Both are odd”;
else
cout <<“Not both even or odd”;
A. Both are even
B. Both are odd
C. Not both even or odd
D. None of the above statements are correct
[Answer] C
Question 9: The output after executing the following C++ code is () .
int m = 7;
if (m / 5 || m / 3)
cout << 0;
else if (m / 3)
cout << 1;
else if (m / 5)
cout << 2;
else
cout << 3;
A. 0
B. 1
C. 2
D. 3
[Answer] A
Question 10: The output after executing the following C++ code segment is () .
int cnt = 0;
for (int i = 1; i <= 5; i++)
cnt = cnt + 1;
cout << cnt;
A. 1
B. 4
C. 5
D. 10
[Answer] C
Question 11: The output after executing the following C++ code is () .
int tnt = 0;
for (int i = 1; i < 5; i += 2)
tnt = tnt + i;
cout << tnt;
A. 2
B. 4
C. 9
D. 10
[Answer] B
Question 12: The output after executing the following C++ code is () .
int n = 5;
int cnt = 1;
while(n >= 0){
cnt += 1;
n -= 2;
}
cout << cnt;
A. 3
B. 4
C. 6
D. 7
[Answer] B
Question 13: The following C++ code is used to find all factors of a positive integer, that is, output all numbers that can divide a positive integer. For example, if the input is 10, the output is 1, 2, 5, 10; if the input is 12, the output is 1, 2, 3, 4, 6, 12; if the input is 17, the output is 1, 17. The code to fill in the blank is () .
int n = 0;
cout <<“Please enter a positive integer:”;
cin >> n;
for(___________)//Fill in the code here
if (n % i == 0)
cout << i << endl;
A. int i = 1; i < n; i + 1
B. int i = 1; i < n + 1; i + 1
C. int i = 1; i < n; i++
D. int i = 1; i < n + 1; i++
[Answer] D
Question 14: In the following code, fill in the blank to output the sum of the squares of the digits of the positive integer 1234.
int n = 1234, s = 0;
for (; n; n /= 10)
s += _______;//Fill in the code here
cout << s << endl;
A. n / 10
B. (n / 10) * (n / 10)
C. n % 10
D. (n % 10) * (n % 10)
[Answer] D
Question 15: After executing the following C++ program, the output result is () .
int n = 5, s = 1;
for (; n = 0; n–)
s *= n;
cout << s << endl;
A. 1
B. 0
C. 120
D. Cannot determine
[Answer] A
True or False Questions
Question 1: Early computer memory was not large enough, so character libraries could be solidified on an expansion card containing read-only memory inserted into the computer motherboard to help process Chinese characters.
True
False
[Answer] True
Question 2: The Sunway TaihuLight supercomputer is a supercomputer independently developed in China, and has repeatedly ranked first in the global TOP500 supercomputer list.
True
False
[Answer] True
Question 3: The value of the C++ expression int(3.14) is 3.
True
False
[Answer] True
Question 4: The output of the C++ statement cout << (2, 3, “23”) is 2, 3, 23.
True
False
[Answer] False
Question 5: The C++ loop statement for (int i = 0; i < 10; i += 2) means that i starts from 0 and ends at 10 but does not include 10, with an interval of 2.
True
False
[Answer] True
Question 6: The value of the C++ expression (‘1’ + ‘1’) is ‘2’.
True
False
[Answer] False
Question 7: In C++ language, the do-while loop cannot lead to an infinite loop, but the while loop can.
True
False
[Answer] False
Question 8: In the following C++ code, since the continue in the loop is unconditionally executed, it will lead to an infinite loop.
for (int i = 1; i < 10; i++) continue;
True
False
[Answer] False
Question 9: In C++ code, you cannot name a variable cout, as cout is a C++ keyword.
True
False
[Answer] False
Question 10: C++ is a high-level programming language.
True
False
[Answer] True
Programming Questions
Question 1: Buy Stationery
[Problem Description]
School has started, and Xiaoming comes to the stationery store to buy stationery. The signature pen costs 2 yuan each, he needs X pens; the notebook costs 5 yuan each, he needs Y notebooks; the ruler costs 3 yuan each, he needs Z rulers. Xiaoming has Q yuan. Please help Xiaoming calculate whether he has enough money to buy the stationery he needs.
[Input Description]
Input 4 lines.
The first line contains a positive integer X, which is the number of signature pens Xiaoming buys. It is agreed that 1≤X≤10.
The second line contains a positive integer Y, which is the number of notebooks Xiaoming buys. It is agreed that 1≤Y≤10.
The third line contains a positive integer Z, which is the number of rulers Xiaoming buys. It is agreed that 1≤Z≤10.
The fourth line contains a positive integer Q, which is the amount of money Xiaoming has (in yuan).
[Output Description]
Output 2 lines. If Xiaoming has enough money to buy the stationery he needs, the first line outputs “Yes”, and the second line outputs the amount of money Xiaoming will have left (in yuan); otherwise, the first line outputs “No”, and the second line outputs how much money Xiaoming lacks (in yuan).
[Sample Input 1]

[Sample Output 1]

[Sample Input 2]

[Sample Output 2]

[Reference Program]
-
#include <iostream>
-
using namespace std;
-
int main() {
-
int x = 0, y = 0, z = 0, q = 0;
-
cin >> x >> y >> z >> q;
-
int t = x * 2 + y * 5 + z * 3;
-
if (q >= t) {
-
cout << “Yes” << endl;
-
cout << q – t << endl;
-
} else {
-
cout << “No” << endl;
-
cout << t – q << endl;
-
}
-
return 0;
-
}
Question 2: Xiaoming’s Lucky Number
[Problem Description]
All positive integers with a unit digit of k, and all multiples of k, are called “k lucky numbers” by Xiaoming. Xiaoming wants to know the sum of all k lucky numbers between positive integers L and R (including L and R), can you help him?
[Input Description]
Input 3 lines. The first line contains a positive integer L, the second line contains a positive integer R, and the third line contains a positive integer R. It is agreed that 2≤k≤9, 1≤L≤R≤1000.
[Output Description]
Output 1 line, the sum of the lucky numbers that meet the requirements.
[Sample Input 1]

[Sample Output 1]

[Sample Explanation 1]
There is 1 lucky number 7 between 1 and 10: 7. Because 7 is both a multiple of 7 and has a unit digit of 7. Therefore, the result is 7.
[Sample Input 2]

[Sample Output 2]

[Sample Explanation 2]
There are 2 lucky numbers 7 between 10 and 20: 14 and 17. 14 is a multiple of 7, and 17 has a unit digit of 7. Therefore, the result is 31.
[Reference Program]
-
#include <iostream>
-
using namespace std;
-
int main() {
-
int k = 0, L = 0, R = 0, sum = 0;
-
cin >> k >> L >> R;
-
for (int n = L; n <= R; n++)
-
if (n % 10 == k || n % k == 0)
-
sum += n;
-
cout << sum << endl;
-
return 0;
-
}
END
Previous Issues · Recommendations
Analysis of C++ Level 3 Exam Questions June 2023
Analysis & Answers for the First Round (Preliminary) of CSP-J 2023
Is GESP and CSP really able to skip the preliminary round?

