Review of Ada approach to problem solving

 

Step 1 – design Specification remembering to only put in the spec what you want the applications program to have access to.

 

 

package  solveProblem is

type someArrayType is array (1..7) of integer;

 

procedure doTask1 (i : in integer);

 

procedure doTask2 (a : in out float; b  : in character);

 

  procedure doTask3 (m : in out someArrayType);

 

end solveProblem;

 

Step 2 – stub out the package body (implementation of package) with required elements remembering that you can add additional procedures, functions, etc. as you discover you need them.   If they do not need to be available to the applications program they are not required to be added to the specification.

 

package body solveProblem is

 

--procedure doTask1 (i : in integer);   copied from specification as a guide

procedure doTask1 (i : in integer) is

  begin

   null;

  end doTask1;

 

--procedure doTask2 (a : in out float; b : in character);  copied from specification as a guide

procedure doTask2 (a : in out float; b : in character) is

  begin

    null;

  end doTask2;

 

 

--procedure doTask3 (m : in out someArrayType);   copied from specification as a guide

procedure doTask3 (m : in out someArrayType) is

  begin

    null;

  end doTask3;

 

end solveProblem;

 

 

Step 3 :  write applications program that uses the package (could be a program to test your specification and implementation.  You can compile this to catch syntax errors and omissions of declarations.  Then you can go back to implementation and fill in code for one procedure/function at a time and recompile.

 

 

 WITH solveProblem;

 procedure mySolveProblem is

    myArray : solveProblem.someArrayType;

   myFloat : float := 0.0;

 begin

    solveProblem.doTask1 (i=>5);

    solveProblem.doTask2 (a =>myFloat,  b=> 'a');

    solveProblem.doTask3 (m =>myArray);

 end mySolveProblem;