Chapter 2 - Fundamental data types. numbers and character strings (such as the ones on this display board) are important data types in any C++ program. In this chapter, you will learn how to work with numbers and text, and how to write simple programs that perform useful tasks with them. | C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Goals To be able to define and initialize variables and constants To understand the properties and limitations of integer and floating-point numbers To write arithmetic expressions and assignment statements in C++ To appreciate the importance of comments and good code layout To create programs that read and process input, and display the results To process strings, using the standard C++ string type Variables A variable is used to store information: can contain one piece of information at a time. has an identifier: The programmer picks a good name A good name describes the contents of the variable or what the variable will be used for the contents of the variable: the name of the variable C++ for Everyone by Cay Horstmann Copyright | C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Goals To be able to define and initialize variables and constants To understand the properties and limitations of integer and floating-point numbers To write arithmetic expressions and assignment statements in C++ To appreciate the importance of comments and good code layout To create programs that read and process input, and display the results To process strings, using the standard C++ string type Variables A variable is used to store information: can contain one piece of information at a time. has an identifier: The programmer picks a good name A good name describes the contents of the variable or what the variable will be used for the contents of the variable: the name of the variable C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Variables Parking garages store cars. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Each parking space is identified – like a variable’s identifier Variables A each parking space in a garage “contains” a car – like a variable’s current contents. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Variables and each space can contain only one car and only cars, not buses or trucks C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Variable Definitions When creating variables, the programmer specifies the type of information to be stored. (more on types later) Unlike a parking space, a variable is often given an initial value. Initialization is putting a value into a variable when the variable is created. Initialization is not required. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. .