Code · 1 file

Sample Ada File

Ada 2012 with decimal fixed-point money and expression functions. Every language sample implements the same small program so you can compare them side by side.

Ada · 749 B

Sample Ada file

An idiomatic Ada example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.adb — first linesAda
--  Sample Ada 2012 program — samplefiles.com
with Ada.Text_IO; use Ada.Text_IO;

procedure Sample is
   type Money is delta 0.01 digits 12;

   type Customer is record
      Id      : Positive;
      Name    : String (1 .. 6);
      Balance : Money;
   end record;

   function Is_Vip (C : Customer) return Boolean is (C.Balance >= 10_000.00);

   Customers : constant array (1 .. 3) of Customer :=
     ((1, "Ada   ", 12_500.00),
      (2, "Grace ", 830.50),
      (3, "Linus ", 10_000.00));

   Total : Money := 0.0;
begin
   for C of Customers loop
      Put_Line (C.Name & Money'Image (C.Balance) & (if Is_Vip (C) then " VIP" else ""));
      Total := Total + C.Balance;
   end loop;

File details

Size
749 B (749 bytes)
MIME type
text/x-ada
SHA-256
a17907a7c5065dac7f1f2441c6321d9a0a5946f6cebe291c0eb4bf4737aab5ae
MD5
5656d49d65e6933fbaa1541af7dbecba

Download from the command line

curl -L -o sample.adb https://files.samplefiles.com/code/adb/sample.adb

Or check the download in your browser with the checksum calculator.