Pages

Subscribe:

Sabado, Pebrero 11, 2012

The Ada Programming Language




The Ada language is the result of the most extensive and most expensive language design effort ever undertaken. Up until 1974 half of the applications at The Department of Defense were embedded systems. An embedded system is one where the computer hardware is embedded in the device it controls. More than 450 programming languages were used to implement different DoD projects, and none of them were standardized. Because of this, software was rarely reused. For these reasons, the Army, Navy, and Air Force proposed to develop a high-level language for embedded systems.
By 1977, a complete language design specification for Ada was created. In April 1977, four proposing contractors were chosen to produce Phase I of the language design. In February 1977, Phase I of the language design was complete. Following this, was a two month evaluation period where 400 volunteers in 80 teams chose two out of the four as being the best language designs. These two companies were then given the go ahead to produce Phase II of the project. At the end of Phase II, another two month evaluation period took place. In May of 1979 the Cii Honeywell/Bull (the only foreign contractor) language design was chosen as the winner. Phase III of the project began after the winner was selected. After a winner was selected, the language design was published by the ACM. In November 1979, over 500 language reports were received from 15 different countries. Most of the reports suggested minor changes in the design, none real drastic. Based on these suggestions, a revised language design was published in February of 1980. After some minor changes to this document over the next few years, the final official version of the language was settled upon. The Ada language was then frozen for the next five years.
Ada was named after Ada Lovelace (1815–1852), who is sometimes credited as being the first computer programmer.
(http://en.wikipedia.org/wiki/Ada_(programming_language))

Language Features
Packages - Data types, data objects, and procedure specifications can be encapsulated into a package. This supports the program design of data abstraction.
Exception Handling - Ada has very good exception handling capabilities which allow the program to handle its own run-time errors.
Generic Program Units - It is possible to write a procedure (for example, a sorting procedure) which does not require a data type to be specified.
Parallel / Concurrent Processing - Ada supports parallel and concurrent execution of tasks.
Ada 95 Will Add -
Support for object-oriented programming
More flexible libraries
Better control mechanisms for shared data
(http://groups.engin.umd.umich.edu/CIS/course.des/cis400/ada/ada.html)
Ada is an effective language for the economical creation of correct software. Along with fairly common features such as modularity and the ability to program by extension, Ada adds a sophisticated set of tools for concurrent programming and a very rich type system that allows you to create your own customized primitive types. The compiler can then use those customizations to determine coding errors. The compiler will also, as a default behavior, automatically produce safety and correctness checks for run time error detection.
(http://www.adaic.org/learn/materials/intro/part5/)
If Statement goes like this:

The Ada if statement is fully blocked.
   if condition  then
      -- statement(s)
   end if;

   if condition then
      -- statement(s)
   else
      -- statement(s)
   end if;

Base sa dito ang pag gamit ng if statement ditto kung I-compare mo sa C di na siya inilalagay sa loob ng parenthesis basta pag nalagay ka ng if condition na agad tapos lalagyan mo ng “then” sa dulo after ng condition parang naming VB may “Then” :D
The condition must always evaluate to a Boolean value (False or True).

Sa paggamit ng loop may tatlo ka pang pagpipilian pwedeng “Simple Loop” , “While Loop” and “For Loop” diba swerte mo madami ka choice na pwedeng gamitin pag ditto ka nag co-code. So eto I tech you how to use the simple loop, it goes like this:

   loop
      -- Loop body goes here
   end loop;

sa Ada ang simple loop ay unconditional means walang condition. This loop will continue forever, or until you execute an exit command within the loop. In Ada, the exit command terminates a loop. It does not terminate a program. Para maglagay ng exit ganito ang pwedeng gawen
loop
      if condition then
         exit;
      end if;
   end loop;
or kea nmn ganito ang gawen mo:
This construct is so common that a shortened version is available.
   loop
      exit when condition;
   end loop;
The simple loop combined with an exit statement is the most general form of looping in Ada, allowing you to perform your test at the top, bottom, or middle of each iteration.

The next loop is the while loop it goes like this:

   while condition loop
      -- Loop body goes here
   end loop;
The Ada while loop is like the while loop in most languages. It is a conditional loop that performs the condition test at the top of the loop.

The last loop is the for loop the Ada for loop iterates through an explicitly stated range of discrete values. As we discussed earlier, the concept of a range is very important in Ada. A range is specified by the notation lowest_value .. highest_value.
   for variable in low_value .. high_value loop
      -- Loop body goes here
   end loop;
The name of a discrete type can be used in place of the value. In that case the loop will iterate over all values in the type, starting at the lowest value. Ranges always must be expressed as low_value..high_value. They can never be expressed in reverse order. You can iterate backwards through a range by adding the reserved wordreverse.
   for variable in reverse low_value .. high_value loop
      -- Loop body goes here
   end loop;
The control variable used in a for loop is only visible within the loop body. It is a read-only variable within the loop body, meaning that you cannot explicitly assign a value to the control variable. You do not declare the control variable before you use it. The compiler determines the data type for the range and creates the control variable to be an instance of that type
Ganito naman gumamit ng for loop.

(http://www.adaic.org/learn/materials/intro/part4/)

Ohh yan! May idea na tau gumamit ng looping statement at saka conditional statement. Lets try naman ang array dito sa ADA:
Basic syntax
The basic form of an Ada array is:
Array (Index_Range) of Element_Type
where Index_Range is a range of values within a discrete index type, and Element_Type is a definite subtype. The array consists of one element of "Element_Type" for each possible value in the given range. If you for example want to count how often a specific letter appears inside a text, you could use:
type Character_Counter is array (Character) of Natural;
As a general advice, do not use Integer as the index range, since most of the time negative indices do not make sense. It is also a good style when using numeric indices, to define them starting in 1 instead of 0, since it is more intuitive for humans and avoids off-by-one errors.
(http://en.wikibooks.org/wiki/Ada_Programming/Types/array#Declaring_arrays)
Calculator Program
--
-- Integer calculator program.  Takes lines of input consisting of
-- <operator> <number>, and applies each one to a display value.  The
-- display value is printed at each step.  The operator is one of =,
-- +, -, *, /, or ^, which correspond to assign, add, subtract, multiply
-- divide, and raise, respectively.  The display value is initially zero.
-- The program terminates on a input of q.
--
with Text_IO;
with Gnat.Io; use Gnat.Io;
procedure Calc is
   Op: Character;               -- Operation to perform.
   Disp: Integer := 0;          -- Contents of the display.
   In_Val: Integer;             -- Input value used to update the display.
begin
   loop
      -- Print the display.
      Put(Disp);
      New_Line;

      -- Promt the user.
      Put("> ");

      -- Skip leading blanks and read the operation.
      loop
         Get(Op);
         exit when Op /= ' ';
      end loop;

      -- Stop when we're s'posed to.
      exit when Op = 'Q' or Op = 'q';

      -- Read the integer value (skips leading blanks) and discard the
      -- remainder of the line.
      Get(In_Val);
      Text_IO.Skip_Line;

      -- Apply the correct operation.
      case Op is
         when '='      => Disp := In_Val;
         when '+'      => Disp := Disp + In_Val;
         when '-'      => Disp := Disp - In_Val;
         when '*'      => Disp := Disp * In_Val;
         when '/'      => Disp := Disp / In_Val;
         when '^'      => Disp := Disp ** In_Val;
         when '0'..'9' => Put_Line("Please specify an operation.");
         when others   => Put_Line("What is " & Op & "?");
      end case;
   end loop;
end Calc;


LAAAquino
200911909

0 (mga) komento:

Mag-post ng isang Komento