Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

Modular programming

Assigned by
Maam Asma Jamil Presented by
•Abida khan
•Shumaila gull
•Mehwish rahman
Topics covered
 Modular programming
 Why modular programming
 Modularity
 Advantages of modular programming
 Disadvantages of modular programming
 Elements and examples of modular programming
Modular programming
Modular programming is a software design
technique that emphasizes separating the
functionality of a program into independent,
interchangeable modules, such that each
contains everything necessary to execute only
one aspect of the desired functionality.
Need for modular programming
 When a program becomes very large and complex , it
becomes very difficult task for the programmer to
design , test and debug such a program.
 Therefore a large can be divided into a smaller program
called modules as the modules can be designed , tested
and debugged separately, the task of programmer
become easy and convenient.
 It makes your program easy to understand.
Modularity

• How do we solve a big/complex


problem?
• Divide it into small tasks and solve
each task. then combine these
solutions.
Modular programming or functions
There are two types of functions:
Library or built-in functions:
As
 Main function for execution of any program
 Math.h
User defined
 Float area()
 etc
Syntax of function

Every function require three elements:


1. Function declaration:
Return-datatype function-name (parameters)

2. Function call: in this we call the function:function-


name(paramerters)
3. function definition: this is actually body of function.
Example explaining modularity
Q. Write a program which return the area of ring?
Solution: as we know that
area of ring=area of outer circle-area of inner circle

Here the area of ring =


Yellow circle area,3.14*r1*r1
-
Area of blue circle,3.14*r2*r2
Using modules or function to write
program
 Here we need two time a program for area of circle
so we will write a function once and call it for as
many times as we need but here in case of area of
ring we will call it two times
Coding….
#include<iostream.h>
//function declaration
Double circlearea(double);
Void main()
{
Double r1;
Double r2;
Double ringarea;
Cout<<“please enter the outer radius value :”;
Cin>>r1;
Cout<<“plz enter value of inner radius :”;
Cin>>r2;
ringarea+circlearea(r1)_circlearea(r2); //function calling
Cout<<“area of cicle having inner radius”<<r2<<“and the outer radius”<<r1<<“is”<<ringarea;
}
Double circlearea(double radius) //function definition
{
Return(3.14*radius*radius);
}
Benefits of modular programming
 Less code has to be written.
 A single procedure can be developed for reuse, eliminating the
need to retype the code many time.
 Program can be design more easily because a small team deals
with only a small part of the entire code.
 Modular programmer allow many programmers to collaborate
on the same application.
Continue…..
 The code is stored across multiple files.
 Code is short , simple and easy to understand.
 The same code can be used in many applications.
 Errors can easily be identified , as they are localized
to a subroutine or function.
Disadvantages of using modules
o Means documentation of module must be systematic.
o Can lead to problems when modules are linked because link
must thoroughly tested.
o Since separate modules repeat certain functions, the modular
programming often need extra time and memory

You might also like