From: vashwath@rediffmail.com (prashna)
Subject: simple newbie program.
Date: 27 Nov 2002 23:26:12 -0800
Date: 2002-11-28T07:26:13+00:00 [thread overview]
Message-ID: <d40d7104.0211272326.671eb34b@posting.google.com> (raw)
Hi all,
have look at following code.
package stack is
procedure initialise_stack;
procedure push (item : in integer);
procedure pop (item : out integer);
procedure display;
end stack;
package body stack is
stack_size : constant := 100;
type stack_size_type is range 0..stack_size;
top : stack_size_type;
stack : array (stack_size_type'range) of integer;
procedure initialise_stack is separate;
procedure push (item : in integer) is separate;
procedure pop (item : out integer) is separate;
procedure display is separate;
end stack;
separate (stack)
procedure initialise_stack is
begin
top := 0;
end initialise_stack;
separate (stack)
procedure push (item : in integer) is
begin
stack(top) := item;
top := top + 1;
end;
separate (stack)
procedure pop ( item : out integer) is
begin
top := top - 1;
item := stack(top);
end pop;
with text_io; use text_io;
separate (stack)
procedure display is
begin
for i in reverse stack_size_type'first .. top-1 loop
put(integer'image(stack(i)));
end loop;
end display;
with text_io;use text_io;
with stack;
procedure stack_user is
item : integer;
choice : integer range 1..5;
package int_io is new text_io.integer_io(integer);
use int_io;
begin
loop
put_line("Enter choice");
put_line("1 to reset the stack");
put_line("2 to push to the stack");
put_line("3 to pop from the stack");
put_line("4 to display stack");
put_line("5 to quit");
get(choice);
case choice is
when 1 => stack.initialise_stack;
when 2 =>
put_line("Enter item to be pushed");
get(item);
stack.push (item);
when 3 =>
stack.pop(item);
put_line("poped item is ");
put(item);new_line;
when 4 =>
stack.display;
when 5=>
exit;
end case;
end loop;
end;
I know there will be bugs in this, Please help me to improve this stack program.
thanks
next reply other threads:[~2002-11-28 7:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-28 7:26 prashna [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-11-28 7:35 simple newbie program Grein, Christoph
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox