1 Math Expressions and Operators
2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division % Modulus (remainder) +Addition - Subtraction Lower = Assignment
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 means ( )
4 7 * % 3 * means (7 * 10) - 5 % 3 * % 3 * (5 % 3) * * ( 2 * 4 ) ( ) Evaluate the Expression
5 What value is stored? var a; var b; a = 8.5; b = 9.37; a = b; a b a b ? ?
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 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) sqrt(x) sqrt(2.0) abs(i) abs(-6) 6
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 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 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