Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Python Objects and Classes
Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
CSE 251 Dr. Charles B. Owen Programming in C1 Functions.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved. 1.
Chapter 7: User-Defined Functions II
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved. 1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2014 All Rights Reserved.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2014 All Rights Reserved.
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2014 All Rights Reserved.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved. 1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Chapter 11: Classes and Data Abstraction
Software Engineering Principles and C++ Classes
ASP.NET Programming with C# and SQL Server First Edition
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2014 All Rights Reserved.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved. 1.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
Functions.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Week 9 PHP Cookies and Session Introduction to JavaScript.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Chapter 6: Functions Starting Out with C++ Early Objects
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Chapter 13 Programming in the Large Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
1 Functions Lecfture Abstraction abstraction is the process of ignoring minutiae and focusing on the big picture in modern life, we are constantly.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2015, Fred McClurg, All Rights.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Outline 16.1Introduction 16.2Program Modules in JavaScript 16.3Programmer-Defined Functions 16.4Function.
JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Class Miscellanea Details About Classes. Review We’ve seen that a class has two sections: class Temperature { public: //... public members private: //...
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2015, Fred McClurg, All Rights.
JavaScript, Fourth Edition
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Week 4 Program Control Structure
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
Custom Functions © Copyright 2014, Fred McClurg All Rights Reserved.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2015, Fred McClurg, All Rights.
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2016, Fred McClurg, All Rights.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
ENCAPSULATION. WHY ENCAPSULATE? So far, the objects we have designed have all of their methods and variables visible to any part of the program that has.
Chapter 7: User-Defined Functions II
Kirkwood Center for Continuing Education
المحاضرة الثانية.
Kirkwood Center for Continuing Education
Kirkwood Center for Continuing Education
COMPUTER PROGRAMMING SKILLS
Presentation transcript:

Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1

Chapter Five PHP function, what’s your function? ourses/php/slides/chapter05.functions.ppt 2

Definition: A function is a reusable, self- contained (encapsulated) block of code with a well defined input and output. They are black box “number machines” that hide the internal implementation details. The function of a function 3

Similar to your TV remote, the user interface details are exposed (via push buttons), documented (via user’s manual) and the end result of using that interface is well defined (e.g. volume is increased, channel is incremented, etc.). The specific implementation details regarding how it actually works is masked from the user. Knowledge of internal operation of the remote control is not necessary for proper operation. Anatomy of a Function 0 11 inputinput outputoutput functionfunction 4

Description: There are hundreds of base functions that come bundled with PHP Examples: phpinfo(); echo("Open the pod bay doors, HAL."); $encrypted = md5( $password ); $unpad = trim( " padded string " ); $noCr = chop( "carriage return\n" ); $squareRoot = sqrt( 9 ); $timeStamp = time(); Base Functions 5

Description: In addition to using base functions, you can define your own custom functions. Function Definition Syntax: function functName( $param1,... ) {... return( $returnValue ); } Function Call Syntax: $returnVal = functName( $p1,... ); User Defined Function Syntax 6

<?php function isLeapYear( $year ) { if (((($year % 4) == 0) && (($year % 100) != 0)) || (($year % 400) == 0)) $result = TRUE; else $result = FALSE; return( $result ); } $yr = 2000; printf( "Year %d ", $yr ); $status = isLeapYear( $yr ) ? "is" : "is not"; printf( "%s a leap year", $status ); ?> User Defined Function Example 7

Problem: Write a function that converts Fahrenheit to Celsius. Requirements: 1. Write a driver that calls the conversion function with a single value. 2. Write a user-defined function that uses the following conversion formula: 3. Display the Fahrenheit value input and the calculated Celsius value returned from the function. Function Parameter: Variable for Fahrenheit. Function Return: Variable for degrees Celsius. Student Exercise (F to C Conversion) 8

<?php function f2c( $degreeF ) { $degreeC = ( 5 / 9 ) * ( $degreeF - 32 ); return( $degreeC ); } $fahrenheit = 212; $celsius = f2c( $fahrenheit ); printf( "%.1f Fahrenheit equals %.1f Celsius", $fahrenheit, $celsius ); ?> Student Solution (F to C Conversion) 9

Description: The default parameter initializes a function argument to a certain value if the parameter is omitted. Example: <?php function myLog( $exp, $base = 10 ) { return( log( $exp, $base ) ); } $result = myLog( 1000 ); printf( "log10(1000): %.0f ", $result ); $result = myLog( 8, 2 ); printf( "log2(8): %d ", $result ); ?> Functions with Default Parameters 10

Description: A static variable is not destroyed after the function exits. A static variable retains its value between function calls and stays in scope until the browser is closed. <?php function birthday() { // initialize once static $age = 0; return( ++$age ); // would this result in the same value? // return( $age++ ); } for ( $i = 0 ; $i < 5 ; $i++ ) printf( "Age: %d ", birthday() ); ?> Static Variables 11

to be continued... urses/php/slides/chapter05b.valueVsRef.ppt