Analysis of the GESP C++ Level 1 Exam Questions for December 2024

Analysis of the GESP C++ Level 1 Exam Questions for December 20241. Multiple Choice Questions (Each question is2 points, total30 points)Analysis of the GESP C++ Level 1 Exam Questions for December 2024

Question 1: On October 8, 2024, the Nobel Prize in Physics was unexpectedly awarded to two computer scientists, John J. Hopfield and Geoffrey E. Hinton. The main research direction of these two scientists is ( ).

A. Astrophysics

B. Fluid Mechanics

C. Artificial Intelligence

D. Quantum Theory

[Answer] C

[Knowledge Point] Current Technology Events, Development in the Field of Artificial Intelligence

[Analysis] John Hopfield and Geoffrey Hinton have made outstanding contributions in the field of artificial intelligence, especially in neural networks and deep learning.

Question 2: Which of the following software is an operating system ( ).

A. Gaode Map

B. Tencent Meeting

C. Pure Blood Harmony

D. Kingsoft Office

[Answer] C

[Knowledge Point] Concept of Operating Systems and Common Software Types

[Analysis] An operating system is a program that manages computer hardware and software resources. Gaode Map is navigation software, Tencent Meeting is office software, and Kingsoft Office is an office suite, while Pure Blood Harmony is an operating system.

Question 3: Which of the following statements about the C++ code is correct ( ).

printf(“Hello,GESP!”);

A. There cannot be Chinese characters inside paired double quotes

B. Paired double quotes can be changed to English single quotes without changing the output effect

C. Paired double quotes can be changed to three consecutive English single quotes without changing the output effect

D. Paired double quotes can be changed to three consecutive English double quotes without changing the output effect

[Answer] D

[Knowledge Point] String Quote Rules in C++

[Analysis]

Option A: There can be Chinese characters inside double quotes, this statement is incorrect.

Option B: Strings in printf must use double quotes, single quotes are for characters and cannot be replaced, this statement is incorrect.

Option C: Three consecutive single quotes are not a valid representation of a C++ string, this statement is incorrect.

Question 4: The value of the C++ expression 12 – 3 * 2 && 2 is ( ).

A. 0

B. 1

C. 6

D. 9

[Answer] B

[Knowledge Point] C++ Operator Precedence and Expression Calculation (multiplication and division before addition and subtraction, logical AND operation)

[Analysis] Multiplication<span><span>3 * 2 = 6</span></span>. Subtraction<span><span>12 - 6 = 6</span></span>. Calculate logical AND<span><span>6 && 2</span></span>, in C++, non-zero values are considered<span><span>true</span></span>, so<span><span>true && true</span></span> results in<span><span>1</span></span>

Question 5: In C++, assuming N is a positive integer 2, then cout << (N / 3 + N % 3) will output ( ).

A. 0

B. 2

C. 3

D. 4

[Answer] B

[Knowledge Point] C++ Arithmetic Operators (division<span><span>/</span></span>, modulus<span><span>%</span></span>) operation rules

[Analysis] Calculate N/3: integer division, 2/3=0 (result takes the integer part). Calculate N%3: modulus operation, 2%3=2. Sum: 0 + 2 = 2

Question 6: The C++ statement cout << 7%3 << ‘ ‘<< “7%3” << ‘ ‘ << “7%3={7%3}” will output after execution ( ).

A. 1 1 1=1

B. 1 7%3 1=1

C. 1 7%3 7%3= 1

D. 1 7%3 7%3={7%3}

[Answer] D

[Knowledge Point] C++ Output Stream Character and String Concatenation Rules

[Analysis] The meaning of each part in the expression: 7%3 results in 1; ‘ ‘ is a space character; “7%3” is a string; “7%3=(7%3)” is a string, where (7%3) will be replaced by the calculated result 1. After concatenation, the output is 1 7%3 7%3=1

Question 7: The following C++ code executes to determine what day it will be after a few days. If it is Sunday, output“Sunday” otherwise output in the form of“Week 1”. The code to fill in the blank is ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. N % 7 != 0

B. N % 7 == 0

C. N == 0

D. N % 7

[Answer] B

[Knowledge Point] Logic of Week Calculation Using Modulus (period of 7) and Conditional Judgment

[Analysis]

There are 7 days in a week, and the calculation of which day it is is achieved by taking the modulus of 7 (remainder 0 corresponds to Sunday).

