Functions October 23, 2017.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1 Created by David Mann, North Idaho College.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 6: User-Defined Functions I
Topic 2A – Library Functions and Casting. CISC 105 – Topic 2A Functions A function is a piece of code which performs a specific task. When a function.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
4-Methods Dr. John P. Abraham Professor UTPA. Common ways of packaging code Properties Methods Classes Namespaces (related classes are grouped into a.
Today’s Lecture Predefined Functions. Introduction to Functions  Reuse Issue  Building Blocks of Programs  Two types of functions  Predefined  Programmer.
1 ICS103 Programming in C Lecture 7: Introduction to Functions.
Chapter 4 Procedural Abstraction and Functions That Return a Value.
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
USER-DEFINED FUNCTIONS. STANDARD (PREDEFINED) FUNCTIONS  In college algebra a function is defined as a rule or correspondence between values called the.
Warm-Up: Monday, March 24 List as many commands in Java as you can remember (at least 10)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstraction and Functions That Return a Value.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Recap……Last Time [Variables, Data Types and Constants]
Chapter 3: User-Defined Functions I
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapters 4 and 5: Excerpts l Class and Method Definitions l Information.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
USING & CREATING FUNCTIONS. MODULAR PROGRAMMING  Why Modular Programming?  Improves Readability & Understandability  Improve Maintainability  Allows.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 4 Functions.
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
FUNCTIONS Source of Notes: Mr Jamal Othman
Chapter 6: User-Defined Functions I
Procedural Abstraction and Functions That Return a Value
Mathematical Functions
Library Functions Goals of software engineering reliable code
Procedural Abstraction and Functions That Return a Value
Procedural Abstraction and Functions That Return a Value
BIL 104E Introduction to Scientific and Engineering Computing
TMF1414 Introduction to Programming
Chapter 4 Procedural Abstraction and Functions That Return a Value 1
Iterative Constructs Review
Lesson 5 Functions I A function is a small program which accomplishes a specific task. For example, we invoke (call) the function, sqrt(x), in the library.
CMPT 201 Functions.
FUNCTIONS EXAMPLES.
CSCI 161: Introduction to Programming Function
Math Library and IO formatting
User-Defined Functions
Formatted and Unformatted Input/Output Functions
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Functions Chapter 3 of the text Motivation:
Using Free Functions Chapter 3 Computing Fundamentals with C++
Programming in Pseudocode
Iterative Constructs Review
FUNCTION CSC128.
Topics discussed in this section:
Elementary Programming (C++)
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
Output Formatting Bina Ramamurthy 4/16/2019 BR.
Chapter 4 Procedural Abstraction and Functions That Return a Value 1
Output Formatting Bina Ramamurthy 9/25/2019 BR.
Presentation transcript:

Functions October 23, 2017

Top-Down Design Top-down design refers to designing a program by breaking down the end result into a series of smaller subtasks, then breaking those down further, and so on. The final subtasks should be trivial to implement (e.g., incrementing a variable). In C++, these subparts are known as functions. Other languages may refer to them as procedures or methods.

Predefined Functions C++ includes a number of predefined functions. The following functions are found in the cmath library: sqrt(x) computes the square root of x (which can be an int or double) pow(x, y) raises x to the power of y abs(x) computes the absolute value of x ceil(x) computes the first whole number greater than or equal to x ceil(2.1) == 3 floor(x) computes the first whole number less than or equal to x floor(2.9) == 2

Predefined Functions Consider the following code: root = sqrt(9); The value in parentheses is called the argument of the function. The value the function computes (in this case, 3) is called the value returned. The expression sqrt(9) is called a function call. Not all predefined functions take arguments. The rand() function (which computes a random number between 0 and 231 – 1) is one such function.

Random Number Generation N.B. On the AP exam, the pseudocode RANDOM(x, y) generates a random number between x and y. For instance, RANDOM(0, 5) generates a random number between 0 and 5.