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 2 hours. Time,place: ask assistant Registration: send email to: den02ugm@yahoo.co.uk
2
Web address for course material http://www.te.ugm.ac.id/~achmad_y/
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 understanding each 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 InputProcessingOutput Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Ouput three characters Char_1 Char_2 Char_3
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 ENDIF IF char_1>char_2 THEN temp = char_1 char_1 = char_2 char_2 = temp ENDIF 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
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 Sort_three_characters 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 ENDIF IF char_1>char_2 THEN temp = char_1 char_1 = char_2 char_2 = temp ENDIF END ´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 FManager EManager DManager CManager BManager A
12
Hierarchy Chart Example 8.1 Process_three_ characters Sort_three_ characters Calling module 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 InputProcessingOutput Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Ouput three characters Char_1 Char_2 Char_3
15
Solution Algorithm 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 Read_three_characters ENDDO END Read_three_characters Prompt the operator for char_1,char_2,char_3 Get char_1, char_2, char_3 END Sort_three_characters 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 ENDIF IF char_1>char_2 THEN temp = char_1 char_1 = char_2 char_2 = temp ENDIF END Print_three_characters Output to the screen char_1, char_2, char_3 END 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.