|
|
|
|
|
|
|
Until now, we have worked primarily with the data types int, char, and float. These three data types are adequate for solving a wide variety of problems. But certain programs need other kinds of data. In this chapter, we take a closer look at all of the simple data types that are part of the C++ language. As part of this look, we discuss the limitations of the computer in doing calculations. We examine how these limitations can cause numerical errors and how to avoid such errors. |
|
|
|
|
|
|
|
|
There are times when even the built-in data types cannot adequately represent all the data in a program. C++ has several mechanisms for creating user-defined data types; that is, we can define new data types ourselves. This chapter introduces one of these mechanisms, the enumeration type. In fact, the remainder of this book is devoted largely to introducing additional user-defined data types. |
|
|
|
|
|
|
|
|
In Chapter 2, we defined a data type as a specific set of data values (which we call the domain) along with a set of operations on those values. For the int type, the domain is the set of whole numbers from INT_MIN through INT_MAX, and the allowable operations are +, -, *, /, %, ++, --, and the relational and logical operators. The domain of the float type is the set of all real numbers that a particular computer is capable of representing, and the operations are the same as those for the int type except that modulus (%) is excluded. |
|
|
|
|
|
|
|
|
The int and float (and char) types have a property in common. Each data type is made up of indivisible, or atomic, data values. Data types with this property are called simple (or atomic) data types. When we say that a value is atomic, we mean that it has no component parts that can be accessed individually. For example, a single character of type char is atomic, but the string Good Morning is not (it is composed of several values of type char). |
|
|
|
 |
|
 |
|
|
Simple (Atomic) Data Type A data type in which each value is atomic (indivisible). |
|
|
|
|
|
|
|
|
Another way of describing a simple type is to say that only one value can be associated with a variable of that type. In contrast, a structured data type is one in which an entire collection of values can be associated with a single variable of that type. Beginning in Chapter 11, we look at structured data types. |
|
|
|
|
|