SlideShare a Scribd company logo
1 of 35
CSWD1001
Programming Methods
Modules
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
1
What we’ll Learn
• Defining and calling a module
• Passing arguments to module
• Hierarchy chart
• Pseudocode
• Flow chart
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
2
What is Module
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
3
A module
is a
group of statements that exist within a
program for the purpose of performing
a specific task
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
4
Benefits
using
Module
Simpler code
Code reuse
Better testing
Easier maintenance
Faster development
Easier facilitation of teamwork
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
5
How to Define Module
Module name()
statement
statement
etc
End Module
A header (starting point)
A body
End point
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
6
Example
Module main()
Display "I have a message for you."
Call showMessage()
Display "That's all, folks!"
End Module
To execute a module,
you call it
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
7
Another example
Module main()
Display "I have a message for you."
Call showMessage()
Display "That's all, folks!"
End Module
Module showMessage()
Display "Hello world"
End Module
The program begins executing at
the main module.
When the end of the main module
is reached, the program stops
executing.
The computer jumps to
the showMessage module and executes
the statements in its body.
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
8
Local vs Global Variables
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
9
Local Variable
Declared inside a module
Cannot be accessed by statements that are outside the module
Different modules can have local variables with the same
names
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
10
Example Local Variable
Module main()
Call getName()
Display "Hello"
End Module
Module getName()
Declare String name
Display "Enter your name"
Input name
End Module
Local variable
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
11
Global Variables
Is accessible to all the module
Declaration statement is outside of all module
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
12
Example Global Variable
Declare Integer number
Module main()
Display "Enter a number."
Input number
Call showNumber()
End Module
Module showNumber()
Display "The number you entered is ", number
End Module
Global variable
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
13
Passing Arguments to Modules
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
14
• An argument is any piece of data that is passed into a module when
the module is called
• If you want a module to receive arguments when it is
called, you must equip the module with one or more
parameter variables.
• A parameter is a variable that receives an argument that is
passed into a module.
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
15
Simple Example
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
16
Two Type of Passing Arguments
Value
• Only a copy of the argument’s
value is passed into the
parameter variable
• If the contents of the parameter
variable are changed inside the
module, it has no effect on the
argument in the calling part of
the program
Reference
• The argument is passed into a
special type of parameter known
as a reference variable.
• When a reference variable is
used as a parameter in a module,
it allows the module to modify
the argument in the calling part
of the program
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
17
Example Passing
Arguments by Value
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
18
Example Passing Arguments by References
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
19
Passing multiple arguments
• Most languages allow you to write modules that accept multiple
arguments.
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
20
Rules to Remember
when
Passing an Arguments
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
21
Argument and the receiving parameter variable be
of the same data type
If you try to pass different type, an error usually
occurs
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
22
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
23
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
24
Hierarchy Charts
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
25
Hierarchy Charts
show the
relationship between the modules
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
26
Flow of Hierarchy Charts
Main
Program
Module 1 Module 2 Module 3
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
27
Example Main Program
receiveOrder()
Confirm()
printCustomerData()
checkAvailability()
processOrder() billCustomer()
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
28
Flow Chart of Modules
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
29
Symbol
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
30
Flowchart Notation Meaning
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
31
Terminal / Terminator
• Marks the starting or
ending point of the
system
• Usually contains the
word “Start” or “End”
Action/Process
• Represent a single step
or and entire sub-
process within a larger
process
Document
• Printed document or
report
Data/Input/Output
• Information entering as
input
• Information display as
output
Decision
• System decision
Database
• Storage information
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
32
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
33
Summary
• Programmers break down programming problems into reasonable units called modules,
subroutines, procedures, functions, or methods.
• To execute a module, you call it from another program or module
• When you create a module, you include a header, a body, and a return statement.
• When a main program wants to use a module, it “calls” the module’s name
• Th e variables and constants declared in a module are usable only within the module; they
are local to the module. Global variables and constants are those that are known to the
entire program.
• You can use a hierarchy chart to illustrate modules’ relationships. A hierarchy chart tells
you which modules exist within a program and which modules call others.
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
34
End
18/9/2018
CSWD1001 @ Kwan Lee First City Unversity Malaysia
(FCUC)
35

More Related Content

Similar to 3 Modules

QQ and Advance query
QQ and Advance queryQQ and Advance query
QQ and Advance queryKai Liu
 
7 Input Validation
7 Input Validation7 Input Validation
7 Input ValidationKwan Lee
 
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Sparkhound Inc.
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfJosé Paumard
 
PHP modernization approach generating KDM models from PHP legacy code
PHP modernization approach generating KDM models from PHP legacy codePHP modernization approach generating KDM models from PHP legacy code
PHP modernization approach generating KDM models from PHP legacy codejournalBEEI
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous DeliveryMike McGarr
 
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...Modelon
 
