7.4. Tables - JulTob/Ada GitHub Wiki

Tables

We can use the enumerated types to define a table.

procedure Class_Marks is 
 Type Students is (
   Alice, Bob, Carl, Dani);
 Type Subjects is (
   Algebra, Calculus, Statistics);

 Type Marks is Array (Students, Subjects) of Integer;

 MyClass: Marks:=
    -- Al, Cl, St
   (  ( 8,  9,  9), -- Alice
      ( 7,  6,  9), -- Bob
      ( 4,  6,  5), -- Carl
      ( 5,  5,  6));-- Dani

procedure Average(M: Marks, S: Student) return float is
  result: Float := 0.0;
  begin
     for Sub in Subjects loop
       result := result 
               + float(M(S,Sub));
       End Loop;
  return (result/3.0);
  end Average;