Review Loops – Condition – Index Functions – Definition – Call – Parameters – Return value.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

CPSC 388 – Compiler Design and Construction
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 13 Fall 2010.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Trigonometry Right Angled Triangle. Hypotenuse [H]
Sine, Cosine, Tangent, The Height Problem. In Trigonometry, we have some basic trigonometric functions that we will use throughout the course and explore.
Trigonometric Ratios Contents IIntroduction to Trigonometric Ratios UUnit Circle AAdjacent, opposite side and hypotenuse of a right angle.
Honors Geometry Section 10.3 Trigonometry on the Unit Circle
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
1 Modularity In “C”. 2 General Syntax data_type function_Name (parameter list) { … return expression; // return output } Body of the function is a compound.
Lecture 3 IAT 800. Sept 15, Fall 2006IAT 8002 Suggestions on learning to program  Spend a lot of time fiddling around with code –Programming is something.
UNIT CIRCLE. Review: Unit Circle – a circle drawn around the origin, with radius 1.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Block Scope By Greg Butler Purpose The purpose of this presentation is to familiarize the student with the concept of variable scope, as it relates to.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
1 Storage Classes, Scope, and Recursion Lecture 6.
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
Scope Accessibility of Names. Review We’ve seen that C++ permits a programmer to declare names and then use those names in a manner consistent with their.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing & using functions  How to declare them, use them, & trace them  Could write programs.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Introduction to the Unit Circle in Trigonometry. What is the Unit Circle? Definition: A unit circle is a circle that has a radius of 1. Typically, especially.
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
PROCESSING Methods. Objectives Be able to define methods that return values Be able to define methods that do not return values Be able to use random.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
2-D Shapes, Color, and simple animation. 7 Basic Shapes Ellipse :: ellipse() Arc :: arc() Line :: line() Point :: point() Rectangle :: rect() Triangle.
Introduction to Trigonometry What is Trigonometry? Trigonometry is the study of how the sides and angles of a triangle are related to each other. It's.
7.2 Finding a Missing Side of a Triangle using Trigonometry
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Finding a Missing Angle of a Right Triangle. EXAMPLE #1  First: figure out what trig ratio to use in regards to the angle.  Opposite and Adjacent O,A.
1 Lecture 3 Part 2 Storage Classes, Scope, and Recursion.
Trigonometric Functions. A Block Data B Block Data.
Function 2. User-Defined Functions C++ programs usually have the following form: // include statements // function prototypes // main() function // function.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Review Array – int[] diameters = new int[10]; – diameters[0], diameters[2], diameters[9] – diameters.length Indexing starts at 0 A way to have a collection.
Review Expressions and operators Iteration – while-loop – for-loop.
[10.3] Tangents Circle Vocab. [10.3] Tangents Circle Vocab.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
User-Defined Functions (cont’d) - Reference Parameters.
(1) Sin, Cos or Tan? x 7 35 o S H O C H A T A O Answer: Tan You know the adjacent and want the opposite.
Chapter 13 Right Angle Trigonometry
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
Trigonometry Mini-Project Carlos Velazquez 6/4/13 A block.
9.5: Trigonometric Ratios. Vocabulary Trigonometric Ratio: the ratio of the lengths of two sides of a right triangle Angle of elevation: the angle that.
 2000 Prentice Hall, Inc. All rights reserved Program Components in C++ Function definitions –Only written once –These statements are hidden from.
Trigonometric Ratios Section 8.1. Warm Up State the following: 1.Angle opposite AB 2.Side opposite angle A 3.Side opposite angle B 4.Angle opposite AC.
How would you solve the right triangles: 1)2) 12 x 1663° x y 14 28°
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
TRIGONOMETRY AND THE UNIT CIRCLE SEC LEQ: How can you use a unit circle to find trigonometric values?
The Unit Circle and Circular Functions Trigonometry Section 3.3.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
Advanced Programming in C
Test 2 Review Outline.
The Lifetime of a Variable
C Functions -Continue…-.
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
20 minutes maximum exhibits
Scope, Visibility, and Lifetime
Chapter 10 Algorithms.
Chapter 10 Algorithms.
LCC 6310 Computation as an Expressive Medium
Chapter 10 Algorithms.
How About Some PI? Trigonometry Feb 18,2009.
Continuous & Random September 21, 2009.
Scope Rules.
Presentation transcript:

Review Loops – Condition – Index Functions – Definition – Call – Parameters – Return value

Execution Statements are executed one at a time in the order written Execution order – Globals and initializations – setup() called once – draw() called repeatedly – If any mouse or keyboard events occur, the corresponding functions are called between calls to draw() – exact timing can not be guaranteed.

Variable Scope The region of code in which a particular variable is accessible. To a first approximation, the scope of a section of your code is demarcated by { and }. – Functions – Loops – Conditionals A variable is only accessible/available within the scope in which it is declared.

Variable Lifetime Variables cannot be referenced before they are declared. A variable is created and initialized when a program enters the block in which it is declared. – Functions – Loops – Conditionals – Function parameters A variable is destroyed when a program exists the block in which it was declared.

Global variables Variables that are declared outside of any scope are considered globals (versus locals). Global variables should be declared at the top of your program. Do not sprinkle them between functions!

Shadowing When there is a name conflict between variables of different scopes int x = 10; void setup() { int x = 5; int y = x; } The conflicting variables can not have different types (or it’s considered a re-declaration and is not allowed) When shadowed, smaller (inner) scopes have precedence over larger (outer) scopes

int a = 20; void setup() { size(200, 200); background(51); stroke(255); noLoop(); } void draw(){ line(a, 0, a, height); for(int a=50; a<80; a += 2) { line(a, 0, a, height); } int a = 100; line(a, 0, a, height); drawAnotherLine() drawAnotherLine(); drawYetAnotherLine() drawYetAnotherLine(); } void drawAnotherLine() { int a = 185; line(a, 0, a, height); } void drawYetAnotherLine() { line(a+2, 0, a+2, height); } What is drawn?

Basics of Trigonometry q h (hypotenuse) a (adjacent) o (opposite )

Definition sin (q) = o/h o = h*sin (q) cos (q) = a/h a = h*cos (q) tangent (q) = o/a = sin (q)/ cos (q)

Trigonometry on a unit circle q r p 0°0° 90 ° origin

Trigonometry on a unit circle q r p 0°0° 90 °

Trigonometry on a unit circle 0°0° 90 ° q

Drawing points along a circle int steps = 8; int radius = 20; float angle = 2*PI/steps; for (int i=0; i<steps; i++) { float x = cos(angle*i)*radius; float y = sin(angle*i)*radius; // draw a point every 1/8th of a circle ellipse(x, y, 10, 10); }