CSC311 - Structured Programming Exam Notes
Advantages of Structured Programming:
- Structured programming employs a top-down design model, breaking the overall program structure into separate subsections.
- Advantages (four needed):
- Improved code readability: Easier to understand and maintain.
- Enhanced modularity: Programs are divided into smaller, manageable modules.
- Increased reusability: Modules can be reused in different parts of the program or in other programs.
- Simplified debugging: Errors can be easily located and fixed within specific modules.
- Better code organization: Promotes a systematic approach to program development.
- Reduced complexity: Makes large programs easier to design and understand.
Demerits of Structured Programming:
- Demerits (three needed):
- Can be less efficient for certain types of problems compared to unstructured programming.
- May require more planning and design effort upfront.
- Can be less flexible in some cases, particularly when dealing with complex or rapidly changing requirements.
- Sometimes leads to longer code, especially when modularizing simple tasks.
Elements of Structured Programming:
- Elements (three needed):
- Sequence: Statements are executed in a specific order.
- Selection: Control flow based on conditions (e.g., if-else statements).
- Iteration: Repetition of code blocks (e.g., loops).
- Functions/Subroutines: Reusable blocks of code.
Subprograms in Structured Programming:
Subprograms are programs inside a larger main program, reusable any number of times.
Types of Subprograms (two needed):
- Functions: Return a value after execution.
- Procedures (or Subroutines): Do not necessarily return a value; perform a specific task.
Discussion of Subprograms:
- Functions: Designed to perform a specific calculation or operation and return a result. They promote code reusability and modularity. For example, a function to calculate the square root of a number:
- Procedures: Execute a series of statements to accomplish a task. They may modify data or interact with the environment. An example would be a procedure to print a report.
Design Principles of Structured Programming:
Main principle: Linearize control flow so execution follows the code sequence.
Types of Design Principles (four needed):
- Top-down design:
- Modular design:
- Data abstraction:
- Information hiding:
Discussion of Design Principles (two needed):
- Top-down design: Breaking down a complex problem into smaller, more manageable subproblems.
- Modular design: Dividing a program into independent modules, each performing a specific task.
Black Box Principle:
- Information Hiding (or Abstraction): Allows subsystems to be seen as black boxes with understood tasks but invisible details.
Abstraction in Structured Programming:
- Abstraction hides irrelevant codes to reduce complexity and increase efficiency.
- Types of Abstraction:
- Hardware Abstraction: Allows programmers to understand the code and communicate with the hardware. This involves working with higher-level languages and libraries that abstract away the complexities of the underlying hardware.
- Control Abstraction: Allows a programmer to create new control constructs, which are statements in a program that define how the computer executes functions (e.g., creating a custom loop or conditional statement).
Stepwise Refinement:
Stepwise Refinement:
- A process of breaking down a complex problem into smaller, more manageable subproblems. This continues until the subproblems are simple enough to be easily implemented.
- Involves repeatedly refining the solution by adding more detail at each step.
Disadvantages of Stepwise Refinement (three needed):
- Can be time-consuming.
- May lead to a less efficient solution if not done carefully.
- Can be difficult to apply to problems that are not well-defined.
Merits of Modular Programming (three needed):
- Improved code reusability.
- Simplified debugging and maintenance.
- Increased code organization and readability.
- Facilitates team development by allowing different programmers to work on different modules concurrently.
Top-Down Design Approach:
- Top-down design involves starting with the overall problem and breaking it down into smaller, more manageable subproblems. Each subproblem is then further refined until it can be easily implemented.
Design Approach Without Modularity:
- Monolithic design: A software application designed without modularity. It's a single, large block of code that is difficult to understand, maintain, and reuse.