CSC 125/259 Assignment 1: Ada Drills. The Ada language was intially created for use by the US military, and is still taught at the service academies and used in the areospace and other defense-related industries. It is designed to be a robust language that imposes a degree of discipline in programmers, even more so than languages like Java. Our interest in this language, however, is in its extensive support for concurrent programming. In this first assignment you will become familiar with the basic mechanics of writing Ada programs. 1. Following the example of the fibonacci program (fibs.adb), write a program that includes: i. a function gcd that returns the gcd of two integers. In C/Java you would write this as int gcd(int a, int b) { if (a==0) return b; else return gcd(b%a,a); } "a % b" is "a mod b" in Ada. ii. Write the n-factorial (e.g, factorial of 5 is 5*4*3*2*1) function as a NON-RECURSIVE PROCEDURE in Ada. That is, instead of writing a function that returns the answer, use a procedure with an OUT parameter. Use a while loop inside the procedure. iii. an outer procedure that tests gcd and n-factorial. 2. The following data structure implements a linked-list in Ada. type Node; -- prototype for forward reference type Nodept is access Node; -- pointer to Node structure type Node is record Head: Integer; -- the data item, or "car" Tail: Nodept := null; -- pointer to next node, or "cdr" end record; That is, Nodept is a pointer to a Node record (struct). To declare a nodept: first : Nodept; -- this must be inside a declaration section To create a Node: first := new Node; -- note it's "Node" here, not "Nodept". first.Head := 1; first.Tail := null; -- etc ... Look in the file "lotsastuff.adb" for more complete sample code. Use linked lists to implement a stack data structure. That is, first implement: type liststack is record tos : nodept := null; -- pointer to top of stack size : integer := 0; -- keeps track of size of stack. end record; Then, write procedures/functions for the operations push, pop and checkempty on liststacks. Write code to test its usage. You will have to discover for youself if you need certain parameters as in or out parameters. Also write a procedure to add an integer to the END of the stack (so it can also be used like a queue). You'll have to decide as to the appropriate forms of procedure/function to use. But here's a sample procedure that would print out the contents of a liststack: procedure printstack(s : liststack) is current : nodept; begin current := s.tos; while not(current = null) loop put(current.head,width=>4); current := current.tail; end loop; new_line; end printstack;