Skip to main content

Posts

Runtime Error (Exception) Handling

ADA handles programmer defined exceptions and system defined exceptions Some of the system defined exceptions are like  NUMERIC_ERROR - raised whenever the abnormal precision in the program like divide by zero  STORAGE-ERROR - raised whenever the program runs out of memory space CONSTRAINT_ERROR - asserts when a variable goes out of its bound TASKING_ERROR - raised during the incorrect use of tasks PROGRAM_ERROR- raised whenever an exception is not captured by any other conditions Example on Exceptions //Program to create two programmer defined exceptions declare  P,PRESSURE:float; HIGH_PRESSURE, LOW_PRESSURE:exception; begin   loop     P:=READ_PRESSURE(PRESSURE);     if P raise LOW_PRESSURE;     elseif P>150 then  raise HIGH_PRESSURE; end if; end loop; exception  when LOW_PRESSURE => put("Warning: Very Low Pressure"); when HIGH_PRESSURE => put ("Warning: High Pressure"); When exceptions are raised in multiple procedures or block and Procedures, hand...

Packages in ADA

Benefits of Packages Packages can be compiled, debugged independently software maintenance is very easier Once package is developed, they can be made accessible to everyone who has access to it. packages provide more security                                                                                                             Packages contains two parts 1) a specification and 2) a body Specification interfaces to the outside world. body contains the executable statements associated with the functions Examples of packages includ, COMPLEX NUMBERS Calculations, Creation of TIMER and CLOCK using packages and made as a library Example //Package specification describes the functions and variables relevant to complex number and their addition and subtraction operations package COMPLEX_NUMBER is type COMPLEX is  record  real, imag:float; end record; function ADD(a,b:COMPLEX) return COMPLEX; function SUB(a,b:COMPLEX) return COMPLEX; end COMPLEX_NUMBER; //Paackage body will implement the f...

Blocks and Procedures in ADA

Blocks A Block in ADA contains two parts specification and a body. The specification specifies the variable used inside the block and the body executes the statement for the block syntax block begin --- --- end The main purpose of blocks are information hiding. A Variable declared inside a block is accessible only within the block and nowhere outside the block. Example var x,y:integer begin    y:=0;  for x in 1..10 loop   block    var x:integer;     begin      for x in 1..5 loop     y:=y+x;    end loop; end; end loop; (NB: the above example shows two variables x within the block and outside the block, The x inside the block is accessible only within that block) Procedures and Functions Blocks are repeated whenever they are needed, but functions can be written once, called anytimes Examples //to define a function to show the smaller among two integers function SMALLER (A,B: integer) return integer is  begin if A   return A; else return B; end if; end SMALLER; //function calling S...

ADA - Control Structures

if-then-else if y x:=4; elseif a=0 then x:=6; else d:=9; end if for .... do for i in 0..10 loop x(i) := i * j; end loop; while while x x:=x+i; end loop; case case x is when 1 => y:=x; when 2 => y:=0; when others => y:=-1; end case

ADA - Data types

Simple Data types //creates three variables for TEMPERATURE which is of type float type TEMPERATURE is new float; ta, tb, tc: TEMPERATURE; //creates three variables for PRESSURE which is of type float type PRESSURE is new float; pa, pb, pc: PRESSURE; ta=pa is illegal as it is implicit type conversion ta= TEMPERATURE(pa); is legal //creates range between o to 10000 type HEIGHT is new float range 0..100000; Sub types type TIME is new float range 0..23.59; subtype MORNING is TIME range 0..11.59; subtype NOON is TIME range 12..16.00; subtype EVENING is TIME range 16.01..18.59 Enumeration type MONTH is (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec); floating point type var1 is digits 8 range -1e20..1e20; type var2 is digits 12 range -1e20..1e20; fixed point type var3 is delta 0.001 range 0.000..0.999; Arrays //SMALLINT is a array variable can have the range between 0 and 20, 10 such variables are declared type SMALLINT is integer range 0..20; type VAR4 is array(1..10) of SMALLINT...

ADA - programming language Features

Object oriented programming Strong typing Generic programming/templates Exception handling Facilities for modular organization of code Standard libraries for I/O, string handling, numeric computing Systems programming Concurrent programming Real-time programming Helps for periodic and event driven tasks Avoids unbounded priority inversion Efficient implementation of Priority ceiling in ADA Distributed systems programming Interfaces to other languages (C, COBOL, Fortran)

Strongly Typed Language

What is a strongly typed language? Each variable must be declared with its own data type each data type should be associated with a value and operation (which operates on those values) implicit type conversions are not allowed explicit type conversions are legal. for example, if i is integer and a is float, then i=a; says it is implicit which is illegal, if i=(integer)a; then it is perfectly legal.