First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.

Slides:



Advertisements
Similar presentations
Structured Design. 2 Design Quality – Simplicity “There are two ways of constructing a software design: One is to make it so simple that there are obviously.
Advertisements

Chapter 3: Modularization
Communication between modules, cohesion and coupling
Programming Logic and Design Fourth Edition, Introductory
Assistanship Assistant: Denny, TE 2002 Type: not compulsary, only when necessary Duration: once a week, not more than 2 hours. Time,place: ask assistant.
© Copyright 2011 John Wiley & Sons, Inc.
Chapter 2: Input, Processing, and Output
Modularisation II Lecture 9. Communication between modules Also known as intermodule communication. The fewer and the simpler the communications, the.
Modules, Hierarchy Charts, and Documentation
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
Chapter 1 Program Design
Pseudocode.
Chapter 3 Planning Your Solution
The Program Design Phases
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
System Implementation System Implementation - Mr. Ahmad Al-Ghoul System Analysis and Design.
Structured COBOL Programming, Stern & Stern, 9th edition
Pseudocode algorithms using sequence, selection and repetition
Simple Program Design Third Edition A Step-by-Step Approach
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Programming Logic and Design Fifth Edition, Comprehensive
Programming Concepts Chapter 3.
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
Developing an Algorithm
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Array Processing.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Developing an Algorithm
System Implementation
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10.
Pseudocode Algorithms Using Sequence, Selection, and Repetition
Repetition Control Structures Simple Program Design Third Edition A Step-by-Step Approach 5.
Pseudocode Algorithms Using Sequence, Selection, and Repetition Simple Program Design Third Edition A Step-by-Step Approach 6.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Developing an Algorithm. Simple Program Design, Fourth Edition Chapter 3 2 Objectives In this chapter you will be able to: Introduce methods of analyzing.
Chapter 8 First steps in modularisation. Objectives To introduce modularisation as a means of dividing a problem into subtasks To present hierarchy charts.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
Cosc175/module.ppt1 Introduction to Modularity Function/procedures void/value-returning Arguments/parameters Formal arguments/actual arguments Pass by.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into small parts (module)
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Systems Design.  Application Design  User Interface Design  Database Design.
Flowcharts Lecture 12.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Structure Charts. Graphical representation of the logic of the program, the decisions made, where they are made, the alternative paths, the data stores,
Systems Analysis and Design in a Changing World, Fourth Edition
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
Chapter 2: Input, Processing, and Output
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Designing and Debugging Batch and Interactive COBOL Programs
Starting Out with Programming Logic & Design
Unit# 9: Computer Program Development
Chapter 4 void Functions
Pseudocode algorithms using sequence, selection and repetition
Topics Introduction to Functions Defining and Calling a Void Function
Topics Introduction to Functions Defining and Calling a Function
Starting Out with Programming Logic & Design
Communication between modules, cohesion and coupling
Chapter 4: Writing and Designing a Complete Program
Assistanship Assistant : Denny, TE 2002
Introduction to Pseudocode
Presentation transcript:

First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8

Objectives To introduce modularization as a means of dividing a problem into subtasks To present hierarchy charts as a pictorial representation of modular program structure To discuss intermodule communication, local and global variables, and the passing of parameters between modules To develop programming examples that use a simple modularized structure 8

Modularization As programming problems increase in complexity, it becomes more and more difficult to consider the solution as a whole You must identify the major tasks to be performed in the problem, then divide the problem into sections that represent those tasks This process of identifying first the major tasks, then further subtasks within them, is known as top-down design or functional decomposition 8

Modularization By using a top-down design methodology, the programmer is adopting a modular approach to program design Modularization is the process of dividing a problem into separate tasks 8

The Modularization Process When you are defining the problem, write down the activities or processing steps to be performed The emphasis when defining the problem must still be to concentrate on the tasks or functions that need to be performed A module must be large enough to perform its task, and must include only the operations that contribute to the performance of that task 8

The Modularization Process The name of the module should describe the work to be done as a single specific function The convention of naming a module by using a verb, followed by a two-word object, is particularly important, as it helps to identify the separate task or function that the module has been designed to perform Typical module names might be: Print_page_headings Calculate_sales_tax Validate_input_date 8

The Mainline A mainline routine must provide the master control that ties all the modules together and coordinates their activity This program mainline should show the main processing functions, and the order in which they are to be performed It should also show the flow of data and the major control structures 8

Example 8.1 Read 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 A Defining diagram (see figure at bottom of page 105 of the textbook) 8

Example 8.1 Read Three Characters B Initial solution algorithm Refer to the algorithm written out on page 106 of the textbook C Solution algorithm using a module Refer to the code written out on pages 106 and 107 of the textbook The solution algorithm now consists of two modules: a mainline module called Read_three_characters and a submodule called Sort_three_characters 8

Hierarchy Charts or Structure Charts After the tasks have been grouped into functions or modules, present these modules graphically in a diagram This diagram is known as a hierarchy chart, as it shows not only the names of all the modules but also their hierarchical relationship to each other 8

Hierarchy Charts or Structure Charts 8 A hierarchy chart may also be referred to as a structure chart, or a visual table of contents The hierarchy chart uses a tree-like diagram of boxes; each box represents a module in the program and the lines connecting the boxes represent the relationship of the modules to other in the program hierarchy

