Lecture 17 - October 22, 2007
Discussion of problems found in Queue ADT test programs
Discussion of problems found in completing the Sort Program
If you get a constraint_error and your parogram has an array in it, first thing to suspect is that you are exceeding the bounds of the array.
First thing to do is to insert DEBUGGING STATEMENTS which print out the indexes you are trying to access.
If you don’t have an array in your program and you get a constraint_error, what might be wrong is
You might be going out of the range of allowable values for a data type.
If your program has to do several separate things, then as soon as it does one of them correctly, delete that from your code and work on the next thing. Be sure to save the deleted code somewhere.
Proabably the easiest thing is to rename the code from which you deleted and work from that new code.
For the exam we have to know
Bubble sort
Selection sort
Insertion sort
Quicksort
Know what a specification is
Know what the body of a specification contains
When given a .ads file, you can’t change it.
Everything in the .ads file MUST be implemented in the .adb body for the specification.
You can add any helper functions you think you can use to the specification without altering the spec.
If your program gives you a compile time error message saying it doesn’t know about ada, you probably are trying to print and forgot a with statement or two.
When you are writing a TEST PROGRAM, you are not writing a program for the user to use your ADT, you are trying to make sure that it works correctly so that when you write a program for the user to use your ADT, it will do what it’s supposed to do.
When you test a program, your output should say:
What you are testing
What you expect
What you got.
When you are writing a QUEUE ADT, the only way to show the queue is to empty it (deleting an item at a time and printing it.). Unfortunately just doing that, leaves you with an empty queue which is not what you wanted. Going through the array (which you aren’t supposed to know about) isn’t really kosher . There are three ways (or more) to show the queue without violating the QUEUE ADT concept.
One : copy the queue before you show it.
Two make another empty queue; every time you delete something from the queue, put it on the temp queue.
Third: determine the number of elements in the queue; repeat the following for the number elements in the queue; delete the first element and print it; then add it to the end of the queue;
If you want to, you can create user-defined exceptions.
First: declare it example: queueFull : exception;
Second: raise in appropriate place example: if ourQueue.sizeOfThing(myQ) = 20 then
Raise queueFull;
If (ourQueue.isThingFull(myQ) then
raise queueFull;
Third: handle it example: exception
When queueFull => ada.text_io.put_line (“ can not add to a full queue “);
Discrete_Sets
Fractions
Queue ADT implementation using arrays
Queue ADT implementation using linked list
Sort Program
BinarySearchTest
RandomNumberGenerator
all the other things
in the notes!