A function is a group of statements that exist within a program for the purpose of performing a specific task. We can use functions to divide and conquer.

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

Introduction to Computers and Programming Introduction to Methods in Java.
VBA Modules, Functions, Variables, and Constants
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
Introduction to Computers and Programming Lecture 13: User defined methods Instructor: Evan Korth New York University.
Algorithm Description. Dinky Database Dantai The Dinky Database Dantai has received an unreasonable number of complaints about the speed of their Zip.
Program Design Divide and Conquer –Divide the program into separate tasks Functional Decomposition Top-Down Design –Divide an overall problem into discrete.
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
Introduction to Methods
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Top-Down Design and Modular Development
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
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.
Top-Down Design and Modular Development. The process of developing methods for objects is mostly a process of developing algorithms; each method is an.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
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.
1 CS161 Introduction to Computer Science Topic #9.
1 Methods Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Chapter 8 Functions in Depth. Chapter 8 A programmer-defined function is a block of statements, or a subprogram, that is written to perform a specific.
1 ICS103 Programming in C Lecture 8: Functions I.
Chapter 6 Methods Chapter 6 - Methods.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
Chapter 5 Methods 1. Motivations Method : groups statements that perform a function.  Level of abstraction (black box)  Code Reuse – no need to reinvent.
Controlling Computers with Programs When you create a computer program you are creating a set of instructions that tell the computer exactly and completely.
Guide to Programming with Python Chapter Six Functions: The Tic-Tac-Toe Game.
JavaScript Modularity. Goals By the end of this lecture, you should … Understand why programmers use modularity. Understand how to create a function in.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Chapter 7: Function.
Topics Introduction to Functions Defining and Calling a Void Function
Topic: Functions – Part 2
Function There are two types of Function User Defined Function
CSC113: Computer Programming (Theory = 03, Lab = 01)
©2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The Effectiveness of Test-first Programming
Starting Out with Java: From Control Structures through Objects
Starting Out with Programming Logic & Design
Chapter 3 Simple Functions
Subroutines Web Programming.
Functions, Procedures, and Abstraction
Chapter 4 void Functions
Functions Overview CSCE 121 J. Michael Moore
Topics Introduction to Functions Defining and Calling a Void Function
Functions Christopher Harrison | Content Developer
Chapter 9: Value-Returning Functions
Purpose Students will be able to use the Commutative, Associative, and Distributive Properties to simplify expressions and combine like terms.
Topics Introduction to Functions Defining and Calling a Function
Starting Out with Programming Logic & Design
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Modules Programming Guides.
Modules, Subroutines, Procedures, Functions, or Methods
Chapter (3) - Procedures
Functions, Procedures, and Abstraction
Agenda for Unit 3: Functions
Chapter 6: Methods CS1: Java Programming Colorado State University
Presentation transcript:

A function is a group of statements that exist within a program for the purpose of performing a specific task. We can use functions to divide and conquer a task

Benefits Simpler Code: Code is easier to read and understand. Code Reuse: Functions reduce duplication of code, if a specific operation is performed multiple times, it can be written once and used over and over again. Better Testing: With each task in its own block, its easier to test and develop. Faster Development: If a programmer has to develop multiple programs, and he discovers that certain tasks are common to them, he can write a function or functions to perform those tasks and reuse them. Easier Facilitation of Teamwork: Functions make it easier to do collaboration.

What mistake can we find in the following code?

Scope and Local Variables

Passing Arguments to Functions