-- gears.adb: compute for a specific case the gear ratio for each -- choice of gears on a bicycle, expressed as a rational fraction. -- From this information the correct gear shifting order can be -- derived by simply sorting the output of this program on the -- column containing the speed factor. -- Kent Paul Dolan's first substantive Ada 95 program, completed -- September 30th, 1999. with Ada.Text_IO, Ada.Integer_Text_IO; procedure Gears is -- type for telling how many teeth a particular front or back gear has subtype Gear_Tooth_Cardinal is integer range 1 .. 100; -- type for which front gear position is in use subtype Front_Gear_Ordinal is integer range 1 .. 3; Front_Bottom_Gear: Front_Gear_Ordinal := 1; Front_Top_Gear : Front_Gear_Ordinal := 2; Front_Gear_Teeth: array ( Front_Bottom_Gear .. Front_Top_Gear ) of Gear_Tooth_Cardinal := ( 39 , 50 ); -- type for which back gear position is in use subtype Back_Gear_Ordinal is integer range 1 .. 7; Back_Bottom_Gear: Back_Gear_Ordinal := 1; Back_Top_Gear : Back_Gear_Ordinal := 5; Back_Gear_Teeth: array ( Back_Bottom_Gear .. Back_Top_Gear ) of Gear_Tooth_Cardinal := ( 28, 24, 20, 17, 14 ); Gear_Ratio_Base : Integer := 1; begin for Back_Gear_Position in Back_Bottom_Gear .. Back_Top_Gear loop Gear_Ratio_Base := Gear_Ratio_Base * Back_Gear_Teeth( Back_Gear_Position ); end loop; for Front_Gear_Position in Front_Bottom_Gear .. Front_Top_Gear loop for Back_Gear_Position in Back_Bottom_Gear .. Back_Top_Gear loop Ada.Integer_Text_IO.Put ( Item => Front_Gear_Position, Width => 2 ); Ada.Text_IO.Put( " : " ); Ada.Integer_Text_IO.Put ( Item => Front_Gear_Teeth( Front_Gear_Position ), Width => 3 ); Ada.Text_IO.Put( " , " ); Ada.Integer_Text_IO.Put ( Item => Back_Gear_Position, Width => 2 ); Ada.Text_IO.Put( " : " ); Ada.Integer_Text_IO.Put ( Item => Back_Gear_Teeth( Back_Gear_Position ), Width => 3 ); Ada.Text_IO.Put( " => " ); Ada.Integer_Text_IO.Put ( Item => Front_Gear_Teeth( Front_Gear_Position ) * ( Gear_Ratio_Base / Back_Gear_Teeth( Back_Gear_Position ) ), Width => 8 ); Ada.Text_IO.Put( " :: " ); Ada.Integer_Text_IO.Put ( Item => Gear_Ratio_Base, Width => 7 ); Ada.Text_IO.Put_Line( "" ); end loop; end loop; end Gears;