Lecture 9 –
September 24th
We discussed problems people were having with the Fractions program that
was due today
We talked about
To overload an
existing operator (+, - ,*,/) you have to put them in “ “ and define the function. We
can see how this is done in both Fractions.ads
and Fractions.adb.
We talked about how to
call one of these overloaded functions:
myFraction := Fractions.”+”(parameters)
We went over and answered the questions that were associated with Fractions.ads and Fractions.adb
and were found in Fraction.doc (Blackboard Assignment4)
Remember: Function calls always appear on the right
side of an assignment operator .
On the left side of
the operator is a variable holding the type of value returned by the function.
Every
To test the syntax of your declarations before
you do any real work, use a NULL; statement.
< > with
no space between them in
In our generic package Discrete_Set the “+” is an
overloaded operator
Three
operations come for free with private types:
Test
elements of a private type for being equal
You can
test element of a private type for being not equal
You can assign
an element of a private type to another element of a private type
We
discussed how the private type set_type is
represented in the Discrete_Set package. It is an array of Booleans with as many
elements as there are elements in the set_type.
For example,
define the enumerated type Fruit defined as shown below.
TYPE Fruit
is (apple, berry cherry);
Supposed also
that you had instantiatiated the package Discrete_Set as follows:
PACKAGE mySet IS NEW Discrete_Set (Element_Type => Fruit);
Further suppose
that you declared setA as follows.
setA : mySet.Set_type.
Further
suppose that you initialized it to the package defined constant Universal_Set as follows.
setA := mySet.Universal_Set;
The diagram
below shows what would be in
setA which is a three-element array of Booleans whose
elements can only be accessed through the functions in the Discrete_Set
package.
apple berry cherry
true |
true |
true |
If you had
initialized setA to mySet.EmptySet,
then all of the values would be false.