1 -Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. How it works Programmer.

Slides:



Advertisements
Similar presentations
Chapter 2: Modularization
Advertisements

Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
The Web Warrior Guide to Web Design Technologies
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Introduction to Computers and Programming Introduction to Methods in Java.
Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 6: User-Defined Functions I.
Top-Down Design with Functions 4 What do programmer’s (not programs!) use as input to the design of a program? –Documentation Problem definition Requirements.
Multimedia & Website Design Working in Teams. This week Look at team work issues in web design Plan file and directory conventions Introduce formal software.
Chapter 6: User-Defined Functions I
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Guide To UNIX Using Linux Third Edition
ASP.NET Programming with C# and SQL Server First Edition
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Programmer Defined Functions Matthew Verleger. Windows It’s estimated that Window’s XP contains 45 million lines of code (and it’s over 10 years old).
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Add to your agenda! Discovery Day. Wednesday, April 3 rd – all day – Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For example: “Formula.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
1 Shawlands Academy Higher Computing Software Development Unit.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Annoucements Discovery Day ( sent this morning) – Wednesday, April 3 rd : Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For.
File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Introduction to Computer Application (IC) MH Room 517 Time : 7:00-9:30pm.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
The Software Development Process
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
1. FINISHING FUNCTIONS 2. INTRODUCING PLOTTING 1.
Programmer-Defined Functions Advantages vs. Disadvantage 1.Definition and general Idea 2.Many Advantages 3.1 Disadvantage 1.
Top-down approach / Stepwise Refinement & Procedures & Functions.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
-Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. Vocabulary 5. Examples 6. General Template – Applications 1. Definitions,
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
1 ICS103 Programming in C Lecture 8: Functions I.
Introduction to OOP CPS235: Introduction.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Programming Fundamentals Enumerations and Functions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
JavaScript 101 Lesson 6: Introduction to Functions.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Chapter 7: Function.
Visit for more Learning Resources
User-Written Functions
JavaScript: Functions
Function There are two types of Function User Defined Function
User-Defined Functions
Defining Classes and Methods
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Introducing Modularity
Presentation transcript:

1 -Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. How it works Programmer

2 -Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. How it works User

3 1.a. Goals of overall chapter 1. Understand all the advantages of writing programmer- defined functions 2. Know all the vocabulary (7) involved Function definition, Function call, Parameters vs. Arguments, Return info, Documentation, Code body (function body) 3. Easily create a programmer-defined function file and position all the elements correctly 4. Easily test and use a programmer-defined function

1.b. Goals of this lesson Understand the overall idea of what a function is Get a mental picture of how they work Know the many advantages of writing/using functions 4

5 2. General Concept sin(), cos(), fprintf(), mod(), input() were called built-in or library functions. These functions already exist in the MATLAB directory. They “come with” the software. This chapter introduces programmer-defined functions. As the vocabulary states the function is defined (written) by the programmer (you!). It does not pre-exist in the MATLAB directory.

6 General Concept cont. Used in every decent piece of software that exists. EGR101 – Rocket Project

7 General Concept cont. Huntsville Alabama. PARSEC (the Preliminary Analysis of Revolutionary Space Exploration Concepts) at NASA in Huntsville Alabama. Orbit Specialist Fuel Specialist Size Fuel Tank Structure Specialist Select/Design Engine Vehicle Geometry Estimate Cost THE CLIENT Can you see advantages to working like this? Applied to the Rocket Project…

3. Advantages 1. Focus: The developers are concerned with the goals of the function, not being distracted by other details of the project. 2. Portability: Instead of one script file that contains the entire program, the software is divided into smaller files. 1. Various engineers can work on their parts simultaneously. 2. Engineers can develop code peacefully in their private cube or even take work home or on business travel. 3. Engineers can send pieces of codes to other colleagues who are just as specialized as them providing feedback and improvements! 4. One engineer can participate in multiple projects: the fuel requirements may be the same for two different rockets… 8

9 3. Memory efficiency: One code: lots of variables  Smaller code and functions: lots of calculations but only the results are stored. The intermediate calculations are cleared from memory 4. Easier to debug: One code: what does not work???????? Smaller code and functions: Each function can be tested separately regardless of work by other colleagues. Assumptions have to be made but the function itself can be tested. Advantages, cont.

4. How it works Just like big projects 10 The client gives initial data. Results the client wanted! Task 1 Task 2 Task 3 Project Manager This may seem similar to EGR101 projects where within a team, students had to split a project into smaller tasks.

11 5. In Programming… Main script file clc clear Function definition #1 Function definition #2 Function definition #n Passing data to the function Passing data to… Getting results back…

12 5. Vocab. "Main Script File" Main script file (Project Manager) clc clear Function definition #1 Function definition #2 Function definition #n Passing data to the function Passing data to… Getting results back… "Main Script File" i.e. THE BOSS.

13 5. Vocab. "Function Definitions" Main script file (Project Manager) clc clear Function definition #1 Function definition #2 Function definition #n Passing data to the function Passing data to… Getting results back… "Functions Definitions" i.e. Each smaller piece of code.

14 5. Vocab. "Calling" Main script file (Project Manager) clc clear Function definition #1 Function definition #2 Function definition #n Getting results back… "Calling the function" i.e. "Execute this!"

15 5. Vocab. "Passing Arguments" Main script file (Project Manager) clc clear Function definition #1 Function definition #2 Function definition #n Passing data to the function Passing data to… Getting results back… "Passing Arguments" i.e. Giving Inputs

16 5. Vocab. "Return Values" Main script file (Project Manager) clc clear Function definition #1 Function definition #2 Function definition #n Passing data to the function Passing data to… Getting results back… "Return Values" i.e. Outputs

17 Vocabulary: Summary 1. Main script file: The script file that contains the original overall project. 2. Function definition: the actual lines of code the function has to execute. 3. Function call: the command that calls upon the execution of the code that is inside the function-definition 1. Usually placed within the main script file but can also be within another function-definition. Yes, a function can call a 1 st function that can call a 2 nd function that calls a 3 rd function,… 4. Passing arguments: giving inputs to the function definition. 5. Return info: final values that the function-definition calculated and gives back

Wrapping Up Any decent software has many many many functions. Advantages: 1. Focus/modularity 2. Portability 3. Memory efficient 4. Easy to debug Disadvantage: a lot more files to keep track of! Works like any job in real life. A big-boss delegates smaller tasks to other people. These other people may choose to delegate even more! Vocabulary: function call, function definition, passing arguments, return values 18