Subprograms are the conventional parameterized unit of programming. In Ada, subprograms fall into two categories: Functions and Procedures. This lab covers the subject of Functions in Ada.
Functions are called as components of expressions and return a value as part of the expression, whereas procedures are called as statements standing alone. Functions, and in general subprograms, are composed of a specification part and a body part . A Function generally takes arguments (parameters). Functions without arguments often return a constant value. This may be useful for inheritance purposes.
In this lab, we will try to implement Newton's formula to compute (x + y)n where x and
y are Real numbers and n a positive Integer.
Remember that Newton's Formula (also called Binome Formula) is :
where x and y are Real numbers (Float will be used to implement Real numbers) and n is a
positive integers. The problem will be decomposed in three small problems to illustrate
the devide-and-conquer strategy. Each of the problems consist in writing an Ada function.
The student should also write test procedures to test the implemented functions.
Problem 3 (OPTIONAL): Binome's formula (Newton's formula)
Using Functions written in Problems 1 and 2, write a function that takes as arguments two
reals x, y and a postive integer n then computes (x+y)n using Newton's
formula given above.
Example of execution:
*******************************************
********* Newton's formula ****************
*******************************************
Enter two reals : 5.0 3.0
Enter a positve integer : 2
The result is : 64