Presentation is loading. Please wait.

Presentation is loading. Please wait.

Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into small parts (module)

Similar presentations


Presentation on theme: "Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into small parts (module)"— Presentation transcript:

1 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.

2 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

3 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

4 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.

5 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

6 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

7 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`

8 Hierarchy Chart Example 8.1 Process_three_ characters Sort_three_ characters Calling module Called module

9 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.

10 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

11 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

12 Hierarchy charts Process_three_ characters Read_three_ characters Sort_three_ characters Print_three_ characters


Download ppt "Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into small parts (module)"

Similar presentations


Ads by Google