This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

61
Task/Menu/Ada/menu-1.ada Normal file
View file

@ -0,0 +1,61 @@
-- menu2.adb --
-- rosetta.org menu example
-- GPS 4.3-5 (Debian)
-- note: the use of Unbounded strings is somewhat overkill, except that
-- it allows Ada to handle variable length string data easily
-- ie: differing length menu items text
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,
Ada.Strings.Unbounded.Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO,
Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO;
procedure menu2 is
package tio renames Ada.Integer_Text_IO;
-- rename package to use a shorter name, tio, as integer get prefix
menu_item : array (1..4) of Unbounded_String;
-- 4 menu items of any length
choice : integer := 0;
-- user selection entry value
procedure show_menu is
-- display the menu options and collect the users input
-- into locally global variable 'choice'
begin
for pntr in menu_item'first .. menu_item'last loop
put (pntr ); put(" "); put( menu_item(pntr)); new_line;
end loop;
put("chose (0 to exit) #:"); tio.get(choice);
end show_menu;
-- main program --
begin
menu_item(1) := to_unbounded_string("Fee Fie");
menu_item(2) := to_unbounded_string("Huff & Puff");
menu_item(3) := to_unbounded_string("mirror mirror");
menu_item(4) := to_unbounded_string("tick tock");
-- setup menu selection strings in an array
show_menu;
loop
if choice in menu_item'range then
put("you chose #:");
case choice is
-- in a real menu, each case would execute appropriate user procedures
when 1 => put ( menu_item(choice)); new_line;
when 2 => put ( menu_item(choice)); new_line;
when 3 => put ( menu_item(choice)); new_line;
when 4 => put ( menu_item(choice)); new_line;
when others => null;
end case;
show_menu;
else
put("Menu selection out of range"); new_line;
if choice = 0 then exit; end if;
-- need a exit option !
show_menu;
end if;
end loop;
end menu2;

20
Task/Menu/Ada/menu-2.ada Normal file
View file

@ -0,0 +1,20 @@
./menu2
1 Fee Fie
2 Huff & Puff
3 mirror mirror
4 tick tock
chose (0 to exit) #:2
you chose #:Huff & Puff
1 Fee Fie
2 Huff & Puff
3 mirror mirror
4 tick tock
chose (0 to exit) #:55
Menu selection out of range
1 Fee Fie
2 Huff & Puff
3 mirror mirror
4 tick tock
chose (0 to exit) #:0
Menu selection out of range
[2010-06-09 22:18:25] process terminated successfully (elapsed time: 15.27s)