Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Math Expressions and Operators. 2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division.

Similar presentations


Presentation on theme: "1 Math Expressions and Operators. 2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division."— Presentation transcript:

1 1 Math Expressions and Operators

2 2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division % Modulus (remainder) +Addition - Subtraction Lower = Assignment

3 3 Associativity l left to right Associativity means that in an expression having 2 operators with the same priority, the left operator is applied first l in C++ the binary operators *, /, %, +, - are all left associative l expression 9 - 5 - 1 means ( 9 - 5 ) - 1 4 - 1 3

4 4 7 * 10 - 5 % 3 * 4 + 9 means (7 * 10) - 5 % 3 * 4 + 9 70 - 5 % 3 * 4 + 9 70 - (5 % 3) * 4 + 9 70 - 2 * 4 + 9 70 - ( 2 * 4 ) + 9 70 - 8 + 9 ( 70 - 8 ) + 9 62 + 9 71 Evaluate the Expression

5 5 What value is stored? var a; var b; a = 8.5; b = 9.37; a = b; a b a b 8.5 9.37 ? ?

6 Built-in Variables l mouseX - current x position of the mouse cursor l mouseY - current y position of the mouse cursor l width - width of the screen l height - height of the screen l PI 6

7 7 FUNCTION EXAMPLE VALUE OF CALL abs(x) abs(-6.4) 6.4 pow(x,y) pow(2.0,3.0) 8.0 sqrt(x) sqrt(100.0) 10.0 log(x) n.log log(2.0).693147 sqrt(x) sqrt(2.0) 1.41421 abs(i) abs(-6) 6

8 More Functions Calculations l abs() l ceil() l dist() – between 2 pts l exp() l floor() l log() – common log l max() - largest value l min() – smallest value l pow() l round() l sq() l sqrt() Trigonometry l sin() l cos() l tan() l acos() l asin() l atan() l degrees() - rad to deg l radians() - deg to rad 8

9 9 Write C++ Expressions for The square root of b 2 - 4ac sqrt ( b*b - 4.0*a*c ) The square root of the average of myAge and yourAge sqrt ( ( myAge + yourAge ) / 2. )

10 10 Draw Function var draw = function() { : point(random(400), random(400)); : } l Executes repeatedly l Default frameRate is 60 fps (less on slower computer) l frameCount n # frames drawn


Download ppt "1 Math Expressions and Operators. 2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division."

Similar presentations


Ads by Google