Lecture 16 – October 19th
Exam
will be next Thursday, October 26th
during the regular class period in the lab.
It will be a paper exam. It may
include writing code but you will not use the computer to do this. Please try to come early. My exams are usually long and I will come at
9:15 (when the previous class ends) and you may begin as soon as you get
here. You will need to finish by the end
of the class period.
Submission
deadline for you Queue programs has been extended to 9pm tonight (October 19th)
without penalty. After that it will be
counted late and you will lose 10 points per day. It will be graded over the weekend so if you
don’t turn it and the folder in by noon tomorrow, you may not get it back
graded before the exam.
The
first thing we did in class today was to download the generic swap
specification and implementation and the skeleton of the program to use the
generic and complete the skeleton.
First
we tested it with integers.
Then we tested it with characters.
Then we tested it with floats
Then we tested it with fixed length strings
Then we tested it with records
Subtype
myString is String(1..5) -- example of subtype declaration
With
ada.float_text_io; -- is the with clause for floating
point numbers
Procedure
printFloat is
Value : float;
Begin
Value :=
62.367;
-- to
avoid exponential notation in printout of floating point number use
ada.float_text_io.put
( num => value, fore => 5, aft => 3, exp
=> 0);
end printFloat;
We
talked abstractly about how we could modify our Stack packages so that they
could handle stacks of floats, characters, strings or records instead of just
integers.
Here is the original stack specification
WITH ada.integer_text_io; PACKAGE stack IS StackFull :
exception; --
added to original specification StackEmpty : exception;
-- added to original specification TYPE myArrayType IS ARRAY (1..20) of integer; TYPE aStack IS RECORD anArray : myArrayType; Top : integer; END
RECORD; PROCEDURE makeEmpty (someStack : IN OUT aStack; PROCEDURE push (someStack
:IN OUT aStack;
someValue : IN integer); PROCEDURE pop (someStack
: IN OUT aStack;
someValue : OUT
integer); FUNCTION isFull (someStack : IN aStack) RETURN boolean; FUNCTION isEmpty (someStack : IN aStack) RETURN boolean; PROCEDURE peek (someStack
: IN aStack;
someValue : OUT integer);
-- could be a function END stack; |
An
outline of the necessary changes to the specification to make it generic is
here
GENERIC TYPE
Element IS PRIVATE; PACKAGE Stacks_Generic
IS TYPE
aStack
(Capacity: Positive) IS LIMITED PRIVATE; StackFull : EXCEPTION; StackEmpty :
EXCEPTION; PROCEDURE makeEmpty (someStack : IN OUT aStack; PROCEDURE push (someStack
:IN OUT aStack;
someValue : IN Element); PROCEDURE pop (someStack
: IN OUT aStack;
someValue : OUT
Element); FUNCTION isFull (someStack : IN aStack) RETURN boolean; FUNCTION isEmpty (someStack : IN aStack) RETURN boolean; PROCEDURE peek (someStack
: IN aStack;
someValue : OUT Element); PRIVATE TYPE List
IS ARRAY ( TYPE aStack (Capacity : Positive)IS RECORD
Stuff : List (1..Capacity); Top
: integer := 0; END RECORD; END
Stacks_Generic; |
HOMEWORK:
1.
bring
your books to class
2.
start studying for the test.
a.
I
suggest you review all the notes
b.
Go
through the index of the text and highlight the things we have talked about and
look at the pages on which they are discussed
3.
review your stack programs and make sure that everything you submitted
worked and that the specification corresponds to what
is above in
a.
specifications
b.
implementations
c.
test
program
4.
begin work on your generic stack programs using the
guidelines discussed in class. We will
discuss what you are having difficulty with at a future class before they are
due.