C++ for Programmers: Control Statements: Part 1
- 4.1 Introduction
- 4.2 Control Structures
- 4.3 if Selection Statement
- 4.4 if...else Double-Selection Statement
- 4.5 while Repetition Statement
- 4.6 Counter-Controlled Repetition
- 4.7 Sentinel-Controlled Repetition
- 4.8 Nested Control Statements
- 4.9 Assignment Operators
- 4.10 Increment and Decrement Operators
- 4.11 (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System
- 4.12 Wrap-Up
Get an introduction to C++'s if, if...else and while statements, three of the building blocks that allow you to specify the logic required for member functions to perform their tasks. Also learn to use while repetition statement, counter-controlled repetition and sentinel-controlled repetition, and the increment, decrement and assignment operators.
The following excerpt is from the 1st edition of "C++ for Programmers" ©2009.
4.1 Introduction
In this chapter, we introduce C++'s if, if...else and while statements, three of the building blocks that allow you to specify the logic required for member functions to perform their tasks. We devote a portion of this chapter (and Chapters 5 and 7) to further developing the GradeBook class introduced in Chapter 3. In particular, we add a member function to the GradeBook class that uses control statements to calculate the average of a set of student grades. Another example demonstrates additional ways to combine control statements to solve a similar problem. We introduce C++'s assignment operators and explore C++'s increment and decrement operators. These additional operators abbreviate and simplify many program statements.