ada programming language

Learn from examples

1. Program to output a string, integer, and floating point exal1.adb source code -- exal1.adb print a string, integer, float with text_io; use text_io ; procedure exal1 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; a, b : integer; x : float; begin put_line("exal1.adb running"); put_line(""); Put_Line("my string"); a := 12; b := 4; put("a="); put(a); put_Line(""); put("b="); put(b); put_Line(""); x := 37.4; put("x="); put(x); put_Line(""); put_line("exal1.adb finished"); end exal1; Execution output: exal1.adb running my string a= 12 b= 4 x= 3.74000E+01 exal1.adb finished 2. commands to execute the source code at a minimum, Windows, Linux, MacOSX. Windows: use nmake or ada.bat ??? exal1.adb Linux: gnatmake exal1.adb exal1 MacOSX ??? exal1.adb Sample Makefile: # Makefile for ada exal1.out file all: exal1_adb.out # can have many .out exal1.out : exal1.adb gnatmake exal1.adb ./exal1 > exal1_adb.out cat exal1_adb.out 3. You must be able to declare variables and arrays and matrix of various types. exal3.adb source code -- exal3.adb example declare and use variables, arrays, matrix with text_io; use text_io ; procedure exal3 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; begin put_line("exal3.adb running"); put_line("exal3.adb finished"); end exal3; Execution output: exal3.adb running exal3.adb finished 4. You need to be able to have loops, iteration statements exal4.adb source code -- exal4.adb example loops, iteration with text_io; use text_io ; procedure exal4 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; begin put_line("exal4.adb running"); put_line("exal4.adb finished"); end exal4; Execution output: exal4.adb running exal4.adb finished 5. You need if then else conditional statements exal5.adb source code -- exal5.adb example if then else with text_io; use text_io ; procedure exal5 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; begin put_line("exal5.adb running"); put_line("exal5.adb finished"); end exal5; Execution output: exal5.adb running exal5.adb finished 6. You need to be able to create functions, procedures, subroutines. exal6.adb source code -- exal6.adb example delclare and use functions and procedures with text_io; use text_io ; procedure exal6 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; begin put_line("exal6.adb running"); put_line("exal6.adb finished"); end exal6; Execution output: exal6.adb running exal6.adb finished 7. You need to be able to read and write files in various formats. exal7.adb source code -- exal7.adb example read and write files with text_io; use text_io ; procedure exal7 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; begin put_line("exal7.adb running"); put_line("exal7.adb finished"); end exal7; Execution output: exal7.adb running exal7.adb finished 8. You need to be able to use a number of files combined to build a program. This may include packages, libraries, operating system commands, header files, etc. exal8.adb source code -- exal8.adb example use external files and libraries with text_io; use text_io ; procedure exal8 is package int_io is new integer_io(integer) ; use int_io; package flt_io is new float_io(float); use flt_io; begin put_line("exal8.adb running"); put_line("exal8.adb finished"); end exal8; Execution output: exal8.adb running exal8.adb finished

Last updated 7/25/2019