www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 169 (continued)]

4.14. Wrap-Up

This chapter presented basic problem-solving techniques that programmers use in building classes and developing member functions for these classes. We demonstrated how to construct an algorithm (i.e., an approach to solving a problem) in pseudocode, then how to refine the algorithm through several phases of pseudocode development, resulting in C++ code that can be executed as part of a function. You learned how to use top-down, stepwise refinement to plan out the specific actions that a function must perform and the order in which the function must perform them.


[Page 170]

You learned that only three types of control structuressequence, selection and repetitionare needed to develop any algorithm. We demonstrated two of C++'s selection statementsthe if single-selection statement and the if...else double-selection statement. The if statement is used to execute a set of statements based on a conditionif the condition is true, the statements execute; if it is not, the statements are skipped. The if...else double-selection statement is used to execute one set of statements if a condition is true, and another set of statements if the condition is false. We then discussed the while repetition statement, where a set of statements are executed repeatedly as long as a condition is true. We used control-statement stacking to total and compute the average of a set of student grades with counter- and sentinel-controlled repetition, and we used controlstatement nesting to analyze and make decisions based on a set of exam results. We introduced assignment operators, which can be used for abbreviating statements. We presented the increment and decrement operators, which can be used to add or subtract the value 1 from a variable. In Chapter 5, Control Statements: Part 2, we continue our discussion of control statements, introducing the for, do...while and switch statements.


Previous Page
Next Page