SP Topic 2 - Prog DVLPMNT & Design
SP Topic 2 - Prog DVLPMNT & Design
In top-down design, the design process starts with the high-level or broad view of the problem. The
main task is to identify the major functionalities or modules required to solve the problem. These
major modules are then further divided into sub-modules, and this decomposition continues until the
lowest level of detail is reached.
The key steps involved in the top-down design process are as follows:
a. Problem Analysis: The first step is to understand and analyze the problem or system
requirements. This involves gathering information about the problem domain, identifying the
major functionalities, and determining the inputs, outputs, and processing requirements.
b. Identify Main Modules: Based on the problem analysis, the main modules or components
that are required to solve the problem are identified. These modules represent the major steps
or tasks involved in solving the problem.
c. Decomposition: Each main module is further decomposed into smaller sub-modules. The
decomposition is done by identifying the tasks or operations that need to be performed within
each module. This process continues until the modules are small enough to be easily
implemented.
d. Define Interfaces: Interfaces between the modules are defined, specifying how they will
communicate and interact with each other. This includes identifying the data inputs and
outputs for each module and defining the parameters and return values of functions or
procedures.
2. Bottom-up design
This involves building a system or program from its individual components or modules. Unlike top-down
design, which starts with a high-level view and breaks the problem down into smaller parts, bottom-up
design begins with the smallest components and gradually assembles them into larger modules and
eventually the complete system.
In bottom-up design, the focus is on developing the individual building blocks first, and then combining
them to create more complex modules and eventually the entire system. This approach allows for greater
attention to detail at the lower levels and ensures that each component is functioning correctly before
integration.
The key steps involved in the bottom-up design process are as follows:
a. Identify Basic Components: The first step is to identify the basic components or modules required
to solve the problem. These components are usually the smallest and simplest parts of the system.
b. Implement Basic Components: Each basic component is implemented independently, focusing on
its functionality and correctness. This involves writing the code for each component, testing it, and
ensuring that it performs the desired operations correctly.
c. Test and Verify Components: Once the basic components are implemented, they are individually
tested to ensure that they work as expected. This includes verifying their behavior, handling edge
cases, and confirming that they meet the requirements.
d. Assemble Components: After the individual components have been tested and verified, they are
combined to create larger modules. These modules are built by integrating the basic components and
defining the interfaces between them.
e. Test and Verify Modules: The assembled modules are then tested to ensure that they function
correctly and produce the desired results. Integration testing is performed to verify the interactions
between the modules and to identify any potential issues or errors.
f. Repeat the Process: The process of implementing, testing, and integrating components and modules
is repeated, gradually moving from smaller modules to larger ones, until the complete system is built.
Bottom-up design allows for a more incremental and iterative development approach. It ensures that each
component is thoroughly tested and validated before moving on to the next level of integration. This
approach also promotes code reusability, as the independently developed and tested components can be
easily reused in different systems or projects.
Overall, bottom-up design is a structured programming design concept that focuses on developing and
integrating smaller components to build larger modules and systems. It ensures attention to detail,
encourages code reusability, and facilitates a systematic and incremental approach to software development.
3. Modular design
Modular design is a key design concept in structured programming that emphasizes dividing a program into
self-contained modules or units. Each module represents a distinct functionality or task and can be
developed and tested independently. These modules interact with each other through well-defined interfaces,
providing a way to organize and manage complex systems efficiently.
Here are the main aspects of modular design in structured programming:
a. Encapsulation: Modules in structured programming encapsulate a set of related operations or data.
They provide a logical boundary around a specific functionality, allowing for information hiding and
reducing the complexity of the overall system. Encapsulation ensures that the internal details of a
module are hidden from other modules, providing abstraction and making the system more
maintainable.
b. Cohesion: Modules should exhibit high cohesion, which means that the operations within a module
are closely related and focused on a single task. High cohesion promotes code clarity, reusability, and
maintainability. It allows modules to be easily understood and modified without affecting other parts
of the program.
c. Low Coupling: Coupling refers to the degree of interdependence between modules. In modular
design, it is desirable to have low coupling, which means that modules are loosely connected and
have minimal reliance on each other. Low coupling enhances the modifiability and reusability of
modules, as changes in one module are less likely to affect other modules.
d. Interface Design: Modules interact with each other through well-defined interfaces. The interface
defines the inputs, outputs, and functionalities that are exposed to other modules. A clear and
standardized interface facilitates communication and integration between modules and allows for
easy replacement or modification of modules without affecting the entire system.
e. Abstraction: Modular design promotes abstraction by hiding unnecessary implementation details
and exposing only the essential functionalities and data structures. This allows programmers to work
with higher-level concepts and simplifies the understanding and use of modules.
f. Information Hiding: Modules should hide their internal details and only expose the necessary
information to other modules. Information hiding helps to minimize dependencies and maintain the
integrity of the module's implementation. It also allows for future modifications or enhancements to
be made within the module without impacting other parts of the program.
g. Reusability: Modules designed with a modular approach are typically reusable. They can be easily
integrated into different systems or projects, reducing development time and effort. Reusable
modules enhance productivity and code maintainability.
By employing modular design principles, structured programming promotes code organization, readability,
reusability, and maintainability. It allows developers to tackle complex problems by breaking them down
into manageable components that can be independently developed, tested, and modified. Modular design
facilitates collaboration among team members, as different modules can be developed in parallel, and the
system can be built by integrating the modules together.
4. Control flow structure
This governs the order in which program statements are executed. It provides the means to control the flow
of execution based on certain conditions or rules, enabling the program to make decisions and repeat or skip
certain blocks of code. The control flow structures in structured programming include sequence, selection,
and iteration.
a. Sequence: Sequence is the simplest control flow structure, representing the default flow of execution
where statements are executed in the order they appear. The program follows a linear path, executing
one statement after another until it reaches the end. Sequence ensures that statements are executed
sequentially, allowing the program to perform a series of actions or operations.
b. Selection: Selection structures, such as "if-else" statements and "switch" statements, enable the
program to make decisions based on certain conditions. These structures allow the program to
selectively execute different blocks of code depending on the outcome of a condition evaluation.
i. "if-else" statement: It evaluates a condition and executes a specific block of code if the condition
is true. If the condition is false, an alternative block of code can be executed using the "else"
clause.
ii. "switch" statement: It evaluates an expression or variable and matches it against multiple cases.
The corresponding case block is executed based on the matching value.
Selection structures enable the program to take different paths or perform different actions based on
conditions, providing flexibility and decision-making capabilities.
c. Iteration: Iteration, also known as looping, allows the program to repeat a block of code multiple
times until a certain condition is met. Iteration structures provide a way to automate repetitive tasks
and perform actions on collections of data.
i. "for" loop: It executes a block of code a predetermined number of times, based on a control
variable that increments or decrements with each iteration.
ii."while" loop: It repeatedly executes a block of code as long as a condition remains true. The
condition is evaluated before each iteration.
iii."Do-while" loop: It executes a block of code at least once and then repeatedly executes it as long
as a condition remains true. The condition is evaluated after each iteration.
Iteration structures allow the program to efficiently process large amounts of data, implement algorithms,
and solve problems that require repetitive computations.
By using control flow structures effectively, structured programming enhances code readability,
maintainability, and understandability. It enables programmers to express complex logic in a structured and
organized manner, leading to efficient and reliable software.
5. Monolithic design
This refers to the design approach where a program is structured as a single, large module or codebase. In a
monolithic design, the entire program logic is contained within a single file or unit, and there is no clear
separation of functionalities.
Key characteristics of monolithic design in structured programming are as follows:
i. Lack of Modularization: Monolithic design does not follow the modular design principles of
structured programming. Instead of dividing the program into smaller, self-contained modules, all the
code resides in a single unit. This can lead to a large and unwieldy codebase, making it challenging
to understand, maintain, and modify the program.
ii. Tight Coupling: In monolithic design, different parts of the program are often tightly coupled with
each other. This means that changes made to one section of the code can have unintended
consequences on other sections. The lack of well-defined interfaces and encapsulation makes it
difficult to isolate and modify specific functionalities without affecting the entire program.
iii. Limited Reusability: Due to the lack of modularization, code reusability is limited in monolithic
design. Modules cannot be easily extracted and reused in other projects or systems. This can result in
code duplication and reduced development efficiency, as developers have to rewrite similar
functionalities for different parts of the program.
iv. Code Clutter: The absence of modularization in monolithic design can lead to code clutter. With all
the code in a single unit, it becomes harder to navigate, understand, and debug the program. It can
also make it challenging to collaborate with other developers or work on different parts of the
program concurrently.
v. Maintenance Challenges: Monolithic designs can pose challenges when it comes to maintaining
and evolving the program over time. Modifications or enhancements to specific functionalities
require understanding and potentially modifying a large portion of the code. This increases the
likelihood of introducing errors and makes it difficult to ensure code correctness and stability.
While monolithic design was commonly used in early software development practices, it is generally
considered less desirable in modern software engineering. The lack of modularity and the challenges
associated with monolithic designs have led to the adoption of modular design principles.
PROGRAM DESIGN TOOLS
In structured programming, there are several design tools and techniques that help in the process of program
design. These tools assist in visualizing the structure, flow, and organization of the program. Here are some
commonly used program design tools in structured programming:
1. Pseudocode: Pseudocode is a high-level, informal programming language that describes the
program's logic using plain language or a simplified syntax. It allows developers to express the
program's algorithmic steps without getting into the specifics of a particular programming language.
Pseudocode helps in clarifying the program's design and facilitates communication between
developers and stakeholders.
2. Flowcharts: Flowcharts are graphical representations of the program's logic and control flow. They
use symbols and arrows to represent different program components, such as inputs, outputs,
processes, decisions, and loops. Flowcharts provide a visual representation of the program's flow,
making it easier to understand and analyze.
3. Structure Charts: Structure charts illustrate the modular structure of a program by visually
representing the relationships between modules or functions. They show the hierarchy and
interconnections among different program modules, along with the flow of control and data between
them. Structure charts help in organizing and planning the program's structure and identifying
dependencies and relationships between modules.
4. Hierarchy Charts: Hierarchy charts depict the hierarchical structure of a program by representing
the modules or functions as boxes and showing the relationships between them. They illustrate the
program's structure in terms of levels or layers, with the main program at the top and the sub-
modules below. Hierarchy charts provide a clear overview of the program's structure and
organization.
5. Data Flow Diagrams (DFD): DFDs represent the flow of data within a system or program. They
illustrate how data moves through different processes, inputs, outputs, and data stores. DFDs help in
understanding the data requirements of a program and identifying the relationships and
transformations that occur within the program.
6. Structure Tables: Structure tables provide a tabular representation of the program's structure and
control flow. They outline the modules, inputs, outputs, and relationships between modules in a
structured manner. Structure tables are useful for documenting and planning the program's structure
and ensuring that all necessary components are accounted for.
These program design tools assist in the visual representation, organization, and planning of structured
programs. They help programmers and software designers in communicating ideas, analyzing program logic,
and ensuring a clear and well-structured design before moving on to the implementation phase.
NB: Emphasis on pseudocodes and flowcharts – photocopied notes
ASSIGNMENT:
1. Differentiate between syntax and semantics of a programming language.
2. In athletics track events, medals are awarded to the first 3 athletes. Position 1 gets a gold medal,
Position 2 gets a silver medal, and Position 3 gets a bronze medal.
a. Write a pseudocode to represent that
b. Draw a flowchart to represent that