Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
PHP Reusing Code and Writing Functions.
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Modular Programming With Functions
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Introduction to Computers and Programming Introduction to Methods in Java.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Functions. COMP104 Lecture 13 / Slide 2 Review of Array: Bubble Sort for (j=0; j List[j+1]) swap(List[j], List[j+1]); }
Chapter 6: User-Defined Functions I
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Lab 5 Using methods Why methods ? Manage complexity Manage complexity Better program organization Better program organization Next step in understanding.
Computer Science 240 Principles of Software Design.
IB Computer Science: 1.6 Software Design Created by Kevin Scott.
CS 31 Discussion, Week 4 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:30-1:30pm (today)
CS1101: Programming Methodology
CS1101: Programming Methodology Aaron Tan.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
1 -Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. How it works Programmer.
Top-Down Design and Modular Development
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Chapter 6 Functions 1. Opening Problem 2 Find the sum of integers from 1 to 10, from 20 to 37, and from 35 to 49, respectively.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
CSE 219 Computer Science III Program Design Principles.
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
1 Life Cycle of Software Specification Design –Risk Analysis –Verification Coding Testing –Refining –Production Maintenance.
Top-Down Design and Modular Development. The process of developing methods for objects is mostly a process of developing algorithms; each method is an.
C Programming Lecture 8-1 : Function (Basic). What is a Function? A small program(subroutine) that performs a particular task Input : parameter / argument.
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
CMSC 104, Version 8/061L17Top-DownDesign.ppt Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.1.

1 Program Development l Problem definition l Problem analysis l Algorithm design l Program coding l Program testing l Program documentation.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
Or how to work smarter when building solutions.  2:30 – 3:30 Mondays – focus on problem solving (with some terminology thrown in upon occasion)  All.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
Chapter 3: User-Defined Functions I
04/02/ Procedures Top-down approach / Stepwise Refinement & Sub Procedures.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Lesson 06: Functions Class Participation: Class Chat:
CSC 222: Computer Programming II
Coupling and Cohesion Rajni Bhalla.
Exam #1 You will have exactly 30 Mins to complete the exam.
Chapter 6: User-Defined Functions I
Possible exam questions with Scenarios
Review What is an object? What is a class?
Chapter 6 Functions.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Functions, variables, operators, loops Modularity
User-Defined Functions
Problem Solving Techniques
MSIS 655 Advanced Business Applications Programming
Lesson 06: Functions Class Chat: Attendance: Participation
Chapter 6: User-Defined Functions I
Chapter 2. Problem Solving and Software Engineering
Introduction to Computing Lecture 08: Functions (Part I)
Software Development Chapter 1.
Introduction to Methods and Interfaces
Presentation transcript:

Modular Programming

Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the code easier to develop, test and debug  Promotes reusability of codes In general a problem is solved in 3 steps: input  computation  output. © CS1101 (AY Semester 1) Week6 - 2

Modular Programming (2/6) Write a separate module to perform the computation step. If the computation is complex, it should be further split into smaller steps and each step performed by a module. A ‘module’  Should be well-defined  Should do one task © CS1101 (AY Semester 1) Week6 - 3

Modular Programming (3/6) A well-defined module  Has a good name (for readability and documentation)  Has a clear interface (what parameters does it take?)  May pass back to its caller no result or a single result (what value does it return?)  Example: setColour(int c)  Example: getColour() © CS1101 (AY Semester 1) Week6 - 4 void setColour(int c) { int colour = c; } Takes in integer c. Does not return any value (void). int getColour() { return colour; } Takes in no parameter. Returns an integer

Modular Programming (4/6) Advantages of modular programming:  Easy to replace  E.g.: When you discover a better algorithm for isPrime(int), you just replace that method without affecting any other parts of the program or other programs.  Easy to reuse  E.g.: Suppose you want to write a program to count the number of prime numbers between two integers a and b.  Compare how you would need to modify © CS1101 (AY Semester 1) Week6 - 5

Modular Programming (5/6) Reusability of code  If isPrime(int) is a very commonly used method, we could even go a step further…  Ie. It is so short and sweet!  Any other application that requires the isPrime(int) method can use the method in a similar fashion. © CS1101 (AY Semester 1) Week6 - 6

7 Advantages of Modular Programming Extension of function modularity: Build, test, debug in isolation from other modules. Prevent access to private functions and data – prevent misuse. Hide difficult algorithms behind a set of interfaces. Hide non-portable code behind a portable interface. Can change internals without changing client code. Enable teams to work on same program. Each works on a different module. Modules are often reusable – libraries.