The Ada Program: proportions.adb

  1 -- proportions.adb:  DWM case study "Mixing Proportions", page 135-138

  2 
  3 with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
  4 use Ada;
  5 
  6 procedure Proportions is
  7    Parts_Of_A, Parts_Of_B: Integer;-- Proportion of ingredients

  8    Units        : String (1..80);  -- String to hold units of measurement

  9    Last_Char    : Integer;         -- Index of last character in "Units"

 10    Num_Recipies : Float;           -- Number of recipies needed

 11    Total_Amount, Amount_A, Amount_B: Float;  -- Amount of ingredients

 12 
 13 begin
 14    -- Prompt the user, and get the data

 15    Text_IO.Put_Line ("Enter the proportions of two ingredients.");
 16    Integer_Text_IO.Get (Parts_Of_A);
 17    Integer_Text_IO.Get (Parts_Of_B);
 18    Text_IO.Put_Line ("Enter the amount of mixture desired.");
 19    Float_Text_IO.Get (Total_Amount);
 20    Text_IO.Skip_Line;
 21    Text_IO.Put_Line ("Enter the units of measurement you're using.");
 22    Text_IO.Get_Line (Item=>Units, Last=>Last_Char);
 23    Text_IO.New_Line;
 24    -- Print the data

 25    Text_IO.Put ("The ingredients are mixed in the proportion of ");
 26    Integer_Text_IO.Put (Item=>Parts_Of_A, Width=>0);
 27    Text_IO.Put (" to ");
 28    Integer_Text_IO.Put (Item=>Parts_Of_B, Width=>0);
 29    Text_IO.Put_Line (".");
 30    Text_IO.Put ("To prepare ");
 31    Float_Text_IO.Put (Item=>Total_Amount, Fore=>1, Aft=>1, Exp=>0);
 32    Text_IO.Put (" " & Units (1..Last_Char) );
 33    Text_IO.Put_Line (" of mixture:");
 34    -- Determine the number of recipies required

 35    Num_Recipies := Total_Amount / Float (Parts_Of_A + Parts_Of_B);
 36    -- Determine the amount of each ingredient required

 37    Amount_A := Float (Parts_Of_A) * Num_Recipies;
 38    Amount_B := Float (Parts_Of_B) * Num_Recipies;
 39    -- Print amount of each ingredient

 40    Text_IO.Put ("Combine ");
 41    Float_Text_IO.Put (Item=>Amount_A, Fore=>1, Aft=>1, Exp=>0);
 42    Text_IO.Put (" " & Units (1..Last_Char) );
 43    Text_IO.Put (" of ingredient A with ");
 44    Float_Text_IO.Put (Item=>Amount_B, Fore=>1, Aft=>1, Exp=>0);
 45    Text_IO.Put (" " & Units (1..Last_Char) );
 46    Text_IO.Put_Line (" of ingredient B.");
 47 end Proportions;