< previous page page_56 next page >

Page 56
double. Each larger size gives us a wider range of values and more precision (the number of significant digits in the number), but at the expense of more memory space to hold the number.
Floating point values also can have an exponent, as in scientific notation. (In scientific notation, a number is written as a value multiplied by 10 to some power.) Instead of writing 3.504 x 1012, in C++ we write 3.504E12. The E means exponent of base 10. The number preceding the letter E doesn't need to include a decimal point. Here are some examples of floating point numbers in scientific notation:
1.74536E-12   3.652442E4   7E20
Most programs don't need the double and longdouble types. The float type usually provides sufficient precision and range of values for floating point numbers. Even personal computers provide float values with a precision of six or seven significant digits and a maximum value of about 3.4E+38. In the Payroll program, the identifiers MAX_HOURS, OVERTIME, payRate, hours, wages, and total are all of type float because they are identifiers for data items that may have fractional parts.
We talk more about floating point numbers in Chapter 10. But there is one more thing you should know about them now. Computers cannot always represent floating point numbers exactly. You learned in Chapter 1 that the computer stores all data in binary (base-2) form. Many floating point values can only be approximated in the binary number system. Don't be surprised if your program prints out the number 4.8 as 4.7999998. In most cases, slight inaccuracies in the rightmost fractional digits are to be expected and are not the result of programmer error.
Naming Elements: Declarations
Identifiers can be used to name both constants and variables. In other words, an identifier can be the name of a memory location whose contents are not allowed to change or it can be the name of a memory location whose contents do change.
How do we tell the computer what an identifier represents? By using a declaration, a statement that associates a name (an identifier) with a description of an element in a C++ program (just as a dictionary definition associates a name with a description of the thing being named). In a declaration, we name an identifier and what it represents. For example, the Payroll program uses the declaration
int empNum;
to announce that empNum is the name of a variable whose contents are of type int. When we declare a variable, the compiler picks a location in memory to

 
< previous page page_56 next page >