Option A: N%7 != 0 indicates it is not Sunday, which does not meet the condition of “outputting Sunday”.

Option B: N%7 == 0 indicates the remainder is 0, which means it is Sunday, meeting the condition.

Option C: N==0 is logically incorrect and unrelated to week calculation.

Option D: N%7 is an expression rather than a condition (conditions must return a boolean value), syntax error.

Question 8: The output of the following C++ code after execution is ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. 54

B. 20

C. 19

D. 18

[Answer] C

[Knowledge Point] C++ Execution Logic of For Loop, Variable Increment and Expression Calculation

[Analysis]

Initialize N=0, i starts from 1, the loop condition i < 10, executed 9 times (i=1 to i=9).

Each time the loop N += 1, so N finally equals 9.

In the last loop i=9, calculate N + i = 9 + 9 = 18

Question 9: The output of the following C++ code after execution is ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. 4950

B. 5050

C. 450

D. 100

[Answer] C

[Knowledge Point] C++ For Loop, Modulus Operation Accumulation Logic

[Analysis]

i loops from 0 to 99, i % 10 is the unit digit of i (0-9 loops).

Every 10 numbers (0-9, 10-19…90-99), the unit digits 0-9 each appear 10 times.

The sum is (0+1+2+…+9)×10 = 45×10 = 450

Question 10: The output of the following C++ code after execution is ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. 10

B. 9

C. 6

D. 5

[Answer] C

[Knowledge Point] C++ For Loop, Continue (Skip Loop) and Break (Terminate Loop) Logic

[Analysis]

i starts from 5, increments by 5 each time, loop condition i < 100, but when i >= 50, break. Meanwhile, if i is even (i%2==0), continue (skip this loop’s tnt +=1).

The traversed i values: 5 (odd, tnt=1), 10 (even, skip), 15 (odd, tnt=2), 20 (even, skip), 25 (odd, tnt=3), 30 (even, skip), 35 (odd, tnt=4), 40 (even, skip), 45 (odd, tnt=5), 50 (at this point i>=50, break).

Finally, tnt=5

Question 11: The following program is used to determine whether the input integer N is an even number that can be divided by 3. The code to fill in the blank is ( ).Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. (N%2)&&(N%3)

B. (N%2==0)&&(N%3)

C. (N%2)&&(N%3==0)

D. (N%2==0)&&(N%3==0)

[Answer] D

[Knowledge Point] Logical Operators (<span><span>&&</span></span>) and Modulus Operation (<span><span>%</span></span>) Conditional Judgment

[Analysis] Even number: N%2 == 0 (remainder is 0, divisible by 2); divisible by 3: N%3 == 0 (remainder is 0). Both are connected by && (logical AND), i.e., (N%2==0) && (N%3==0).

Question 12: The output of the following C++ code after execution is ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. 54

B. 45

C. 25

D. 10

[Answer] C

[Knowledge Point] C++ For Loop, Increment Operator (<span><span>i++</span></span>) Logic

[Analysis]

i++ is post-increment, meaning the current value of i participates in the accumulation of cnt, then i is incremented.

Number of loop executions: i from 1 to 9 (5 times in total, because i increments twice each time: for loop’s i++ and the statement’s i++, the actual effective loop count is (9-1)/2 + 1 = 5 times).

Accumulation process: 1 + 3 + 5 + 7 + 9 = 25.

Question 13: The int type variable a represents the length of a side of a square, as shown in the figure where all four sides of the square are 4. Which of the following statements will increase the perimeter (the sum of the four sides) of the square by 4? ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. a*4;

B. a+4;

C. a+1;

D. ++a;

[Answer] D

[Knowledge Point] Perimeter Calculation of a Square (Perimeter = 4 × Side Length) and the Impact of Variable Operations on Results

[Analysis]

To increase the perimeter by 4, the side length must increase by 4÷4=1.

Option A: a*4 calculates the perimeter, does not change the side length, exclude;

Option B: a+4 increases the side length by 4, the perimeter increases by 4×4=16, exclude;

Option C: a+1 is an expression (does not change a itself), cannot actually increase the perimeter, exclude;

Option D: ++a is a prefix increment, directly adds 1 to a (side length becomes 5), the perimeter becomes 4×5=20, which is an increase of 4 from the original perimeter 4×4=16, meeting the requirement.

Question 14: The value of the C++ expression (6 > 2) * 2 is ( ).

A. 1

B. 2

C. true

D. truetrue

[Answer] B

