Modular Thinking: Easy Quiz on Functions and Procedures Quiz

  1. Choosing Between a Function and a Procedure

    In a simple calculator program, which module type should you use to compute and return the product of two numbers so it can be used inside another expression?

    1. Function
    2. Procedure
    3. Event handler
    4. Class
    5. Funtion
  2. Parameters vs. Arguments

    When calling a module greet('Ava') that was defined as a procedure greet(name), what is the correct term for the value 'Ava' supplied at call time?

    1. Argument
    2. Parameter
    3. Return value
    4. Local variable
    5. Parametre
  3. Reuse and Maintenance via Modules

    If a sales app puts its tax calculation in a single function computeTax(amount), what is the main benefit of this modular design for easy programs?

    1. It centralizes the logic so all code can reuse it and updates happen in one place.
    2. It guarantees the program will run twice as fast.
    3. It automatically encrypts all financial data.
    4. It eliminates the need for testing.
    5. It increases the number of global variables required.
  4. Identifying a Pure Function

    Which statement best describes a pure function in a module that squares a number, such as square(x) returning x*x?

    1. It returns the same result for the same input and does not change program state.
    2. It prints the result to the screen and updates a global counter.
    3. It may return different results for the same input if called at night.
    4. It stores the result in a file for later use.
    5. It requires pass-by-reference to work.
  5. Local Variable Scope in Modules

    Inside a function sum(a, b), a variable total is set to a + b but not returned; which statement about total is generally true in modular programs?

    1. It cannot be accessed directly from code outside the function.
    2. It becomes a global variable after the function finishes.
    3. It persists automatically across multiple runs of the program.
    4. It can be modified by callers even without being passed by reference.
    5. It is compiled into a public constant named TOTAL.