Chapter 6 Modular Programming 20061122 chap6.

Slides:



Advertisements
Similar presentations
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 6: Modular Programming Problem Solving & Program Design in.
Advertisements

Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Chapter 6 Modular Programming J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Subprogram Control - Data sharing Mechanisms to exchange data Arguments - data objects sent to a subprogram to be processed. Obtained through  parameters.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
1 CS 201 Pointers (2) Debzani Deb. 2 Overview Pointers Functions: pass by reference Quiz 2 : Review Q & A.
Computer Programming Lecture 13 Functions with Multiple Output Parameters Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics.
Chapter 6 Modular Programming Dr. J.-Y. Pan Dept. Comm. Eng. Nat. Chung Cheng Univ.
Function with Output Parameters 4 We have seen that functions can return a single value or no value (void return type) 4 It is quite often useful to be.
Modular Programming From Chapter 6. Output Parameters Pass by reference. In the calling program: int frog, lily; int * frog_ptr=&frog; function_name(frog_ptr,
TDBA66, VT-03, Lecture - Ch6_21 Function calls A function call implies –Every expression in the argument list is evaluated –If necessary, the value of.
CS 201 Functions Debzani Deb.
Chapter 9: Arrays and Strings
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 8 Arrays and Strings
Chapter 7 Simple Data Types and Function Calls Alkar / Demirer.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
C++ for Engineers and Scientists Third Edition
CP104 Introduction to Programming Modular Programming Lecture 16__ 1 Modular Programming II Functions with single output Functions with multiple outputs.
chap8 Chapter 8 Arrays (Hanly) chap8 2 Data Structure Simple data types use a simple memory to store a variable. Data Structure: a.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Chapter 8 Arrays and Strings
Compiler Construction
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Modular Programming Advantages of using functions (to make a modular program) are: Changing the program into separate pieces Code reusing Easier modification.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
#include using namespace std; // Declare a function. void check(int, double, double); int main() { check(1, 2.3, 4.56); check(7, 8.9, 10.11); } void check(int.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
User-Defined Functions II TK1914: C++ Programming.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
1 ICS103 Programming in C Lecture 8: Functions I.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Modular Programming Problem Solving and Program Design in C 5th.
Programming Fundamentals Enumerations and Functions.
Chapter 7 Modularity Using Functions: Part II. A First Book of ANSI C, Fourth Edition 2 Variable Scope If variables created inside a function are available.
A First Book of ANSI C Fourth Edition
ECE 103 Engineering Programming Chapter 30 C Functions Herbert G. Mayer, PSU CS Status 8/9/2014 Initial content copied verbatim from ECE 103 material developed.
Problem Solving and Program Design in C Chap. 6 Pointers and Modular Programming Chow-Sing Lin.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Test 2 Review Outline.
User-Written Functions
Programming Logic and Design Seventh Edition
Chapter 6: User-Defined Functions I
Chapter 7: User-Defined Functions II
Chapter 10: Void Functions
Chapter 6 Modular Programming Dr. J.-Y. Pan Dept. Comm. Eng.
Function There are two types of Function User Defined Function
User-Defined Functions
C++ for Engineers and Scientists Second Edition
Simple Data Types and Function Calls
Chapter 6 Methods: A Deeper Look
Object-Oriented Programming Using C++ Second Edition
Assist.Prof.Dr. Nükhet ÖZBEK Ege University
CS150 Introduction to Computer Science 1
Chapter 9: Value-Returning Functions
ICS103: Programming in C 6: Pointers and Modular Programming
Presentation transcript:

Chapter 6 Modular Programming 20061122 chap6

Functions with Simple Output Parameters In Chapter 3: functions. How to pass inputs into a function, and How to use the return statement to send back one result value from a function. How programmers use output parameters to return multiple results from a function. 20061122 chap6

Example: Function separate Separate a number into three parts. 20061122 chap6

20061122 chap6

Pointer A declaration of a simple output parameter such as char *signp tells the complier that signp will contain the address of a type char variable. The parameter signp is a pointer to a type char variable. Pointer: a memory cell whose content is the address of another memory cell. 20061122 chap6

Main function (Fig. 6.3) 20061122 chap6

separate(value, &sn, &whl, &fr) The use of the address-of operator & on the actual arguments sn, whl and fr is essential. If the operator & were omitted, we would be passing to separate the values of sn, whl and fr. The only way separate can store value is sn, whl and fr is if it knows where to find them in memory. e.g. scanf(“%d%lf”, &code, &amount); 20061122 chap6

Parameter Correspondence for separate 20061122 chap6

Multiple Calls to a Function with Input/Output Parameters The use of a single parameter both to bring a data value into a function and to carry a result value out of a function. How a function may be called more than once. Example: the Sort operation A rearrangement of data in a particular sequence (increasing or decreasing) 20061122 chap6

Ex: Sort Three Numbers (Fig. 6.6) 20061122 chap6

20061122 chap6

Scope of Names The region in a program where a particular meaning of a name is visible. The scope of the function subprogram begins with its prototype and continues to the end of the source file. All of the formal parameter and local variables are visible only from their declaration to the closing brace of the function in which they are declared. 20061122 chap6

Fig. 6.8 20061122 chap6

Formal Output Parameters as Actual Arguments Sometimes a function needs to pass its own output parameter as an argument when it calls another function. 20061122 chap6

20061122 chap6

Data Areas for scan_fraction and Its Caller 20061122 chap6

A Program with Multiple Functions Case Study: Arithmetic with Common Factions. 20061122 chap6

Show the program Fig. 6.12 20061122 chap6

Sample Run of a Partially Complete Program Containing Stubs 20061122 chap6

Debugging and Testing Top-Down Testing vs. Bottom-Up Testing Stubs: we can insert stubs in the program for functions that were not yet written. It provides a trace of the call sequence and allows the programmers to determine whether the flow of control within the program is correct. 20061122 chap6

Stub for multiply_fractions 20061122 chap6

Bottom-up Testing When a function is completed, we often perform a preliminary test of a new function. We perform such a unit test by writing a short driver function to call it. 20061122 chap6

Summary How programmers use output parameters to return multiple results from a function Pointer!!!!!! 20061122 chap6