1 / 10

C++ Arithmetic and Assignment Operators: Nuts and Bolts Explained in Chapter 5

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++.

rgrissom
Download Presentation

C++ Arithmetic and Assignment Operators: Nuts and Bolts Explained in Chapter 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5NUTS AND BOLTS: STANDARD STUFF IN C++

  2. Chapter 5 • The C++ Arithmetic Operators • Addition + • Subtraction – • Multiplication  • Division / • Modulus (remainder) % • Increment ++ • Decrement _ _

  3. Chapter 5 • Order of Precedence ( ) evaluated first, inside-out. , /, or % evaluated second, left-to-right. +,  evaluated last, left-to-right.

  4. 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.

  5. Chapter 5 • The C++ Assignment Operators • Simple assignment = • Addition/assignment += • Subtraction/assignment = • Multiplication/assignment = • Division/assignment /= • Modulus/assignment %=

  6. Chapter 5 • Conversion Functions • toascii() Converts a character to its ASCII value. • tolower() Converts a character to lowercase. • toupper() Converts a character to uppercase.

  7. 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.

  8. 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).

  9. 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.

  10. Chapter 5 • Generating A Random Number Between 0 and 99 srand(1);randomValue = rand() % 100;

More Related