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
Web address for course material http://www.te.ugm.ac.id/~achmad_y/
Modularisation Lecture 8
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.
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
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
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.
Defining diagram Input Processing Output Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Ouput three characters
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
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`
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
Hierarchy Chart Example 8.1 Process_three_ characters Calling module Sort_three_ characters Called module
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.
Defining diagram Input Processing Output Char_1 Char_2 Char_3 Prompt for characters Accept three characters Sort three characters Ouput three characters
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
Hierarchy charts Process_three_ characters Read_three_ characters Sort_three_ characters Print_three_ characters