{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Click to edit Master subtitle style 2/5/11 Additional Operators and Math functions in C++

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

View Full Document
2/5/11 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--
2/5/11 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 ; ? 5 6 6 5 5 6 ?

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

View Full Document
2/5/11 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
2/5/11 System Mathematical Purpose Function Name Prototype/Signature Usage Notes Computes cosine cos double cos (double X); X must be 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 ]}