Advertisement
Guest User

Untitled

a guest
Dec 30th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.33 KB | None | 0 0
  1. with Ada.Text_IO;         use Ada.Text_IO;
  2. with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
  3.  
  4. procedure Cars is
  5.    
  6. ----KONSTANT SOM SÄGER HUR MÅNGA BILAR SOM SKA JÄMFÖRAS----
  7.    C : constant Integer := 5;
  8.    
  9.    Type Reg_Array is
  10.      array (1..C) of String(1..6);
  11.    
  12.    Type Weight_Array is
  13.      array (1..C) of Integer;
  14.    
  15.    Type Trash_Array is
  16.      array (1..C) of String(1..60);
  17.      
  18.    procedure Get(Reg_Nr : out Reg_Array; Weight : out Weight_Array; Trash : out Trash_Array) is
  19.       Last : Integer;
  20.    begin
  21.       for I in 1..C loop
  22.      Get(Reg_Nr(I));
  23.      Get(Weight(I));
  24.      Get_Line(Trash(I), Last);
  25.      Trash(I)(Last+1 .. Trash'Last) := (others => ' ');
  26.       end loop;
  27.    end Get;
  28.    
  29.    function Max(Weight : in Weight_Array)
  30.            return Integer is
  31.      Max, Index : Integer := 0;
  32.    begin
  33.       for I in 1..C loop
  34.      if Max < Weight(I) then
  35.         Max := Weight(I);
  36.         Index := I;
  37.      end if;
  38.       end loop;
  39.       Return Index;
  40.    end Max;
  41.    
  42.    Reg_Nr : Reg_Array;
  43.    Weight : Weight_Array;
  44.    Trash  : Trash_Array;
  45.    Index  : Integer;
  46.    
  47. begin
  48.    Put("Mata in fem bilar: ");
  49.    New_Line;
  50.    Get(Reg_Nr, Weight, Trash);
  51.    Index := Max(Weight);
  52.    New_Line;
  53.    Put("Tyngsta bilen var " );
  54.    Put(Reg_Nr(Index));
  55.    Put(" som väger ");
  56.    Put(Weight(Index),0);
  57.    Put(" kg.");
  58. end Cars;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement