SlideShare a Scribd company logo
1 of 20
LOGO
11
MODULAR PROGRAMMINGMODULAR PROGRAMMING
Submitted to: Submitted by:Submitted to: Submitted by:
Mrs. Priyanka Soni Krati KatyalMrs. Priyanka Soni Krati Katyal
MCA 1MCA 1stst
SemSem
Topics Covered
• Modular Programing
• Need of Modular Programming
• Why Modular Programming??
• Modularity
• Elements of Modular Programming
• Modular Programming Example
• Advantages of Modular Programming
• Disadvantages of Modular Programming
• Reference
Modular ProgrammingModular Programming
Modular programmingModular programming is a software designis a software design
technique that emphasizes separating thetechnique that emphasizes separating the
functionality of afunctionality of a programprogram into independent,into independent,
interchangeable modules, such that each containsinterchangeable modules, such that each contains
everything necessary to execute only one aspect ofeverything necessary to execute only one aspect of
the desired functionality.the desired functionality.
Need for Modular ProgrammingNeed for Modular Programming
• When a program becomes very large andWhen a program becomes very large and
complex, it becomes very difficult task for thecomplex, it becomes very difficult task for the
programmers to design, test and debug such aprogrammers to design, test and debug such a
program.program.
• Therefore a long program can be divided into aTherefore a long program can be divided into a
smaller program called modules as the modulessmaller program called modules as the modules
can be designed, tested and debugged separately,can be designed, tested and debugged separately,
the task of programmer becomes easy andthe task of programmer becomes easy and
convenient.convenient.
• It makes your program easy to understand.It makes your program easy to understand.
• Helps manage complexityHelps manage complexity
o Smaller blocks of codeSmaller blocks of code
o Easier to readEasier to read
• Encourages re-use of codeEncourages re-use of code
Within a particular program or acrossWithin a particular program or across
different programsdifferent programs
• Allows independent development of codeAllows independent development of code
Why Modular Programming??Why Modular Programming??
ModularityModularity
• How do you solve a big/complexHow do you solve a big/complex
problem?problem?
• Divide it into small tasks and solve eachDivide it into small tasks and solve each
task. Then combine these solutions.task. Then combine these solutions.
Divide and ConquerDivide and Conquer
• In C we useIn C we use functionsfunctions also referred to asalso referred to as
modulesmodules to perform specific tasks that weto perform specific tasks that we
determined in our solutiondetermined in our solution
• This strategy is essentially based on theThis strategy is essentially based on the
divide-and-conquer approach to problemdivide-and-conquer approach to problem
solving and has many advantages oversolving and has many advantages over
developing a program for the entire problem.developing a program for the entire problem.
• We will assign a name to each module andWe will assign a name to each module and
combine the named modules in a programcombine the named modules in a program
structure under the control of a mainstructure under the control of a main
program.program.
• Such a program structure consists of aSuch a program structure consists of a
set of modules and an order ofset of modules and an order of
execution.execution.
Elements of Modular ProgrammingElements of Modular Programming
• C requires that function names be unique in aC requires that function names be unique in a
source program file.source program file.
• Program execution always begins and eventuallyProgram execution always begins and eventually
terminates in the main function.terminates in the main function.
• Additional functions are called or invoked whenAdditional functions are called or invoked when
the program encounters function namesthe program encounters function names
• Functions could beFunctions could be
Pre-defined library functions (e.g., printf, sin, tan)Pre-defined library functions (e.g., printf, sin, tan)
oror
Programmer-defined functions (e.g., my_printf,Programmer-defined functions (e.g., my_printf,
area)area)
• FunctionsFunctions Perform a specific taskPerform a specific task
 Arguments with no return typeArguments with no return type
void fun(int x, int y)void fun(int x, int y)
{{
//statement//statement
}}
 Arguments with return typeArguments with return type
int fun(int x, int y)int fun(int x, int y)
{{
//statement//statement
return 0;return 0;
}}
 No arguments with no return typeNo arguments with no return type
void fun( )void fun( )
{{
//statement//statement
}}
 No Arguments with return typeNo Arguments with return type
int fun( )int fun( )
{{
//statement//statement
return 0;return 0;
}}
These functions require three elements:These functions require three elements:
1.1.Function declaration: In this only theFunction declaration: In this only the
name and the syntax of the function willname and the syntax of the function will
written.written.
2.2. Function calls: In this program will callFunction calls: In this program will call
the functionthe function
3. Function definition: In this program3. Function definition: In this program
will defines that how the function willwill defines that how the function will
perform there task.perform there task.
A function definition consists ofA function definition consists of
1. A function type1. A function type
2. A function name2. A function name
3. An optional list of formal parameters enclosed in3. An optional list of formal parameters enclosed in
parenthesesparentheses
4. A compound statement.4. A compound statement.
Ex : Void start(int a)Ex : Void start(int a)
{{
…….statement…...statement…..
}}
#include <stdio.h>#include <stdio.h>
int max(int num1, int num2);int max(int num1, int num2);
int main ()int main ()
{{
int a = 100;int a = 100;
int b = 200;int b = 200;
int ret;int ret;
ret = max(a, b);ret = max(a, b);
printf( "Max value is : %dn", ret );printf( "Max value is : %dn", ret );
Modular Programming ExampleModular Programming Example
return 0;return 0;
}}
int max(int num1, int num2)int max(int num1, int num2)
{{
int result;int result;
if (num1 > num2)if (num1 > num2)
result = num1;result = num1;
elseelse
result = num2;result = num2;
return result;return result;
}}
OutputOutput
Max value is : 200Max value is : 200
Advantages of using modulesAdvantages of using modules
• Modules can be written and testedModules can be written and tested
separatelyseparately
• Modules can be reusedModules can be reused
• Large projects can be developed inLarge projects can be developed in
parallelparallel
• Reduces length of program, making itReduces length of program, making it
more readablemore readable
• Promotes the concept ofPromotes the concept of abstractionabstraction
 A module hides details of a taskA module hides details of a task
 We just need to know what this moduleWe just need to know what this module
doesdoes
 We don’t need to know how it does itWe don’t need to know how it does it
Disadvantages of using modulesDisadvantages of using modules
• means documentation of modules must bemeans documentation of modules must be
systematicsystematic
• can lead to problems when modules are linkedcan lead to problems when modules are linked
because link must thoroughly testedbecause link must thoroughly tested
• Since separate modules map repeat certainSince separate modules map repeat certain
functions, the modular programming oftenfunctions, the modular programming often
need extra time and memory.need extra time and memory.
ReferenceReference
www.google.comwww.google.com
www.encyclopedia.comwww.encyclopedia.com
www.wikipedia.comwww.wikipedia.com
www.ctutorial.comwww.ctutorial.com
Thank You
MLSU
UNIVERSITY

More Related Content

What's hot (20)

Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Array in c++
Array in c++Array in c++
Array in c++
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
String functions in C
String functions in CString functions in C
String functions in C
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Call by value
Call by valueCall by value
Call by value
 
Data types
Data typesData types
Data types
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
SPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in CSPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Array in c
Array in cArray in c
Array in c
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Python Modules
Python ModulesPython Modules
Python Modules
 

Viewers also liked (6)

Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Risc & cisk
Risc & ciskRisc & cisk
Risc & cisk
 
And or graph problem reduction using predicate logic
And or graph problem reduction using predicate logicAnd or graph problem reduction using predicate logic
And or graph problem reduction using predicate logic
 
Protection
ProtectionProtection
Protection
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 

Similar to Modular programming

Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptxmiki304759
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programmingDhaval Dalal
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsRuth Marvin
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdfsantosh147365
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)geetika goyal
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxurvashipundir04
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in CHarendra Singh
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural ProgrammingDeepam Aggarwal
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSDr.YNM
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)Dr. Ahmed Al Zaidy
 

Similar to Modular programming (20)

Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
Functions
FunctionsFunctions
Functions
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Python training
Python trainingPython training
Python training
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 
Functions
FunctionsFunctions
Functions
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
ProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPSProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPS
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)
 

Recently uploaded

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 

Recently uploaded (20)

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 

Modular programming

  • 1. LOGO 11 MODULAR PROGRAMMINGMODULAR PROGRAMMING Submitted to: Submitted by:Submitted to: Submitted by: Mrs. Priyanka Soni Krati KatyalMrs. Priyanka Soni Krati Katyal MCA 1MCA 1stst SemSem
  • 2. Topics Covered • Modular Programing • Need of Modular Programming • Why Modular Programming?? • Modularity • Elements of Modular Programming • Modular Programming Example • Advantages of Modular Programming • Disadvantages of Modular Programming • Reference
  • 3. Modular ProgrammingModular Programming Modular programmingModular programming is a software designis a software design technique that emphasizes separating thetechnique that emphasizes separating the functionality of afunctionality of a programprogram into independent,into independent, interchangeable modules, such that each containsinterchangeable modules, such that each contains everything necessary to execute only one aspect ofeverything necessary to execute only one aspect of the desired functionality.the desired functionality.
  • 4. Need for Modular ProgrammingNeed for Modular Programming • When a program becomes very large andWhen a program becomes very large and complex, it becomes very difficult task for thecomplex, it becomes very difficult task for the programmers to design, test and debug such aprogrammers to design, test and debug such a program.program. • Therefore a long program can be divided into aTherefore a long program can be divided into a smaller program called modules as the modulessmaller program called modules as the modules can be designed, tested and debugged separately,can be designed, tested and debugged separately, the task of programmer becomes easy andthe task of programmer becomes easy and convenient.convenient. • It makes your program easy to understand.It makes your program easy to understand.
  • 5. • Helps manage complexityHelps manage complexity o Smaller blocks of codeSmaller blocks of code o Easier to readEasier to read • Encourages re-use of codeEncourages re-use of code Within a particular program or acrossWithin a particular program or across different programsdifferent programs • Allows independent development of codeAllows independent development of code Why Modular Programming??Why Modular Programming??
  • 6. ModularityModularity • How do you solve a big/complexHow do you solve a big/complex problem?problem? • Divide it into small tasks and solve eachDivide it into small tasks and solve each task. Then combine these solutions.task. Then combine these solutions. Divide and ConquerDivide and Conquer
  • 7. • In C we useIn C we use functionsfunctions also referred to asalso referred to as modulesmodules to perform specific tasks that weto perform specific tasks that we determined in our solutiondetermined in our solution • This strategy is essentially based on theThis strategy is essentially based on the divide-and-conquer approach to problemdivide-and-conquer approach to problem solving and has many advantages oversolving and has many advantages over developing a program for the entire problem.developing a program for the entire problem. • We will assign a name to each module andWe will assign a name to each module and combine the named modules in a programcombine the named modules in a program structure under the control of a mainstructure under the control of a main program.program.
  • 8. • Such a program structure consists of aSuch a program structure consists of a set of modules and an order ofset of modules and an order of execution.execution.
  • 9. Elements of Modular ProgrammingElements of Modular Programming • C requires that function names be unique in aC requires that function names be unique in a source program file.source program file. • Program execution always begins and eventuallyProgram execution always begins and eventually terminates in the main function.terminates in the main function. • Additional functions are called or invoked whenAdditional functions are called or invoked when the program encounters function namesthe program encounters function names • Functions could beFunctions could be Pre-defined library functions (e.g., printf, sin, tan)Pre-defined library functions (e.g., printf, sin, tan) oror Programmer-defined functions (e.g., my_printf,Programmer-defined functions (e.g., my_printf, area)area)
  • 10. • FunctionsFunctions Perform a specific taskPerform a specific task  Arguments with no return typeArguments with no return type void fun(int x, int y)void fun(int x, int y) {{ //statement//statement }}  Arguments with return typeArguments with return type int fun(int x, int y)int fun(int x, int y) {{ //statement//statement return 0;return 0; }}
  • 11.  No arguments with no return typeNo arguments with no return type void fun( )void fun( ) {{ //statement//statement }}  No Arguments with return typeNo Arguments with return type int fun( )int fun( ) {{ //statement//statement return 0;return 0; }}
  • 12. These functions require three elements:These functions require three elements: 1.1.Function declaration: In this only theFunction declaration: In this only the name and the syntax of the function willname and the syntax of the function will written.written. 2.2. Function calls: In this program will callFunction calls: In this program will call the functionthe function 3. Function definition: In this program3. Function definition: In this program will defines that how the function willwill defines that how the function will perform there task.perform there task.
  • 13. A function definition consists ofA function definition consists of 1. A function type1. A function type 2. A function name2. A function name 3. An optional list of formal parameters enclosed in3. An optional list of formal parameters enclosed in parenthesesparentheses 4. A compound statement.4. A compound statement. Ex : Void start(int a)Ex : Void start(int a) {{ …….statement…...statement….. }}
  • 14. #include <stdio.h>#include <stdio.h> int max(int num1, int num2);int max(int num1, int num2); int main ()int main () {{ int a = 100;int a = 100; int b = 200;int b = 200; int ret;int ret; ret = max(a, b);ret = max(a, b); printf( "Max value is : %dn", ret );printf( "Max value is : %dn", ret ); Modular Programming ExampleModular Programming Example
  • 15. return 0;return 0; }} int max(int num1, int num2)int max(int num1, int num2) {{ int result;int result; if (num1 > num2)if (num1 > num2) result = num1;result = num1; elseelse result = num2;result = num2; return result;return result; }}
  • 16. OutputOutput Max value is : 200Max value is : 200
  • 17. Advantages of using modulesAdvantages of using modules • Modules can be written and testedModules can be written and tested separatelyseparately • Modules can be reusedModules can be reused • Large projects can be developed inLarge projects can be developed in parallelparallel • Reduces length of program, making itReduces length of program, making it more readablemore readable • Promotes the concept ofPromotes the concept of abstractionabstraction  A module hides details of a taskA module hides details of a task  We just need to know what this moduleWe just need to know what this module doesdoes  We don’t need to know how it does itWe don’t need to know how it does it
  • 18. Disadvantages of using modulesDisadvantages of using modules • means documentation of modules must bemeans documentation of modules must be systematicsystematic • can lead to problems when modules are linkedcan lead to problems when modules are linked because link must thoroughly testedbecause link must thoroughly tested • Since separate modules map repeat certainSince separate modules map repeat certain functions, the modular programming oftenfunctions, the modular programming often need extra time and memory.need extra time and memory.