Evaluation of a Second-Degree Polynomial

To develop a better understanding of the rules of operator precedence, consider the evaluation of a second-degree polynomial y = ax2 + bx + c:

Image

The circled numbers indicate the order in which C++ applies the operators. There is no arithmetic operator for exponentiation in C++, so we’ve represented x2 as x * x. In Chapter 5, we’ll discuss the standard library function pow (“power”) that performs exponentiation.

Suppose variables a, b, c and x in the preceding second-degree polynomial are initialized as follows: a = 2, b = 3, c = 7 and x = 5. Figure 2.8 illustrates the order in which the operators are applied and the final value of the expression.

Image

Fig. 2.8. Order in which a second-degree polynomial is evaluated.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.17.64