comp.lang.ada
 help / color / mirror / Atom feed
* Re: Why can't i get an EXE!
@ 2002-01-06 19:45 Phoenix.
  2002-01-06 20:12 ` Preben Randhol
  0 siblings, 1 reply; 14+ messages in thread
From: Phoenix. @ 2002-01-06 19:45 UTC (permalink / raw)


    Tankyou very much for your assistance with my program. Your advise has
solved my primary problem. However I appear to have a new problem.
    My program now runs however it doesn't perform it's desired task. Which
is to allow the user to add and remove items from a queue and also to show
what is in the queue. This is where my problem occured when I was trying to
show what is stored within the queue.
    The problem is that as soon as the procedure ends, it appears to clear
what is stored within the que. Therefore I think the problem is that the
variables are not declared globally, and are local to each procedure, and
thus I was wondering how I declare them Globally if that is the problem.
However if it is not the problem I was wondering what the problem is.

 >>BEGIN QUE.ADS

package Que is

Empty_Queue : exception;

type Queue is array(1..500) of Integer;

Q : Queue;

Qs : Queue;

Tail : Integer := 0;

Tails : Integer := 0;

Head : Integer := 1;

Heads : Integer := 1;

Count : Integer := 0;

N : Integer;

A : Integer;

procedure Initialiser(Q: in out Queue; Head: in out Integer; Tail: in out

Integer);

procedure Add(Q: in out Queue; Head: in out Integer; Tail: in out Integer);

procedure Remove(Q: in out Queue; Head: in out Integer; Tail: in out

Integer);

procedure Show(Q: in out Queue; Head: in out Integer; Tail: in out Integer);

end Que;

<<END QUE.ADS



>>BEGIN QUE.ADB

with Ada.Text_Io, Ada.Integer_Text_Io;

use Ada.Text_Io, Ada.Integer_Text_Io;

with Text_Io;

use Text_Io;



package body Que is

procedure Initialiser(Q: in out Queue; Head: in out Integer; Tail: in out

Integer) is

begin

Tail := 0;

Head := 1;



end Initialiser;

procedure Add(Q: in out Queue; Head: in out Integer; Tail: in out Integer)

is

begin

Put_Line("Please enter an integer ");

Get(N);

Tail := Tail+1;

Q(Tail) := N;

-- call proc show here

-- Proc SHOW

for Count in Tail..Head loop

A := Q(Count);

Put(A);

end loop;

-- END PROC SHOW

end Add;

procedure Remove(Q: in out Queue; Head: in out Integer; Tail: in out

Integer) is

begin

if Head < Tail then

--put_line("Queue is currently empty");

raise Empty_Queue;

else

Head := Head + 1;

end if;

--call proc show here

exception

when Empty_Queue=>

Skip_Line;

Put_Line("The queue is currently empty");

New_Line;

end Remove;

procedure Show(Q: in out Queue; Head: in out Integer; Tail: in out Integer)
is

A : integer;

begin

put_line("This is your queue: - ");

if Head > Tail then

--put_line("Queue is currently empty");

raise Empty_Queue;

else

for Count in Head..Tail loop

A := Q(count);

Put(A);

end loop;

end if;

exception

when Empty_Queue =>

Skip_Line;

Put_Line("The queue is currently empty");

New_Line;

end Show;

end Que;

<<END QUE.ADB



>>BEGIN MAIN.ADB

with Que; use Que;

with Ada.Text_Io, Ada.Integer_Text_Io;

use Ada.Text_Io, Ada.Integer_Text_Io;

procedure Main is

begin

loop

Initialiser(Q, Head, Tail);

New_Line;

Put_Line("****************************");

Put_Line(" 1). Add to queue");

Put_Line(" 2). remove to queue");

Put_Line(" 3). Show Queue");

Put_Line(" 4). Quit queue program");

Put_Line("****************************");

New_Line;

Get(A);

case A is --Execute menu option depending on A's value

when 1 => Add(Q, Head, Tail);

when 2 => Remove(Q, Head, Tail);

when 3 => Show(Q, Head, Tail);

when 4 => exit;

when others => Put_Line("Sorry incorrect entry please retry");

end case;

end loop;

end Main;

<<END MAIN.ADB








^ permalink raw reply	[flat|nested] 14+ messages in thread
* Why can't i get an EXE!
@ 2002-01-05 23:33 NTL
  2002-01-06  0:52 ` Preben Randhol
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: NTL @ 2002-01-05 23:33 UTC (permalink / raw)


