Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.

Slides:



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

Introduction to C Programming
Sub and Function Procedures
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
1 5.3 Sub Procedures, Part II Passing by Value Passing by Reference Sub Procedures that Return a Single Value Debugging.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
1.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
Chapter 6: User-Defined Functions I
1 Modularity In “C”. 2 What is Modularity?  Modularity, is the heart of the high level, structured languages.  Means breaking down a big problem into.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
CS 201 Functions Debzani Deb.
Chapter 6: User-Defined Functions I
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 7: Sub and Function Procedures
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 41 General Procedures Sub Procedures, Part I Sub Procedures, Part II Function Procedures.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
Chapter 6: Functions.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
 Introduction Introduction  Types of Function Types of Function  Library function Library function  User defined function User defined function 
Tasks and Functions Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar Gudarzi.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Tutorial 11 Using and Writing Visual Basic for Applications Code
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
CPS120: Introduction to Computer Science Functions.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
CPS120: Introduction to Computer Science Lecture 14 Functions.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Sub Procedures. A Sub procedure is a block of code that is executed in response to an event. There are two types of Sub procedures, general procedures.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
User defined functions
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
Neal Stublen Breaking Down Tasks  Reduce large tasks into smaller units of code  Smaller units of code might be called any of the.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
FUNCTION Functions is a sub-program that contains one or more statements and it performs some task when called.
Visual Basic CDA College Limassol Campus COM123 Visual Programming 1 Semester B Lecture:Pelekanou Olga Week 5: Useful Functions and Procedures.
1 ICS103 Programming in C Lecture 8: Functions I.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Programming Logic and Design Seventh Edition
Chapter 6: User-Defined Functions I
Functions in C Mrs. Chitra M. Gaikwad.
User-Defined Functions
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
Chapter 4 - Visual Basic Schneider
Flow of Control.
Fundamental Programming
Chapter 10: Void Functions
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
Chapter 6 Modular Programming chap6.
Top-Down Design with Functions
Introducing Modularity
Presentation transcript:

Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney

Introduction Modularity Sub Procedures Arguments – Pass By Value – Pass By Reference

Modularity Decompose problems into components Model how components interact with each other Subprograms are used for this decomposition – Independent sections of code that performs specific tasks – Written and tested separately – Easier to maintain and modify – Pre-defined libraries – programmer defined libraries

Sub & Functions Procedures Sub Procedures – Used to perform tasks – Can return values in their arguments – Used to receive or process input, display output or set properties Function Procedures – Return a value in the function name – Used for calculations

Sub Procedures A “Sub” procedure – is part of a Program – performs a task (or 2) – has a name – is invoked with a “Call” statement A “Sub” – has its own code Sub Name( ) statement(s) End Sub Program … Call Name( ) … End program Sub procedure Program

Example – w/o Sub This version does NOT use a “sub”

Example – w/Sub This version does use a Sub

Example – w/Sub Sub receives the variable “value” Sub procedure Program “calls” Sub procedure Sub declares the variables in title line

Example – w/ Sub & File I/O Country Population Area (sq km) GDP ($)

Example

Argument Passing By Value Pass By Value – Sends the value of the argument to the Subprogram – Argument is evaluated and its value is passed and used locally in the Subprogram – Subprogram can not change the value of the variable in the calling program Arguments Parameters Sub uses value of parameters locally using values passed from calling program. We can use different names in the Sub. Value

Example – Pass By Value

Pass By Reference – Memory address of argument passed – Argument value can be changed in the Subprogram – Value in the calling program is also changed Argument Passing By Reference Sub uses value of parameters locally using address passed from calling program. Sub changes value residing at the address of the argument. This also changes it in the calling program. amt num Memory address

Example – Pass By Reference

Summary Modularity Sub Procedures Arguments – Pass By Value – Pass By Reference