100 likes | 116 Views
Learn about the standard arithmetic and assignment operators in C++, including addition, subtraction, multiplication, division, modulus, increment, and decrement. Explore order of precedence, preincrement vs postincrement, and conversion functions. Discover math functions like abs, acos, sin, sqrt, and more. Convert degrees to radians for trig functions. Generate random numbers in C++.
E N D
Chapter 5 • The C++ Arithmetic Operators • Addition + • Subtraction – • Multiplication • Division / • Modulus (remainder) % • Increment ++ • Decrement _ _
Chapter 5 • Order of Precedence ( ) evaluated first, inside-out. , /, or % evaluated second, left-to-right. +, evaluated last, left-to-right.
Chapter 5 • Increment/DecrementIf a variable is preincremented or predecremented within an expression, the variable is incremented/decremented before the expression is evaluated. On the other hand, if a variable is postincremented or postdecremented within an expression, the variable is incremented/decremented after the expression is evaluated.
Chapter 5 • The C++ Assignment Operators • Simple assignment = • Addition/assignment += • Subtraction/assignment = • Multiplication/assignment = • Division/assignment /= • Modulus/assignment %=
Chapter 5 • Conversion Functions • toascii() Converts a character to its ASCII value. • tolower() Converts a character to lowercase. • toupper() Converts a character to uppercase.
Chapter 5 • Math Functions • abs() Returns the absolute value of the argument. • acos() Returns the arc cos of the argument (radians). • asin() Returns the arc sin of the argument (radians). • atan() Returns the arc tan of the argument(radians). • cos() Returns the cosine of the argument (radians). • hypot(a,b) Returns the hypotenuse of a right triangle. • log() Returns the natural log of the argument. • log10() Returns the base 10 log of the argument.
Chapter 5 • Math Functions (continued) • pow(x,y) Returns x raised to the power of y. • pow10(y) Returns 10 raised to the power of y. • rand() Generates random number. • srand() Initializes the random-number generator . • sin() Returns the sine of the argument (radians). • sqrt() Returns the square root of the argument. • tan() Returns the tangent of the argument (radians).
Chapter 5 • Trig Functions Evaluate Radians, Not Degrees • The standard trig functions in the C++ math.h header file evaluate radians, not degrees. Multiply degrees by PI/180 within the trig function argument to convert degrees to radians.
Chapter 5 • Generating A Random Number Between 0 and 99 srand(1);randomValue = rand() % 100;