Communication Between Modules When designing solution algorithms, you should consider not only the breaking up of the problem into modules but also the flow of information between the modules This flow of information, called intermodule communication, can be accomplished by the scope of the variable (local or global data) or the passing of parameters 8

Scope of a Variable The scope of a variable is the portion of a program in which that variable has been defined and to which it can be referred If a list is created of all the modules in which a variable can be referenced, that list defines the scope of the variable Variables can be global, where the scope of the variable is the whole program, and local, where the scope of the variable is simply the module in which it is defined 8

Global Data When information or data uses the same variable name in both the calling module and the called modules of a program, the data is known as global data, and the scope of the variable is the whole program because the data can be accessed by every module in the program All data, however, does not need to be global 8

Local Data Variables that are defined within a subordinate module are called local variables These local variables are not known to the calling module, nor to any other module 8

Side Effects A side effect is a form of cross- communication of a module with other parts of a program It occurs when a subordinate module alters the value of a global variable inside a module Side effects are not necessarily detrimental 8

Passing Parameters Another method of intermodule communication is the passing of parameters or arguments between modules Parameters are simply data items transferred from a calling module to its subordinate module at the time of calling When a calling module calls a subordinate module in pseudocode, it must consist of the name of the called module with a list of parameters to be passed to the called module enclosed in parentheses 8

Passing Parameters An example: Print_page_headings (page_count, line_count) Parameters may have one of three functions: 1.To pass information from a calling module to a subordinate module 2.To pass information from a subordinate module to its calling module 3.To fulfill a two-way communication role Refer to the figures on page 110 for the symbols that can be incorporated into a hierarchy or structure chart 8

Passing Parameters When designing modular programs, the programmer should avoid using data parameters to indicate status, because this can affect the program in two ways: 1.It may confuse the reader of the program because a variable has been overloaded 2.It may cause unpredictable errors when the program is amended at some later data, as the maintenance programmer may be unaware of the dual purpose of the variable 8

Using Parameters in Program Design Refer to Example 8.1 and change the solution algorithm so that parameters are used to communicate between modules as shown in Example 8.2 of the textbook A Defining diagram (see the figure at the top of page 111 of the textbook) B Group the activities into modules 1.Read_three characters 2.Sort_three characters 8

Using Parameters in Program Design C Construct a hierarchy chart Refer to the figure at the bottom of page 111 of the textbook for an example D Establish the logic of the solution algorithm using pseudocode (mainline and subordinate module) Have students refer to page 112 of the textbook to review the pseudocode 8

Steps in Modularization Top-down modular design is really quite simple if the following steps are performed every time you are presented with a programming problem: 1.Define the program by dividing it into its three components: input, output, and processing 2.Group the activities into subtasks or functions to determine the modules that will make up the program 8

Steps in Modularization 3.Construct a hierarchy chart to illustrate the modules and their relationship to each other 4.Establish the logic of the mainline of the algorithm in pseudocode 5.Develop the pseudocode for each successive module in the hierarchy chart 6.Desk check the solution algorithm. This is achieved by first desk checking the mainline, then each subordinate module in turn 8

Programming Examples Using Modules Example 8.3 Calculate employee’s pay A program is required by a company to read an employee’s number, pay rate, and the number of hours worked in a week. The program is then to compute the employee’s weekly pay and print it along with the input data A) Define the problem (see the figure at the top of page 114 of the textbook) 8

Programming Examples Using Modules B) Group the activities into modules The activities can be grouped into three main functions: 1.Compute_employee_pay 2.Validate_input_fields 3.Calculate_employee_pay C) Construct a hierarchy chart (see the figure on page 114 of the textbook) If you write the solution algorithm as three separate modules, the readability of the solution will improve dramatically 8

Programming Examples Using Modules D) Establish the logic of the mainline of the algorithm using pseudocode Do this by using code as shown on page 115 of the textbook E) Develop the pseudocode for each successive module in the hierarchy chart Accomplish this task by referring to the code shown on page 115 of the textbook 8

Programming Examples Using Modules F) Desk check the solution algorithm Use the following steps to do this: 1.Create some valid input test data 2.List the output that the input data is expected to produce 3.Use a desk check table to walk the data through the mainline of the algorithm to ensure that the expected output is achieved 8

Programming Examples Using Modules (i)Input data: (see the figure on page 116 of the textbook) Three test cases will be used to test the algorithm (ii)Expected results Refer to the examples shown on page 116 of the textbook (iii)Desk check table (see the figure on page 117 of the textbook) 8

Summary A module is a section of an algorithm that is dedicated to the performance of a single function Top-down design is the process of dividing a problem first into the major tasks and then into further subtasks within those major tasks until all the tasks have been identified Hierarchy charts are a method of illustrating the structure of a program that contains modules 8

Summary Intermodule communication is the flow of information or data between modules The steps in modularization that a programmer must follow are: –Define the problem –Group the activities into subtasks or functions –Construct a hierarchy chart –Establish the logic of the mainline, using pseudocode –Develop the pseudocode for each successive module in the hierarchy chart –Desk check the solution algorithm 8