CH04 - An Introduction to Programming with C+, Fifth...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction to Programming with C++, Fifth Edition 4 - 1 Chapter 4 Variables, Constants, and Arithmetic Operators At a Glance Instructor’s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Topics Classroom Activities/Additional Projects Key Terms
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
An Introduction to Programming with C++, Fifth Edition 4 - 2 Lecture Notes Chapter Overview While variables and arithmetic operators were mentioned in the previous chapter, this chapter will introduce the student to a more in-depth understanding of each. The formatting of numeric output will also be discussed. Chapter Objectives After completing the chapter, the student will be able to: Distinguish among a variable, a named constant, and a literal constant Explain how data is stored in memory Declare and initialize a memory location Use an assignment statement to assign data to a variable Include arithmetic operators and arithmetic assignment operators in an expression Get string input using the getline() function Ignore characters using the ignore() function Format floating-point output Write simple .NET C++ commands Instructor Notes More on the Problem-Solving Process The completed program from the previous chapter is shown in Figure 4-1 on page 154. Notice the new components that will be detailed in this chapter. Variables and Named Constants When coding the program from the IPO chart, you will want to assign names, data types, and initial values the IPO items. In C++, two types of memory locations are available for you to temporarily store data; these are variables and named constants. The difference between the two is that values stored in named constants are not allowed to change while the program is executing (they are constant throughout the program), whereas the contents of a variable are allowed to change.
Background image of page 2
An Introduction to Programming with C++, Fifth Edition 4 - 3 Selecting a Name for a Memory Location While most C++ programmers use lowercase for names of memory locations, if names are more than one word, then the beginning of the second word is capitalized to stand out. Remember that in most programming languages, identifier names can consist of letters, numbers, and maybe an underscore. However, they cannot include punctuation characters or spaces. The actual rules for naming identifiers in C++ are covered in Figure 4-3 on page 157. Selecting a Data Type for a Memory Location After naming the item, a data type must be chosen. The data type specifies the type of data that the item is permitted to store (for example, whether a number would have a decimal in it or whether it would be an integer). Figure 4-5 on page 158 lists some of the most commonly used data types available in C++. Note that the String data type is not one of the fundamental data types available in C++. In order to use the String data type, you must create an object using the String class, which is part of Visual C++. Classes will be covered in greater detail in later
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CS 343 taught by Professor Katzman during the Spring '09 term at ITT Tech Tucson.

Page1 / 11

CH04 - An Introduction to Programming with C+, Fifth...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online