[Knowledge Point] C++ Relational Operators (<span><span>></span></span>) and Arithmetic Operators Precedence (the result of relational operation is<span><span>bool</span></span>,<span><span>true</span></span> corresponds to<span><span>1</span></span>,<span><span>false</span></span> corresponds to<span><span>0</span></span>)

[Analysis]

6 > 2, the result is

<span><span>true</span></span> (in C++ represented as<span><span>1</span></span>); calculate<span><span>1 * 2 = 2</span></span>.

Question 15: The following C++ code is used to determine whether the input integer is a digit-increasing number, that is, gradually increasing from the first digit to the last digit, if so, output1. For example, 123 is a digit-increasing number. The code to fill in the blank is ( ).

Analysis of the GESP C++ Level 1 Exam Questions for December 2024Analysis of the GESP C++ Level 1 Exam Questions for December 2024

A. n2 = N%10

B. N /= 10

C. n2 = N/10, N %= 10

D. n2 = N%10, N /= 10

[Answer] D

[Knowledge Point] C++ Loop Structure (<span><span>while</span></span>), Modulus (<span><span>%</span></span>) and Division (<span><span>/</span></span>) Operations in Digit-by-Digit Judgment

[Analysis]

To determine a “digit-increasing number” (increasing from the first digit to the last), it is necessary to extract digits one by one and compare the sizes of adjacent digits.

In the code, n1 = N % 10 extracts the current unit digit, and n2 needs to store the previous digit, and at the beginning of the loop, the previous digit of the first digit must be extracted (logical initial value).

Option D: n2 = N%10, N /= 10, first extracts the initial unit digit to n2, then removes the unit digit from N (achieving digit-by-digit processing), which is logical.

Other options:

Option A: only assigns n2, does not process N, cannot loop through digits;

Option B: only processes N, does not initialize n2;

Option C: logical error in operation, cannot correctly extract the initial digit.

2. True/False Questions (Each question is2 points, total20 points)

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

Question 1: In Windows Explorer, the operation to create a copy of an existing file A is Ctrl+C, then Ctrl+V. ( )

[Answer] √

[Knowledge Point] Windows Explorer Operation Shortcuts

[Analysis] In Windows Explorer, to create a copy of a file, the operation is to first press<span><span>Ctrl+C</span></span> (copy), then press<span><span>Ctrl+V</span></span> (paste), this statement iscorrect

Question 2: In C++, the expressions 8/3 and 8%3 have the same value. ( )

[Answer] √

[Knowledge Point] C++ Arithmetic Operators (Division<span><span>/</span></span>, Modulus<span><span>%</span></span>) Operation Rules

[Analysis]

8/3 is integer division, the result is

<span><span>2</span></span>; <span><span>8%3</span></span> is modulus, the result is<span><span>2</span></span>. Both values are the same

Question 3: X is a basic type variable in C++, then the statement cin>>X, cout <<X can receive keyboard input and output as is. ( )

[Answer] ×

[Knowledge Point] C++ Input and Output Streams (<span><span>cin</span></span>, <span><span>cout</span></span>) Applicable Scenarios

[Analysis] If<span><span>X</span></span> is a character array or string (not a basic type variable, such as<span><span>char X[10]</span></span>), <span><span>cin>>X</span></span> will truncate the input at spaces, unable to “output all content as is”; only when<span><span>X</span></span> is a basic type (like<span><span>int</span></span>, <span><span>float</span></span>) can it be fully output as is. The question does not specify<span><span>X</span></span> is a basic type, therefore this statement isincorrect.

Question 4: The following C++ code will output 10 after execution. ( )

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

[Answer] ×

[Knowledge Point] C++ For Loop, Continue Statement Execution Logic

[Analysis]

In the loop,

<span><span>continue</span></span> will skip the subsequent statements of the current loop (i.e.,<span><span>N += 1</span></span> will not execute),<span><span>N</span></span> will always be<span><span>0</span></span>, the final output will be<span><span>0</span></span> instead of<span><span>10</span></span>, this statement isincorrect.

Question 5: The following C++ code will output 100 after execution. ( )

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

[Answer] ×

[Knowledge Point] C++ For Loop, Continue Statement Execution Logic

[Analysis]

In the loop,<span><span>continue</span></span> will skip the current loop,<span><span>i</span></span> will eventually execute to<span><span>101</span></span> (because the loop condition is<span><span>i <= 100</span></span>), outputting<span><span>101</span></span> instead of<span><span>100</span></span>, this statement isincorrect.

Question 6: The following C++ code will execute three times outputting (i.e., the marked line L2 will be executed once). ( )

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

[Answer] ×

[Knowledge Point] C++ For Loop Execution Count Calculation

[Analysis]

i starts from<span><span>0</span></span>, increments by<span><span>3</span></span>, taking values<span><span>0</span></span>,<span><span>3</span></span>,<span><span>6</span></span>,<span><span>9</span></span>, executed 4 times, not 3 times, this statement isincorrect.

Question 7: The C++ statement cout << (3,2) will output3 and 2 with a comma in between. ( )

[Answer] ×

[Knowledge Point] C++ Comma – (Expression Operation Rules)

[Analysis]

The comma expression takes the value of the last expression,<span><span>(3,2)</span></span> results in<span><span>2</span></span>, only outputting<span><span>2</span></span>, not<span><span>3 and 2</span></span>, this statement isincorrect.

Question 8: In the C++ code, studentName, student_name, and sStudentName are all valid variable names. ( )

[Answer] √

[Knowledge Point] C++ Variable Naming Rules (can only consist of letters, numbers, and underscores, cannot start with a number, case-sensitive)

[Analysis]

studentName (letter + camel case), student_name (letter + underscore) are valid.

Question 9: In C++, for the floating-point variable float f, the statement cin >> f; cout << (f<1); when the input is 2e-1, the output is 0. ( )

[Answer]×

[Knowledge Point] C++ Floating Point Variable Input, Relational Operation (<span><span>f<1</span></span>) Result

[Analysis]

Input<span><span>2e-1</span></span> represents<span><span>0.2</span></span>,<span><span>float f = 0.2</span></span>,<span><span>f<1</span></span> results in<span><span>true</span></span> (in C++ represented as<span><span>1</span></span>), thus outputting<span><span>1</span></span> instead of<span><span>0</span></span>, this statement isincorrect.

Question 10: Inside the loop body of C++, if break and continue statements are consecutive, then their effects cancel each other out, allowing the next loop to execute smoothly. ( )

[Answer] ×

[Knowledge Point] C++ break and continue Mechanism

[Analysis]

break is used to terminate the loop, while continue is used to skip the subsequent statements of the current loop and enter the next loop, the two functions are completely different and cannot “cancel” each other. If<span><span>break</span></span> and<span><span>continue</span></span> appear consecutively,<span><span>break</span></span> will execute first and directly terminate the loop, this statement isincorrect.

3. Programming Questions (Each question is25 points, total50 points)

3.1 Programming Question 1: Temperature Conversion

. Time Limit: 1.0 s

. Memory Limit: 512.0 MB

3.1.1 Problem Description

Little Yang has recently learned about the conversion between Kelvin, Celsius, and Fahrenheit temperatures. Let K represent Kelvin temperature, C represent Celsius temperature, and F represent Fahrenheit temperature. The conversion formulas are as follows:

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

Now Little Yang wants to write a program to calculate the Celsius and Fahrenheit temperatures corresponding to a certain Kelvin temperature. Can you help him?

3.1.2 Input Format

One line, a real number K, representing the Kelvin temperature.

3.1.3 Output Format

One line, if the corresponding Fahrenheit temperature of the input Kelvin temperature is higher than 212, output Temperature is too high! ;

Otherwise, output two real numbers separated by a space C and F, representing Celsius and Fahrenheit temperatures, keeping two decimal places.

3.1.4 Sample

3.1.5 Input Sample 1

412.00

3.1.6 Output Sample 1

Temperature is too high!

3.1.7 Input Sample 2

173.56

3.1.8 Output Sample 2

-99.59 -147.26

3.1.9 Data Range

0 < K < 105

[Knowledge Point]

Data Type: float/double (to store real number temperatures, ensuring precision).

Arithmetic Operations: Temperature conversion formulas (Kelvin to Celsius, Celsius to Fahrenheit) numerical calculations.

Conditional Judgment: if-else branching structure (to judge whether the Fahrenheit temperature exceeds the limit).

Input and Output: scanf (to read real number input), printf (to format output, keeping two decimal places)

[Solution Idea]

1. Define variables: use double type to store Kelvin temperature (K), Celsius temperature (C), and Fahrenheit temperature (F) to avoid precision loss.

2. Read input: read the user-input Kelvin temperature K using scanf.

Temperature conversion:

