Flylib.com

Books Software

 
 
 

Section 4.10. Wrap-Up


4.10. Wrap-Up

In this chapter, we presented the basic concepts of classes, objects, methods, instance variables and properties. You learned how to declare instance variables of a class to maintain separate data for each object of the class, and how to declare methods that operate on that data. You called methods and passed arguments to them. We explained the difference between a local variable of a method and an instance variable of a class. You used a class's constructor to specify the initial values for an object's instance variables . You saw how UML class diagrams model the constructors, operations, attributes and properties of classes. Finally, we demonstrated how Set accessors in properties can be used to validate an object's data and ensure that the object is maintained in a consistent state. In the next chapter we introduce control statements.



Chapter 5. Control Statements: Part 1

Let's all move one place on.

Lewis Carroll

The wheel is come full circle.

William Shakespeare, King Lear

How many apples fell on Newton's head before he took the hint?

Robert Frost

All the evolution we know of proceeds from the vague to the definite.

Charles Sanders Peirce

Objectives

In this chapter you will learn:

  • To use the If ... Then and If ... Then ... Else selection statements to choose among alternative actions.

  • To use the While , Do While ... Loop and Do Until ... Loop repetition statements to execute statements in a program repeatedly.

  • To use the compound assignment operators to abbreviate assignment operations.

  • To use counter-controlled repetition and sentinel-controlled repetition.

  • To use nested control statements.

  • To add Visual Basic code to a Windows application.

Outline

5.1 Introduction

5.2 Control Structures

5.3 If ... Then Selection Statement

5.4 If ... Then ... Else Selection Statement

5.5 While Repetition Statement

5.6 Do While ... Loop Repetition Statement

5.7 Do Until ... Loop Repetition Statement

5.8 Compound Assignment Operators

5.9 Counter-Controlled Repetition

5.10 Sentinel-Controlled Repetition

5.11 Nested Control Statements

5.12 Nested Repetition Statements

5.13 Visual Basic Programming in a Windows Application

5.14 (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System

5.15 Wrap-Up



5.1. Introduction

In this chapter and the next , we present the theory and principles of structured programming with control statementsimportant in building and manipulating objects. In this chapter, we introduce Visual Basic's If ... Then , If ... Then ... Else , While , Do While ... Loop and Do Until ... Loop control statements, five of the building blocks that allow programmers to specify the logic required for methods to perform their tasks . We devote a portion of the chapter (and Chapters 6 and 8) to further developing the GradeBook class introduced in Chapter 4. In particular, we add a method to the GradeBook class that uses control statements to calculate the average of a set of student grades. Another example demonstrates how to combine control statements by "stacking" and "nesting" to solve a particular problem. You will notice that some examples use classes and a test module to demonstrate a concept, while others use only a module. When it does not make sense to create a reusable class to demonstrate a simple concept, we write the code in the Main method of a module.

Throughout most of the chapter we use console applications to demonstrate new programming techniques. We devote one section to enhancing the Windows application you created in Chapter 2 to include your own Visual Basic code.