Pearson Edexcel IGCSE · Computer Science

Constructs: แบบฝึกหัด

ข้อปรนัย 2 ข้อ ตรวจให้ทันทีที่ตอบ และข้อเขียน 4 ข้อ พร้อมวิธีทำละเอียด ทั้งหมดจากเรื่อง Constructs

6 ข้อ20 คะแนนฟรี ไม่ต้องสมัคร
ข้อ 1
1 คะแนน

Study the following pseudocode which involves variable scope:

\( \text{SET globalVar TO 10} \)
\( \text{FUNCTION calculate(n)} \)
  \( \text{SET localVar TO n * 2} \)
  \( \text{SET globalVar TO globalVar + 5} \)
  \( \text{RETURN localVar} \)
\( \text{ENDFUNCTION} \)

If the main program calls \( \text{calculate(4)} \) once, what will be the final value of globalVar and the returned result?

ข้อ 2
1 คะแนน

Consider the following pseudocode fragment:

\( \text{SET count TO 0} \)
\( \text{FOR r FROM 0 TO 2} \)
  \( \text{FOR c FROM 0 TO 1} \)
    \( \text{IF vals[r][c] > 10 THEN} \)
      \( \text{SET count TO count + 1} \)
    \( \text{END IF} \)
  \( \text{END FOR} \)
\( \text{END FOR} \)

The 2D array \( \text{vals} \) contains the following data:
Row 0: 12, 5
Row 1: 8, 15
Row 2: 20, 7

What will be the final value of the variable \( \text{count} \) after execution?

ข้อ 3
3 คะแนน

Explain the primary difference between a count-controlled iteration and a condition-controlled iteration.

ลองเขียนคำตอบด้วยตัวเองก่อน แล้วค่อยเทียบกับวิธีทำ

ข้อ 4
5 คะแนน

An algorithm uses a nested loop to calculate the sum of values in a 2D array. If the inner loop is defined as \( \text{FOR j FROM 0 TO 5} \) but the array rows only contain 4 elements (indices 0 to 3), identify the type of error that occurs and explain its impact on the program execution.

ลองเขียนคำตอบด้วยตัวเองก่อน แล้วค่อยเทียบกับวิธีทำ

ข้อ 5
4 คะแนน

Selection and iteration are fundamental programming constructs.
(a) Describe the difference between a count-controlled loop (FOR loop) and a condition-controlled loop (WHILE loop).
(b) Provide one specific programming scenario where a WHILE loop would be a more appropriate choice than a FOR loop.

ลองเขียนคำตอบด้วยตัวเองก่อน แล้วค่อยเทียบกับวิธีทำ

ข้อ 6
6 คะแนน

A programmer is writing a subprogram to calculate the discount on a customer order.
(a) Explain the difference between passing by value and passing by reference when providing arguments to a subprogram.
(b) Discuss the benefits of using local variables within this subprogram instead of using global variables to track calculation steps, referring to data security and memory management.

ลองเขียนคำตอบด้วยตัวเองก่อน แล้วค่อยเทียบกับวิธีทำ

* เนื้อหาของ thinka สร้างโดย AI อาจไม่ถูกต้องสมบูรณ์ในทุกกรณี กรุณาใช้เป็นสื่อเสริมและตรวจสอบกับเอกสารอ้างอิงอย่างเป็นทางการ

คุณเห็นเฉลยแล้ว ทีนี้มาตรวจคำตอบของคุณบ้าง

หน้านี้บอกได้ว่าคำตอบที่ดีเป็นอย่างไร แต่บอกไม่ได้ว่าคำตอบของคุณขาดอะไร thinka ตรวจข้อเขียนของคุณตามเกณฑ์ให้คะแนนจริงในราว 15 วินาที

อยากฝึกโจทย์แบบนี้เพิ่มไหม เริ่มฝึกหัวข้อนี้ได้เลย ตรวจให้ทันทีทุกข้อ

เริ่มฝึกเลย