Programming Example 7: Methods

Introduction

As you read through this example, look for code that illustrates these important principles that relate to writing your own methods:

  1. The Method prologue: A method prologue is written above the code for the method. The method prologue contains a set of comments that describe the method. All methods that you write must contain a method prologue.
  2. The Method Header The first line of a Method is known as the method header. It tells us what the name of the method is, what it kind of data the method returns, and tells us about the parameters that must be passed to the method.
  3. The Method body: This is the code that is actually executed when the method is invoked. When the method is done doing its work, control always returns to the point where the method was invoked.
  4. Method Invocation: The method invocation is the code that calls the method, and causes it to be executed. The method invocation is responsible for passing any arguments to the method.

The problem statement for this program is located here.

The example program is located here.  An executable of this program can be found here.