Free Practice Quiz Question List

04 — Program Construction and Problem Solving Online Quiz Questions

Use this free practice quiz with 20 questions to review 04 — Program Construction and Problem Solving, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: Testing and debugging are the same process.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Which approach best illustrates decomposition when designing a program to calculate an average?

  1. A

    Writing all code in one long function

  2. B

    Dividing a large problem into smaller tasks

  3. C

    Running the program repeatedly without changing it

  4. D

    Replacing valid inputs with default values

03
Fill in the blank
1 point

Complete the statement: During the average-calculation loop, the invariant is that total always equals .

04
Written response
1 point

What programming term describes a separately organized part of a program that can help code be reused and maintained?

05
Choose one
1 point

Which test input is specifically a boundary-case test for a function that accepts scores from 0 through 100?

  1. A

    A list containing ordinary middle-range scores

  2. B

    A list containing no scores when empty input is not allowed

  3. C

    A list containing the lowest and highest allowed scores

  4. D

    A list containing randomly chosen text values

06
True or false
1 point

True or false: Expected invalid user input should generally be handled with exceptions rather than assertions.

  1. A

    True

  2. B

    False

07
Choose all
1 point

Select all the benefits of modularity described in the material.

  1. A

    It limits the amount of code that must be understood at one time.

  2. B

    It allows individual components to be tested independently.

  3. C

    It requires the same calculation to be copied wherever it is used.

  4. D

    It localizes changes to the relevant component.

08
Written response
1 point

What is the exact arithmetic mean of the scores [20, 40, 60, 80]?

09
Fill in the blank
1 point

Complete the definition: A regression is .

10
Choose one
1 point

A function calculates an average by dividing the sum by len(scores) - 1 instead of len(scores). What kind of error is this?

  1. A

    Syntax error

  2. B

    Runtime error

  3. C

    Input-validation error

  4. D

    Logic error

11
Choose all
1 point

Select all actions that belong to the systematic debugging process described in the material.

  1. A

    Reproduce the problem with reliable failing inputs.

  2. B

    Reduce the problem to the smallest case that still fails.

  3. C

    Change many unrelated parts at the same time.

  4. D

    Run the full test suite after confirming the failing test is fixed.

12
Open ended
1 point

Explain what refactoring is and describe how testing supports a safe refactoring process. Include one example of a refactoring change.

13
Choose one
1 point

Which comment best follows the guidance that comments should explain why rather than merely repeat what the code does?

  1. A

    Add x to y

  2. B

    divide items by group size

  3. C

    Use integer division because the number of complete groups is required.

  4. D

    Set the variable

14
Choose one
1 point

A developer is designing a program that calculates examination-score averages. Which approach best applies decomposition?

  1. A

    Writing all program instructions in one long function

  2. B

    Dividing the problem into smaller tasks

  3. C

    Testing only the final program output

  4. D

    Replacing the algorithm with documentation

15
Choose one
1 point

A programmer wants a function that calculates an average to be easy to test and reuse. Which design best demonstrates high cohesion?

  1. A

    Combine calculation, printing, file access, and input validation in one function

  2. B

    Make every function depend directly on the internal variables of every other function

  3. C

    Separate average calculation from report printing

  4. D

    Copy the average calculation into each report-producing function

16
True or false
1 point

True or false: A sufficiently large collection of tests can prove that a program contains no possible errors.

  1. A

    True

  2. B

    False

17
Choose one
1 point

A program fails intermittently, and a developer has found an input that can reproduce the failure. What should the developer do next to make the cause easier to isolate?

  1. A

    Change many unrelated parts of the program at once

  2. B

    Reduce the problem to the smallest failing input or action sequence

  3. C

    Skip the failing test and run only unrelated tests

  4. D

    Document the correction before investigating the cause

18
Written response
1 point

A developer extracts a long block into a function and removes duplicated code while preserving the program's externally observable behavior. What is this practice called?

19
Choose one
1 point

A function receives user input that is expected to be invalid sometimes, such as text that cannot be converted to a number. Which error-handling approach is most appropriate?

  1. A

    Use an assertion as the normal mechanism for rejecting every invalid user input

  2. B

    Raise or handle a specific exception for the expected invalid input

  3. C

    Catch every possible exception with one broad handler and ignore it

  4. D

    Allow the invalid value to continue without reporting a problem

20
Written response
1 point

Using the arithmetic mean, what average does the score list [70, 80, 90] produce?