Modular Programming and Algorithms I
Modular Programming and Algorithms I
1
The practice of modular programming and understanding of standard algorithms is
central to efficient coding and software development. This module introduces the
principles of modular programming and explores some of the standard algorithms
that are commonly used in the industry. From breaking down complex code to
understanding sorting techniques, this module is a step towards mastering the
building blocks of programming.
The material in this module relates to the following subject learning outcomes:
Student Expectations
During this module, you are expected to spend time working through the prescribed
material prior to attending class. This will enable a more valuable discussion to take
place in online tutorials or conferences, where you will be able to discuss concepts,
present ideas and explore information collaboratively in greater depth.
Accordingly, it is suggested that you allow:
4 hours for facilitated study. This includes guided facilitated study, watching or
attending course lectures (live or pre-recorded), responding to facilitator feedback.
8 hours for personal study. This includes reading through course material,
undertaking learning activities and exploring additional related resources.
Learner Guide
The Learner Guide provides the core knowledge for this topic. Work through the
materials and be prepared to discuss these in your forums, tutorials or classes.
Expand All
Panels
Collapse All
Panels
In the fast-paced
world of software development, efficiency and adaptability are key to meeting
ever-changing demands. Modular programming serves as a beacon in this regard,
promising streamlined processes and enhanced productivity.
● Separation of Concerns
This principle dictates that a program should be segmented into distinct
sections, with each handling a specific aspect of the functionality. This
separation ensures a cleaner, more organized code base which is easier
to maintain and upgrade.
● Reuse of Code
Modular programming encourages the development of reusable modules
that can find utility in various projects, promoting efficiency and reducing
the overall development time.
● Ease of Maintenance: One of the standout benefits of this approach is
the ease with which modules can be updated, added, or removed
individually, without affecting other parts of the program. This makes
maintenance less cumbersome and time-consuming.
● Increased Reliability
By isolating errors to individual modules, it becomes considerably easier to
identify and rectify issues, thereby enhancing the reliability of the software.
Benefits
● Parallel Development
Different teams can work on separate modules simultaneously, which can
significantly speed up the development process.
● Improved Testing
Each module can be tested individually, thereby ensuring higher reliability
and stability of the system.
Challenges
● Integration Issues
Although modules are developed independently, integrating them can
sometimes pose challenges, especially if the modules are developed by
different teams.
● Complexity
As programs grow in size and complexity, managing numerous modules
requires careful planning and coordination to prevent potential issues and
maintain coherence.
Section 2: Functions
A function is a group of statements with a name. We can only execute the group of
statements by using the name of the function. Every C++ program has at least one
function, which is main().
Creating a function
return statement;
}
Parts of a function
● return_type
is the data type of the value of the function returns. Some functions
perform the desired operations without returning a value. In this case, the
return_type is the keyword void.
● function_name
is the actual name of the function. The function name and the parameter
list together constitute the function signature.
● parameter_list
A parameter is like a placeholder. When a function is called, we pass a
value to the parameter. This value is referred to as the actual parameter.
The parameter list refers to the type, order and number of parameters of a
function. Parameters are optional.
● body
The function body is between the curly braces {}, and contains the
statements executed by the function.
● The return statement terminates the current function and returns the value
of the function to its caller.
Function declaration
A minimal function declaration consists of the return type, function name and the
parameter list. For example:
● The return type, which specifies the type of the value that the function
returns, or void if no value is returned.
● The function name, which must begin with a letter or underscore and
cannot contain spaces.
● The parameter list, a local name by which the values may be accessed
inside the function.
Function parameters
Parameters act as local variables inside the function and are specified after the
function name, inside the parentheses.
The void keyword, used in the examples before, indicates that the function should
not return a value. If we want the function to return a value, we can use a data type
(such as int, float, char, etc...) instead of void, and use the return keyword inside the
function.
Example 1
void main() {
int myAge = 23;
printAge(23);
}
Example 2
void main() {
int x = 10;
int y = 5;
add (x, y);
}
Background
Problem Statement
The existing software system at ABC Healthcare was monolithic and rigid, making it
difficult to implement new features and upgrades. The system was also prone to
errors, with issues in one part often affecting the entire system. ABC Healthcare
sought a robust and flexible solution that would overcome these challenges.
Implementation
Outcome
1. Understanding different sorting algorithms like bubble sort and quick sort
provides insights into computational efficiency and time complexity.
2. Standard algorithms solve common problems and are widely applicable in
data science, machine learning, and general software development.
3. Comparing the performance of different algorithms is crucial for choosing the
most efficient solution for a given problem.
Learner Guide
The Learner Guide provides the core knowledge for this topic. Work through the
materials and be prepared to discuss these in your forums, tutorials or classes.
Expand All
Panels
Collapse All
Panels
Their power lies in several features such as optimised resource utilisation, reducing
complexity, offering predictability and consistency, and showcasing adaptability and
scalability.
As we delve deeper into this module, we will illuminate two vital components of
standard algorithms: space complexity and sorting algorithms.
These foundational elements not only enhance your understanding but also equip
you to craft robust and proficient systems in the future.
Space Complexity
Sorting Algorithms
The company noticed a rising trend in delayed deliveries and identified that the
primary cause was the disorganised product retrieval process within the warehouse.
This led to the decision to optimise the warehouse operations using suitable
standard algorithms.
Objective
● Application: Used for sorting less frequently bought items where the data
set is relatively small.
● Benefit: Simplicity and ease of implementation.
Moreover, to further optimise the space utilisation in the warehouse, the team
analysed the space complexity of various processes and implemented strategies to
minimise memory usage in the warehouse management system.
Outcome
Post-implementation, the warehouse witnessed a substantial reduction in product
retrieval time, resulting in faster order processing and happier customers. The
meticulous sorting facilitated easy and quick access to products, optimising the
workflow and enhancing the overall efficiency of the warehouse.
Learner Guide
The Learner Guide provides the core knowledge for this topic. Work through the
materials and be prepared to discuss these in your forums, tutorials or classes.
Expand All
Panels
Collapse All
Panels
Understanding Pass-By-Reference
Example
void main() {
int x = 10;
int y = 5;
calculate(x, y);
Further Resources
The resources in this section are for further exploration, providing additional
information for deeper insights.
Expand All
Panels
Collapse All
Panels
Reading: Modular Programming
This resource explores modular programming, a method of designing software by
breaking down functions into independent modules. It emphasises grouping lines of
code into functions, which can be either for program control or specific tasks.
Modular Programming
Reference: Busbee K.L. & Braunschweig D 2024, Modular Programming, rebus Community (online
publication), accessed 18 January 2024,
<https://press.rebus.community/programmingfundamentals/chapter/modular-programming/>
Reference: Kenneth Leroy Busbee n.d., 'Modularization and C++ Program Layout', LibreTexts,
accessed 31 January 2024,
<https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundam
entals/Programming_Fundamentals_-_A_Modular_Structured_Approach_using_C_(Busbee)/02%3A_
Introduction_to_Programming/2.03%3A_Modularization_and_C_Program_Layout>