Modular Design CS Thinking Example 1

Follow the full solution, then compare it with the other examples linked below.

Example 1

easy
A student writes a 200-line program as one big block of code. Suggest how they could improve it using modular design.

Solution

  1. 1
    Step 1: Identify distinct tasks in the program (e.g., reading input, processing data, displaying results).
  2. 2
    Step 2: Break each task into a separate function or module with a clear name (e.g., readData(), calculateAverage(), displayResults()).
  3. 3
    Step 3: The main program calls these modules in sequence. Each module can be developed, tested, and debugged independently.

Answer

Break the program into separate functions for each task. Each function handles one responsibility and can be tested independently.
Modular design divides a program into self-contained, reusable components. This makes code easier to read, test, debug, and maintain โ€” especially important as programs grow larger.

About Modular Design

Modular design is the practice of structuring a program as a set of independent, self-contained modules, each responsible for a single, well-defined task. Modules communicate through clear interfaces, making the system easier to build, test, debug, and maintain.

Learn more about Modular Design โ†’

More Modular Design Examples