5.1 Introduction

This chapter continues our presentation of structured-programming theory and principles by introducing all but one of C++’s remaining control statements. We demonstrate C++’s for, dowhile and switch statements. Through examples using while and for, we explore the essentials of counter-controlled iteration. We also use compound-interest calculations to begin investigating the issues of processing monetary amounts. First, we discuss the representational errors associated with floating-point types. Then, we develop a new DollarAmount class that uses very large integers to precisely represent monetary amounts. As you’ll see, the class uses only precise integer arithmetic, thus eliminating the kind of representational errors associated with floating-point types. We use a switch statement to count the number of A, B, C, D and F grade equivalents in a set of numeric grades entered by the user. We introduce the break and continue program-control statements. We discuss C++’s logical operators, which enable you to combine simple conditions in control statements. Finally, we summarize C++’s control statements and the proven problem-solving techniques presented in this chapter and Chapter 4.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset