C++ and Object-oriented Numeric Computating For Scientists by Yang, D.

By Yang, D.

Show description

Read Online or Download C++ and Object-oriented Numeric Computating For Scientists And Engineers PDF

Best programming: programming languages books

Additional info for C++ and Object-oriented Numeric Computating For Scientists And Engineers

Example text

If the initial value of expression is false, the statement is never executed. For example, int x = 0 while (x <= 100) { cout << x << '\n' x++ } The statements inside the braces are executed until x <= 100 is no longer true. It will print out 0 1 2 : : : 100: This loop is equivalent to the following for loop. int x for (x = 0 x <= 100 x++) cout << x << '\n' The following while loop will not print out anything since the initial condition is false. int x = 10 while (x > 100) { cout << x++ << '\n' } do-while Loops The do-while statement resembles the while loop, but has the form do statement while (expression) The execution of statement continues until expression evaluates to false.

By de nition, true has the value 1 and false has the value 0 when converted to an integer. Conversely, nonzero integers can be implicitly converted to true and 0 to false. A bool variable occupies at least as much space as a char. 5 The Void Type A type that has no type at all is denoted by void. It is syntactically a fundamental type, but can be used only as part of a more complicated type. 4 Numeric Limits 15 as the base type for pointers to objects of unknown type. These points are explained later.

24 1. 12. What do you think the following program will output? 2 double double double double double double double cout cout cout cout cout cout cout cout cout z0 z1 z2 z3 z4 z5 z6 << << << << << << << << << = = = = = = = // biggest double // double epsilon x + x x * 2 epsilon/9 y/zero zero/zero z3 - z3 x + y "outputting results:\n" z0 << '\n' z1 << '\n' z2 << '\n' z3 << '\n' z4 << '\n' z5 << '\n' z6 << '\n' 1 + z2 << '\n' } Run the program on your computer to check the results. You may see In nity, NaN, and other unusual outputs.

Download PDF sample

Rated 4.23 of 5 – based on 8 votes