1 / 8

Basic Problem Solving with Programming - Functions

Basic Problem Solving with Programming - Functions. Functional Decomposition.

zahi
Download Presentation

Basic Problem Solving with Programming - Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Problem Solving with Programming - Functions

  2. Functional Decomposition • Functional Decomposition in computer science, also known as factoring, refers to the process by which a problem or algorithm is broken down into parts that are easier to conceive, understand, program, reuse, and maintain.

  3. Functional Decomposition Example • You are to program a small Lego Mindstorm robot holding a marker to draw numbers on the ground. • Do you write a separate function for each digit? 10 total? • Or is there a way to abstract away the numbers and concentrate on the types of lines needed?

  4. What is a Function? • A Discrete Piece of Code that Performs a Specific Operation or Task • Named with a Descriptive Identifier • Called with optional arguments from somewhere else in your program • When Called, Program Control (Execution) Is Transferred to the Function • Function Performs Required Tasks, and then Possibly Returns a Value (or values) • After Return from Function, Control Returns to the Statement Following the Function Call

  5. Function Attributes • Function Name: Identifier Used to Call Function • Function Parameter(s) or Argument(s): Optional Value(s) Passed into Function for Use by Function Code • Function Return Value: Optional Value Returned by Function Back to Calling Function

  6. Function Parameters (Arguments) • May Pass as Many Parameters as Necessary to Function • A Copy of the Value of the Parameter Is Passed to the Function • Changing the Value of the Parameter in the Function Does Not Affect the Value of the Original Variable • This Is Called Pass-by-Value

  7. Function Return Value • No return value is required. Some functions just output something or perform some operations. • Most programming languages allow a function to return a value. Some allow returning of multiple values.

  8. Library Functions • Programming languages provide various libraries of commonly used functions • API (Application Programming Interface) defines how to the programmer how to call the function, what parameters are required and assumptions are made. • Scratch/BYOB provides the following function libraries: - Motion - Looks - Sound - Pen - Sensing - Operator (math functions)

More Related