{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

This preview shows pages 1–6. Sign up to view the full content.

Additional Operators and Math functions in C++

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Increment & Decrement  Operators Increment operator: increase variable by 1 Decrement operator: decrease variable by 1 Pre-increment: ++variable Post-increment:  variable++   Pre-decrement:  --variable Post-decrement:  variable--
Increment & Decrement Operators ++count;  or  count++;  increases the value of  count  by  1 --count;  or  count--;  decreases the value of  count  by   1 If  x = 5;  and  y = ++x;    x y it is the same as 2 statements  x = x + 1;   y = x ;  After the second statement both  x  and  y  are  6 If  x = 5;  and  y = x++;   it is the same as 2 statements  y = x ;  x = x + 1;  After the second statement  y  is  5  and  x  is  6 ? 5 6 6 5 5 6 ?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Assignment Statements C++ has special assignment statements called  compound assignment:   += -= *= /= , and  %= Example:  x y a int  x = 2, = 3, a = 4 ;  2 3 4 x *= y;  x = x * y ; 6 3 4 x += y + 2 ;  x = x + (y + 2) ;11 3 4 x -= y;  x = x – y ; 8 3 4 x /= y + a - 3 ;  x = x/(y+ a - 3);2 3 4 x %= y ;  x = x % y ; 2 3 4 x %= y -1 ;  x = x % (y-1); 0 3 4 y /= x + 2;  y = y / (x + 2) ; 0 1 4 a /= ++x + y++;  a=a/(++x + y++); 1 2 2 ++x; a = a /(x+y) ; y++;
System Mathematical Functions Purpose Function Name Prototype/Signature Usage Notes Computes cosine cos double cos (double X); X must be in radians! Computes sine sin double sin (double X); Computes tangent tan double tan (double X); Computes arc cosine acos double acos (double X); Return value is in radians.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}