Webinar: Best Practices for Migrating to Magnolia 5
Webinar: Best Practices for Migrating to Magnolia 5Webinar: Best Practices for Migrating to Magnolia 5
Webinar: Best Practices for Migrating to Magnolia 5Magnolia
 
Oracle RI ETL process overview.
Oracle RI ETL process overview.Oracle RI ETL process overview.
Oracle RI ETL process overview.Puneet Kala
 
Refactoring legacy code: step-by-step examples
Refactoring legacy code: step-by-step examplesRefactoring legacy code: step-by-step examples
Refactoring legacy code: step-by-step examplesEndava
 
ASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docx
ASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docxASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docx
ASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docxadkinspaige22
 
Project ADAS Designreview
Project ADAS DesignreviewProject ADAS Designreview
Project ADAS DesignreviewAli Sohi
 
H2O 3 REST API Overview
H2O 3 REST API OverviewH2O 3 REST API Overview
H2O 3 REST API OverviewSri Ambati
 
H2O 3 REST API Overview
H2O 3 REST API OverviewH2O 3 REST API Overview
H2O 3 REST API OverviewRaymond Peck
 
Open Services for Lifecycle Collaboration (OSLC)
Open Services for Lifecycle Collaboration (OSLC) Open Services for Lifecycle Collaboration (OSLC)
Open Services for Lifecycle Collaboration (OSLC) Axel Reichwein
 

Similar to 3 Modules (20)

QQ and Advance query
QQ and Advance queryQQ and Advance query
QQ and Advance query
 
7 Input Validation
7 Input Validation7 Input Validation
7 Input Validation
 
OODPunit1.pdf
OODPunit1.pdfOODPunit1.pdf
OODPunit1.pdf
 
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
 
8 Array
8 Array8 Array
8 Array
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
 
PHP modernization approach generating KDM models from PHP legacy code
PHP modernization approach generating KDM models from PHP legacy codePHP modernization approach generating KDM models from PHP legacy code
PHP modernization approach generating KDM models from PHP legacy code
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
 
Webinar: Best Practices for Migrating to Magnolia 5
Webinar: Best Practices for Migrating to Magnolia 5Webinar: Best Practices for Migrating to Magnolia 5
Webinar: Best Practices for Migrating to Magnolia 5
 
Modern android development
Modern android developmentModern android development
Modern android development
 
eccenca Eco System
eccenca Eco Systemeccenca Eco System
eccenca Eco System
 
Oracle RI ETL process overview.
Oracle RI ETL process overview.Oracle RI ETL process overview.
Oracle RI ETL process overview.
 
Refactoring legacy code: step-by-step examples
Refactoring legacy code: step-by-step examplesRefactoring legacy code: step-by-step examples
Refactoring legacy code: step-by-step examples
 
COCOMO
COCOMOCOCOMO
COCOMO
 
ASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docx
ASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docxASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docx
ASSIGNMENT 1Fnu MohammadL20495160BUSINESS MODEL 2Fo.docx
 
Project ADAS Designreview
Project ADAS DesignreviewProject ADAS Designreview
Project ADAS Designreview
 
H2O 3 REST API Overview
H2O 3 REST API OverviewH2O 3 REST API Overview
H2O 3 REST API Overview
 
H2O 3 REST API Overview
H2O 3 REST API OverviewH2O 3 REST API Overview
H2O 3 REST API Overview
 
Open Services for Lifecycle Collaboration (OSLC)
Open Services for Lifecycle Collaboration (OSLC) Open Services for Lifecycle Collaboration (OSLC)
Open Services for Lifecycle Collaboration (OSLC)
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...Krashi Coaching
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Denish Jangid
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomSean M. Fox
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxNehaChandwani11
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17Celine George
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45MysoreMuleSoftMeetup
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 

Recently uploaded (20)

Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 

