|
|
|
|
|
|
|
Much of the computation of a program is performed in arithmetic expressions. Expressions can contain more than one operator. The order in which the operations are performed is determined by precedence rules. In arithmetic expressions, multiplication, division, and modulus are performed first, then addition and subtraction. Multiple arithmetic operations of the same precedence are grouped from left to right. You can use parentheses to override the precedence rules. |
|
|
|
|
|
|
|
|
Expressions may include function calls. C++ supports two kinds of functions: value-returning functions and void functions. A value-returning function is called by writing its name (and parameter list) as part of an expression. A void function is called by writing its name (and parameter list) as a complete C++ statement. |
|
|
|
|
|
|
|
|
The C++ standard library is an integral part of every C++ system. The library contains many prewritten functions that any programmer can use. These functions are accessed by using #include directives to the C++ preprocessor, which inserts the appropriate header files into the program. |
|
|
|
|
|
|
|
|
Designing a program includes careful attention to the output format. Output should be clear, understandable, and neatly arranged. Messages in the output should describe the significance of values. Blank lines (produced by successive uses of the endl manipulator) and blank spaces within lines help to organize the output and improve its appearance. |
|
|
|
|
|
|
|
|
In output statements, the setw and setprecision manipulators control the appearance of values in the output. These manipulators do not affect the values actually stored in memory, only their appearance when displayed on the standard output device. |
|
|
|
|
|
|
|
|
Not only should the output produced by a program be easy to read, but the format of the program itself should be clear and readable. C++ is a freeformat language. A consistent style that uses indentation, blank lines, and spaces within lines helps you (and other programmers) understand and work with your programs. |
|
|
|
|
|
|
|
|
1. What is the result of evaluating the expression |
|
|
|
 |
|
|
|
|
(1 + 2 * 2) / 2 + 1 |
|
|
|
 |
|
|
|
|
(pp. 9495) |
|
|
|
|
|