Download presentation
Presentation is loading. Please wait.
1
Assistanship Assistant : Denny, TE 2002
Type : not compulsary, only when necessary Duration : once a week, not more than hours. Time,place : ask assistant Registration : send to:
2
Web address for course material
3
Modularisation Lecture 8
4
Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module) Each module represent single task, free of error Modularisation : is the process of dividing a problem into separate tasks, each with a single purpose.
5
Benefits of modular design
Ease of understandingeach module has only one function Reusable code Elimination of redundancy avoid the repetition of writing Efficiency of maintenance
6
Modular name convention
Describe the work to be done as a single specific function Use a verb, followed by a two-word object. Example: Print_page_heading Calculate_sales_tax Validate_input_date
7
Example 8.1 Design a solution algorithm that will prompt a terminal operator for three characters, accept those characters as input, sort them into ascending sequence and output them to the screen. The algorithm is to continue to read characters until ´XXX´is entered.
8
Defining diagram Input Processing Output Char_1 Char_2 Char_3
Prompt for characters Accept three characters Sort three characters Ouput three characters
9
Original Solution algorithm
Process_three_characters Prompt the operator for char_1, char_2, char_3 Get char_1, char_2, char_3 DOWHILE NOT (char_1=´X`AND char_2=´X´AND char_3=´X´) IF char_1>char_2 THEN temp = char_1 char_1 = char_2 char_2 = temp ENDIF IF char_2>char_3 THEN temp = char_2 char_2 = char_3 char_3 = temp Output to the screen char_1, char_2, char_3 Prompt operator for char_1, char_2, char_3 ENDDO END
10
Solution Algorithm using a module
Process_three_characters Prompt the operator for char_1,char_2,char_3 Get char_1, char_2, char_3 DOWHILE NOT (char_1=´X`AND char_2=´X´AND char_3=´X´) Sort_three_characters Output to the screen char_1,char_2,char_3 Prompt operator for char_1, char_2, char_3 Get char_1,char_2,char_3 ENDDO END IF char_1>char_2 THEN temp = char_1 char_1 = char_2 char_2 = temp ENDIF IF char_2>char_3 THEN temp = char_2 char_2 = char_3 char_3 = temp ´Controlling module´or ´Calling module´or ´Mainline“ `Subordinate module` or `Called Module`
11
Hierarchy charts or structure charts or visual table of content
President Vice_president Sales Vice_president Finance Vice_president Personnel Manager A Manager B Manager C Manager D Manager E Manager F
12
Hierarchy Chart Example 8.1
Process_three_ characters Calling module Sort_three_ characters Called module
13
Example 8.2 Process three characters
Design a solution algorithm that will prompt a terminal operator for three characters, accept those characters as input, sort them into ascending sequence and output them to the screen. The algorithm is to continue to read characters until ´XXX´is entered.
14
Defining diagram Input Processing Output Char_1 Char_2 Char_3
Prompt for characters Accept three characters Sort three characters Ouput three characters
15
Solution Algorithm Mainline 1rst Module 2nd Module 3rd Module
Process_three_characters Read_three_characters DOWHILE NOT (char_1=´X`AND char_2=´X´AND char_3=´X´) Sort_three_characters Print_three_characters ENDDO END Prompt the operator for char_1,char_2,char_3 Get char_1, char_2, char_3 IF char_1>char_2 THEN temp = char_1 char_1 = char_2 char_2 = temp ENDIF IF char_2>char_3 THEN temp = char_2 char_2 = char_3 char_3 = temp Output to the screen char_1, char_2, char_3 Mainline 1rst Module 2nd Module 3rd Module
16
Hierarchy charts Process_three_ characters Read_three_ characters
Sort_three_ characters Print_three_ characters
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.