Package: QUE PACKAGE

Hi
I am a university student studying computer science's and have to create a
small program as part of my coursework
The program below compiles perfectly and builds in ADAGIDE GNAT3.11,
however, I can not get it to create the .C and .EXE files... am I making
some small fundemental mistake.

any help gladly recievied.

David.

P.s. Complete newbie to ADA programming.



>> BEGIN QUE.ADS

package que is
empty_queue : EXCEPTION;

type queue is array(1..500) of integer;

q : queue;
qs : queue;
tail : integer := 0;
tails : integer := 0;
head : integer := 1;
heads : integer := 1;
count : integer := 0;
n : integer;
A : integer;

procedure initialiser(q: in out queue; head: in out integer; tail: in out
integer);
procedure add(q: in out queue; head: in out integer; tail: in out integer);
procedure remove(q: in out queue; head: in out integer; tail: in out
integer);
procedure show(q: in out queue; head: in out integer; tail: in out integer);

end que;


<<END QUE.ADS

>>BEGIN QUE.ADB

with ada.text_io, ada.integer_text_io;
use ada.text_io, ada.integer_text_io;
with text_io;
use text_io;


package body que is



procedure initialiser(q: in out queue; head: in out integer; tail: in out
integer) is
begin
   tail := 0;
   head := 1;
   for count in head..tail loop
   q(count) := 0;
   end loop;

end initialiser;

procedure add(q: in out queue; head: in out integer; tail: in out integer)
is
begin
   put_line("Please enter an integer ");
   get(n);
   tail := tail+1;
   q(tail) := n;
   --call proc show here
end add;

procedure remove(q: in out queue; head: in out integer; tail: in out
integer) is
begin
   if head < tail then
   --put_line("Queue is currently empty");
   raise EMPTY_QUEUE;
   else
   head := head + 1;
   end if;
   --call proc show here

   exception
   when EMPTY_QUEUE=>
      SKIP_LINE;
      Put_Line("The queue is currently empty");
      NEW_LINE;

end remove;

procedure show(q: in out queue; head: in out integer; tail: in out integer)
is
begin
   if head < tail then
   --put_line("Queue is currently empty");
   raise EMPTY_QUEUE;
   else
   for count in head..tail loop
   put_line(" ");
   end loop;
   end if;

   exception
   when EMPTY_QUEUE=>
      SKIP_LINE;
      Put_Line("The queue is currently empty");
      NEW_LINE;

end show;


begin
   loop
      initialiser(q => qs, head => heads, tail => tails);
      Put_Line("****************************");
      Put_Line("   1). Add to queue");
      Put_Line("   2). remove to queue");
      Put_Line("   3). Quit queue program");
      Put_Line("****************************");
      get(A);
      case A is --Execute menu option depending on A's value
         when 1      => add(q => qs, head => heads, tail => tails);
         when 2      => remove(q => qs, head => heads, tail => tails);
         when 3      => exit;
         when others => Put_Line("Sorry incorrect entry please retry");
      end case;
   end loop;


end que;

<<END QUE.ADB





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-01-08 13:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-06 19:45 Why can't i get an EXE! Phoenix.
2002-01-06 20:12 ` Preben Randhol
2002-01-06 22:03   ` Phoenix.
  -- strict thread matches above, loose matches on Subject: below --
2002-01-05 23:33 NTL
2002-01-06  0:52 ` Preben Randhol
2002-01-06  2:02   ` Phoenix.
2002-01-06 12:19     ` Preben Randhol
2002-01-07 11:06 ` Preben Randhol
2002-01-07 21:52 ` Liddle Feesh
2002-01-08 13:14   ` Phoenix.
2002-01-08 13:31     ` Phoenix.
2002-01-08 13:55       ` Liddle Feesh
2002-01-08 13:52     ` Liddle Feesh
2002-01-07 21:59 ` Liddle Feesh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox