motivation complexity of programming problem more difficult to consider the solution as a whole ...
TRANSCRIPT
![Page 1: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/1.jpg)
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.
![Page 2: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/2.jpg)
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
![Page 3: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/3.jpg)
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
![Page 4: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/4.jpg)
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.
![Page 5: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/5.jpg)
• Defining diagram
Input Processing Output
Char_1Char_2Char_3
Prompt for charactersAccept three charactersSort three charactersOuput three characters
Char_1Char_2Char_3
![Page 6: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/6.jpg)
Original Solution algorithmProcess_three_characters
Prompt the operator for char_1, char_2, char_3Get char_1, char_2, char_3DOWHILE NOT (char_1=´X`AND char_2=´X´AND char_3=´X´)
IF char_1>char_2 THENtemp = char_1char_1 = char_2char_2 = temp
ENDIFIF char_2>char_3 THEN
temp = char_2char_2 = char_3char_3 = temp
ENDIFIF char_1>char_2 THEN
temp = char_1char_1 = char_2char_2 = temp
ENDIFOutput to the screen char_1, char_2, char_3Prompt operator for char_1, char_2, char_3Get char_1, char_2, char_3
ENDDOEND
![Page 7: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/7.jpg)
Solution Algorithm using a moduleProcess_three_characters
Prompt the operator for char_1,char_2,char_3Get char_1, char_2, char_3DOWHILE NOT (char_1=´X`AND char_2=´X´AND char_3=´X´)
Sort_three_charactersOutput to the screen char_1,char_2,char_3Prompt operator for char_1, char_2, char_3Get char_1,char_2,char_3
ENDDOEND
Sort_three_charactersIF char_1>char_2 THEN
temp = char_1char_1 = char_2char_2 = temp
ENDIF IF char_2>char_3 THEN
temp = char_2char_2 = char_3char_3 = temp
ENDIFIF char_1>char_2 THEN
temp = char_1char_1 = char_2char_2 = temp
ENDIFEND
´Controlling module´or´Calling module´or ´Mainline“
`Subordinate module` or `Called Module`
![Page 8: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/8.jpg)
Hierarchy Chart Example 8.1
Process_three_characters
Sort_three_characters
Calling module
Called module
![Page 9: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/9.jpg)
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.
![Page 10: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/10.jpg)
• Defining diagram
Input Processing Output
Char_1Char_2Char_3
Prompt for charactersAccept three charactersSort three charactersOuput three characters
Char_1Char_2Char_3
![Page 11: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/11.jpg)
Solution AlgorithmProcess_three_characters
Read_three_charactersDOWHILE NOT (char_1=´X`AND char_2=´X´AND char_3=´X´)
Sort_three_charactersPrint_three_charactersRead_three_characters
ENDDOEND
Read_three_charactersPrompt the operator for char_1,char_2,char_3Get char_1, char_2, char_3
END
Sort_three_charactersIF char_1>char_2 THEN
temp = char_1char_1 = char_2char_2 = temp
ENDIF IF char_2>char_3 THEN
temp = char_2char_2 = char_3char_3 = temp
ENDIFIF char_1>char_2 THEN
temp = char_1char_1 = char_2char_2 = temp
ENDIFEND
Print_three_charactersOutput to the screen char_1, char_2, char_3
END
Mainline
1rst Module
2nd Module
3rd Module
![Page 12: Motivation Complexity of programming problem more difficult to consider the solution as a whole clue: dividing the problem into small parts (module)](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bfef1a28abf838cb9fe1/html5/thumbnails/12.jpg)
Hierarchy charts
Process_three_characters
Read_three_characters
Sort_three_characters
Print_three_characters