------------------------------------------------------------ -- procedure cs2a -- -- Purpose: find and print the CS2A marks and grades for -- several students -- -- Author: Chris Lokan ------------------------------------------------------------ with TEXT_IO; procedure cs2a is package int_io is new TEXT_IO.INTEGER_IO (INTEGER); use TEXT_IO, int_io; mark : INTEGER; -- subject mark for CS2A (0..100) grade : CHARACTER; -- first character of grade answer: CHARACTER; procedure get_integer ( val : out INTEGER; -- value entered by the user low : in INTEGER; -- low bound of range high : in INTEGER ) -- high bound of range is separate; procedure get_marks (m1,m3,m4,m4 : out INTEGER) -- unit marks is separate; procedure compute (m1,m2,m3,m4 : in INTEGER; -- unit marks mark : out INTEGER; -- subject mark grade : out CHARACTER) -- first char of grade is separate; procedure process_student (mark : out INTEGER; -- subject mark grade : out CHARACTER) -- subject grade is separate; begin -- cs2a loop process_student (mark, grade); put ("The overall mark and grade are "); put (mark,width=>3); put (" " & grade); new_line; put ("Another student ? " ); get (answer); skip_line; exit when (answer = 'n') or (answer = 'N'); end loop; end cs2a;
Note that stubs have been provided for four procedures. The definitions of those procedures would come in separate files, compiled separately.
----------------------------------------------------------- -- procedure process_student -- -- Purpose: find and return the CS2A mark and grade for a -- student -- -- Author: c-lokan -- Date: 19 July 1994 ----------------------------------------------------------- separate(cs2a) procedure process_student ( mark : out INTEGER; -- subject mark grade : out CHARACTER -- subject grade ) is m1 : INTEGER; -- mark in first CS2 unit m2 : INTEGER; -- mark in second CS2 unit m3 : INTEGER; -- mark in third CS2 unit m4 : INTEGER; -- mark in fourth CS2 unit begin -- process_student get_marks (m1, m2, m3, m4); compute (m1, m2, m3, m4, mark, grade); end process_student;
First the main program needs to be compiled. When the procedure stubs are encountered, the compiler puts information about those stubs into the Ada library. The stubs provide enough information for the main program itself to be compiled successfully.
Then the procedures are compiled separately. As each is compiled, the stub information in the library is replaced by the actual information from the procedure definition.
The precise commands you need to use depend on the Ada environment you are using:
In our sun ada environment, your source files should each have the suffix ".a". To compile them you would use the following steps:
adas
adac cs2a.a
adac get_integer.a
adac get_marks.a
adac compute.a
adac process_student.a
adae cs2a
a.out
In the gnat ada environment, your source files should each have the suffix ".adb". To compile them you would use the following steps:
gnatcc cs2a.adb
gnatcc get_integer.adb
gnatcc get_marks.adb
gnatcc compute.adb
gnatcc process_student.adb
gnatbl cs2a.ali
cs2a