Programming Languages Practical Course
Ada AssignmentMelanie Rieback
CS Dept., R4.23
The objective of this exercise is to check the overall understanding of the Ada language and --- more specifically --- the task and the generic package features of Ada.
ExerciseWrite a generic parallel merge-sort program in Ada. Let R be an array of n elements. If n=1, then R is sorted. If n>1, split R into two (almost) identical sub-arrays R1 and R2. For each of these two sub-arrays, start a new Ada task to sort it recursively. Once both parallel tasks are finished with sorting their respective sub-array, merge the two sorted sub-array.
-- Parallel merge sort algorithm -- - If n = 1 then R is sorted - If n > 1 then recursively sort the two half parts of R in parallel and merge the results.This exercise has two parts. Both parts must be implemented in Ada following the Ada programming style. The code must be usefully documented and cleanly presented.
Part IImplement a generic package Sort_package containing a procedure named Sort which is able to sort an array of any type of elements. The package should be parameterized through the following parameters:
Part IIWrite the main program which tests the Sort function described above. The main program create a generic instanciation of the package created in part I, specifying the INTEGER type as the type of the array elements. This program must read the number of values to be sorted from the standard input into a variable named N. It must then read the N values from the standard input into an array (the program must not assume that each input line only contains a single value). Once the N values have been read into the array, the main program must sort this array and display the resulting sorted array.
CompilerIn order to do this practical exercise, you must use the GNAT GNU Ada Compiler. This compiler accepts the Ada core language and a number of Ada 95 extensions. The compiler can be found in /usr/local/lang/gnat/bin. The easiest way to build your program is to use the gnatmake tool. The documentation is in /usr/local/lang/gnat/doc.
The compiler requires that each source file only constitutes a single compilation unit. Programs generated with this compiler only can be killed with the kill -9 command, not with Control-C.
ContactFor any questions related to this practical exercise, contact Melanie Rieback, office R4.23, e-mail: email@example.com. Please, ask for an appointment by e-mail.
EvaluationArchive all source files into a tar file, each source file containing the name(s) and studentnumber(s) of the authors as comments, and mail the tar file to firstname.lastname@example.org with as subject: submit ada. The archive file must also contain a Makefile or a shell-script named make which builds your program and generates an executable file named main.
The program should be tested on various input sets. In particular, the program should be tested with the following input:
5 24 8 56 24 3The output must be:
3 8 24 24 56Programs proving unable to behave as required will be graded with a 1.
Do not forget to test your program with the scenario given above.