1 / 13

Programmer-defined Functions Vocabulary

Programmer-defined Functions Vocabulary. More precise Global Idea Vocabulary. General Concept, cont. fuelsize.m. Applied to the Rocket Project…. Huntsville, Alabama. geometry.m. cost.m. engine.m. THE CLIENT. structure.m. orbit.m. fuel.m.

quanda
Download Presentation

Programmer-defined Functions Vocabulary

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. Programmer-defined FunctionsVocabulary More precise Global Idea Vocabulary

  2. General Concept, cont. fuelsize.m Applied to the Rocket Project… Huntsville, Alabama. geometry.m cost.m engine.m THE CLIENT structure.m orbit.m fuel.m PARSEC (the Preliminary Analysis of Revolutionary Space Exploration Concepts) at NASA, in Huntsville, Alabama (2005)

  3. Overall, it may seem to work like this Programmer-defined Function #1 Programmer-defined Function #2 The client gives requirements: initial inputs. Programmer-defined Function #3 Programmer-defined Function #4 Results the client wanted!

  4. In reality, there is a boss (project manager) Task 1 The client initial data. Task 2 Project Manager Results the client wanted! Task 3 This may seem similar to EGR101 projects where, within a team, students had to split a project into smaller tasks.

  5. In reality, there may also be sub-tasks Task 1.1 Task 1 Task 1.2 The client initial data. Task 2 Project Manager Results the client wanted! Task 3

  6. 4. Vocabulary How does this relate to programming? Function definition #1 Function call, passarguments Main script file clc clear Return info Function call, passarguments Function definition #2 Return info Function call, passarguments Function definition #n (Project Manager) Return info

  7. Vocabulary, cont. Main script file • Main script file: The script file that contains the original overall project. • Function definition: the function header and the actual lines of code the function has to execute. (a little file for each new keyword) • Function call: the command that calls upon the execution of the code that is inside the function definition • Usually placed within the main script file, but can also be within another function definition. (A function CAN call another function you made!) • Passing arguments: giving inputs to the function definition. • Return info: final variables that the function definition calculated and gives back • Collection variables: The variables which receive the return info Function definition Function call, passarguments Return info result =

  8. Vocabulary: example1 • How many function calls does this program have? clc clear %ask user for angle angle = input('Enter an angle in degrees: '); %calculate sine of the angle, display results result = sind(angle); fprintf('sine of %.2f degrees is %.2f\n', angle, result) • 1 • 2 • 3 • 4 • 5

  9. Example, cont. clc Function call Main script file clc clear no return info clear (Project Manager) Function call no return info Function call, pass‘Enter an angle….’ input() %collect angle = Return value Function call, pass angle sind() %collect result = Return value Function call, pass‘string’, angle, result IGNORE return info fprintf() Return-info

  10. Vocabulary: example2 • How many function calls does this program show? clc clear %generate random value to evaluate grade grade = rand*100; %find what letter that is, display result letterGrade = changeToLetter(grade); fprintf('With a grade of %.2f, that''s a(n) %c\n', grade, letterGrade) • 1 • 2 • 3 • More than 3

  11. Example, cont. clc Function call Main script file clc clear no return info clear (Project Manager) Function call no return info Function call, (pass nothing) rand %collect grade = Return value Function call, passgrade changeToLetter() %collect letterGrade = Return result Function call, pass‘string’, grade, letterGrade IGNORE return info fprintf() Return-info

  12. Visual Example: Ordering Pizza 1. you place a call. Pizza Place: crust ingredient1 ingredient2 … 2. pass arguments: 'thin crust' 'pepperoni' 'cheese' 3. execute code (many variables used) 5. collect the result! 4. returnsa result

  13. Key Points • Be able to name each step in order, and describe them • Be able to define each of the following: • main file • function definition • passing arguments • return values • collecting return-values

More Related