with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
with ada.float_text_io; use ada.float_text_io;
procedure g1procsv4 is
-- Input and the range values and put them in order
-- Low, high: return endpoints of inclusive range
procedure input_range(low, high: out Integer) is
begin
-- Input the range values
get(low);
get(high);
-- Put range values into nondescending order
if low > high then
declare -- Declare a variable
t: Integer := low;
begin
low := high;
high := t;
end;
end if;
end input_range;
-- Classify and count the value
procedure process_value(rangeLow, rangeHigh, num: in Integer;
low, mid, high: in out natural) is
begin
if num < rangeLow then
low := low + 1;
elsif num <= rangeHigh then
mid := mid + 1;
else -- num > rangeHigh
high := high + 1;
end if;
end process_value;
-- Input the numbers and count their locations within the range
-- specified by low and high
-- Parameters:
-- low, high: endpoints of inclusive range
-- l, e, h: return frequency counts for low, within, and high values
procedure input_and_process_remaining(low, high: Integer;
l, e, h: out Natural) is
num: Integer;
begin
-- Initialize the counts
l := 0;
e := 0;
h := 0;
-- Get and count the values
while not end_of_file loop
get(num);
process_value(low, high, num, l, e, h);
end loop;
end input_and_process_remaining;
-- Print one line of the results
-- Parameters:
-- s: label of result
-- i: count to display
-- i: total count for calculating percentages
procedure putline(s: String; i, n: natural) is
-- Percentage that i is to n
pct: constant float := 100.0 * float(i) / float(n);
begin
put(s);
set_col(14); -- Move to the correct column
put(i);
put(" ");
put(pct, fore => 4, aft => 1, exp => 0);
put("%");
new_line;
end putline;
-- Calculates percentages and outputs results for l, e, and h and their total
-- Parameters:
-- l, e, h: frequency counts for low, within, and high values, respectively
procedure calculate_percent_and_output_results(l, e, h: Natural) is
total: constant Natural := l + e + h;
begin
putline("Below Range:", l, total);
putline("Within Range:", e, total);
putline("Above Range:", h, total);
putline("Total:", total, total);
end calculate_percent_and_output_results;
-- Variables for main routine
low, high: Integer; -- Endpoints for inclusive range
lo, eq, hi: natural; -- Frequency counts for each range
begin
input_range(low, high);
input_and_process_remaining(low, high, lo, eq, hi);
calculate_percent_and_output_results(lo, eq, hi);
end g1procsv4;