3 Modules

  • 1. CSWD1001 Programming Methods Modules 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 1
  • 2. What we’ll Learn • Defining and calling a module • Passing arguments to module • Hierarchy chart • Pseudocode • Flow chart 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 2
  • 3. What is Module 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 3
  • 4. A module is a group of statements that exist within a program for the purpose of performing a specific task 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 4
  • 5. Benefits using Module Simpler code Code reuse Better testing Easier maintenance Faster development Easier facilitation of teamwork 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 5
  • 6. How to Define Module Module name() statement statement etc End Module A header (starting point) A body End point 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 6
  • 7. Example Module main() Display "I have a message for you." Call showMessage() Display "That's all, folks!" End Module To execute a module, you call it 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 7
  • 8. Another example Module main() Display "I have a message for you." Call showMessage() Display "That's all, folks!" End Module Module showMessage() Display "Hello world" End Module The program begins executing at the main module. When the end of the main module is reached, the program stops executing. The computer jumps to the showMessage module and executes the statements in its body. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 8
  • 9. Local vs Global Variables 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 9
  • 10. Local Variable Declared inside a module Cannot be accessed by statements that are outside the module Different modules can have local variables with the same names 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 10
  • 11. Example Local Variable Module main() Call getName() Display "Hello" End Module Module getName() Declare String name Display "Enter your name" Input name End Module Local variable 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 11
  • 12. Global Variables Is accessible to all the module Declaration statement is outside of all module 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 12
  • 13. Example Global Variable Declare Integer number Module main() Display "Enter a number." Input number Call showNumber() End Module Module showNumber() Display "The number you entered is ", number End Module Global variable 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 13
  • 14. Passing Arguments to Modules 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 14
  • 15. • An argument is any piece of data that is passed into a module when the module is called • If you want a module to receive arguments when it is called, you must equip the module with one or more parameter variables. • A parameter is a variable that receives an argument that is passed into a module. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 15
  • 16. Simple Example 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 16
  • 17. Two Type of Passing Arguments Value • Only a copy of the argument’s value is passed into the parameter variable • If the contents of the parameter variable are changed inside the module, it has no effect on the argument in the calling part of the program Reference • The argument is passed into a special type of parameter known as a reference variable. • When a reference variable is used as a parameter in a module, it allows the module to modify the argument in the calling part of the program 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 17
  • 18. Example Passing Arguments by Value 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 18
  • 19. Example Passing Arguments by References 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 19
  • 20. Passing multiple arguments • Most languages allow you to write modules that accept multiple arguments. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 20
  • 21. Rules to Remember when Passing an Arguments 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 21
  • 22. Argument and the receiving parameter variable be of the same data type If you try to pass different type, an error usually occurs 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 22
  • 23. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 23
  • 24. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 24
  • 25. Hierarchy Charts 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 25
  • 26. Hierarchy Charts show the relationship between the modules 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 26
  • 27. Flow of Hierarchy Charts Main Program Module 1 Module 2 Module 3 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 27
  • 28. Example Main Program receiveOrder() Confirm() printCustomerData() checkAvailability() processOrder() billCustomer() 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 28
  • 29. Flow Chart of Modules 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 29
  • 30. Symbol 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 30
  • 31. Flowchart Notation Meaning 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 31
  • 32. Terminal / Terminator • Marks the starting or ending point of the system • Usually contains the word “Start” or “End” Action/Process • Represent a single step or and entire sub- process within a larger process Document • Printed document or report Data/Input/Output • Information entering as input • Information display as output Decision • System decision Database • Storage information 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 32
  • 33. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 33
  • 34. Summary • Programmers break down programming problems into reasonable units called modules, subroutines, procedures, functions, or methods. • To execute a module, you call it from another program or module • When you create a module, you include a header, a body, and a return statement. • When a main program wants to use a module, it “calls” the module’s name • Th e variables and constants declared in a module are usable only within the module; they are local to the module. Global variables and constants are those that are known to the entire program. • You can use a hierarchy chart to illustrate modules’ relationships. A hierarchy chart tells you which modules exist within a program and which modules call others. 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 34
  • 35. End 18/9/2018 CSWD1001 @ Kwan Lee First City Unversity Malaysia (FCUC) 35

Editor's Notes

  1. Reason - Programmers seldom write programs as one long series of steps.
  2. #include <iostream> using namespace std; //Declare module int number1, number2; int showSum(int value1, int value2); int main(){ cout << "Enter first number: "; cin >> number1; cout << "Enter second number: "; cin >> number2; showSum(number1, number2); } //Module changeMe int showSum(int value1, int value2){ cout << "Number 1: " << number1 << endl; cout << "number 2: " << number2 << endl; int sum = number1 + number2; cout << "Total is: " << sum;; }
  3. When you pass an argument to a module, most programming languages require that the argument and the receiving parameter variable be of the same data type.
  4. NOTE: Some languages allow you to pass an argument into a parameter variable of a different type as long as no data will be lost. For example, some languages allow you to pass integer arguments into real parameters because real variables can hold whole numbers. If you pass a real argument, such as 24.7, into an integer parameter, the fractional part of the number would be lost.
  5. #include <iostream> using namespace std; //Declare module without return value void showMessage(); int main(){ cout<<"I have a message for you" << endl; //Call module showMessage(); cout << endl; cout <<"That's all folks. :P"; } //Module showMessage void showMessage(){ cout << "Hello World"; }