Celsius temperature formula: C = K – 273.15 (Kelvin to Celsius).

Fahrenheit temperature formula: F = C * 1.8 + 32 (Celsius to Fahrenheit).

3. Conditional judgment and output:

If F > 212, output the prompt message Temperature is too high!.

Otherwise, use printf’s formatted output (%.2f) to keep two decimal places, output C and F.

[Reference Program]

#include &lt;stdio.h&gt;int main() {    double K, C, F; // Use double type to ensure temperature precision    // Read the input Kelvin temperature    scanf("%lf", &amp;K); // %lf is the input format specifier for double
    // Temperature conversion calculation    C = K - 273.15;   // Kelvin to Celsius    F = C * 1.8 + 32; // Celsius to Fahrenheit
    // Conditional judgment and output    if (F &gt; 212) {        printf("Temperature is too high!\n");    } else {        // %.2f indicates output floating-point numbers keeping two decimal places        printf("%.2f %.2f\n", C, F);    }
    return 0;}

[Note] 1.Header File: <span><span>#include</span><span> <stdio.h></span></span> is the standard input-output header file in C language, must be included to use <span><span>scanf</span></span> and <span><span>printf</span></span><span><span>2.</span></span><strong><span><span>Formatted Output</span></span></strong><span><span><span>: </span></span></span><code><span><span>printf("%.2f %.2f\n", C, F)</span></span> in which, <span><span>%.2f</span></span> forces the output to keep two decimal places, ensuring the result format meets the requirements; if the temperature exceeds the limit, the specified prompt string is output.

3.2 Programming Question 2: Odd and Even Numbers

. Time Limit: 1.0 s

. Memory Limit: 512.0 MB

3.2.1 Problem Description

Little Yang has n positive integers, and he wants to know how many of them are odd and how many are even.

3.2.2 Input Format

The first line contains a positive integer n , representing the number of positive integers.

After that, n lines, each containing a positive integer.

3.2.3 Output Format

Output two positive integers (separated by a space in English), representing the count of odd and even numbers. If the count of odd or even numbers is0 , then output0.

3.2.4 Sample

Analysis of the GESP C++ Level 1 Exam Questions for December 2024

For all data, it is guaranteed that 1 n 105 and the positive integers do not exceed 105.

[Knowledge Point]

1. Loop Structure: for loop (to traverse the specified number of input numbers).

2. Conditional Judgment: if-else branching (to determine the odd/even nature of the number using modulus %).

3. Input and Output: cin reads integer input, cout outputs the statistical results.

4. Variable Initialization and Accumulation: initialization and increment operations of counter variables (odd counts odd numbers, even counts even numbers)

<span><p><span><span><span>[Solution Idea]</span></span></span></p><p><span><span>1. Define variables:</span></span></p><p><span><span>n: to store the number of positive integers to be input.</span></span></p><p><span><span>num: to temporarily store each positive integer read.</span></span></p><p><span><span>odd and even: to count odd and even numbers, initialized to 0 (to avoid random values affecting statistics).</span></span></p><p><span><span>2. Read the number of inputs: read n using cin to determine the total number of numbers to be processed.</span></span></p><p><span><span>3. Loop to process each number:</span></span></p><p><span><span>Use a for loop to execute n times, reading a positive integer num each time.</span></span></p><p><span><span>Use num % 2 == 1 to determine if it is an odd number (the result of odd numbers modulo 2 is 1), if so, increment odd; otherwise, increment even.</span></span></p><p><span><span>4. Output results: after the loop ends, output the count of odd and even numbers using cout, separated by a space. [Reference Program]</span></span></p></span>

#include &lt;iostream&gt;using namespace std;int main() {    int n;          // Store the number of positive integers to be input    int num;        // Temporarily store each positive integer read    int odd = 0;    // Odd number counter, initialized to 0    int even = 0;   // Even number counter, initialized to 0    // Read the number of input numbers n    cin &gt;&gt; n;    // Loop n times, read each number and determine odd/even nature    for (int i = 0; i &lt; n; ++i) {        cin &gt;&gt; num;          // Read the current number        if (num % 2 == 1) {  // Determine if it is an odd number (modulus 2 equals 1)            odd++;           // Increment odd number counter        } else {            even++;          // Increment even number counter        }    }    // Output statistical results (odd count space even count)    cout &lt;&lt; odd &lt;&lt; " " &lt;&lt; even &lt;&lt; endl;    return 0;}

Leave a Comment