comp.lang.ada
 help / color / mirror / Atom feed
* urgent help needed!!!
@ 1997-03-29  0:00 yus000
  1997-03-31  0:00 ` Nick Roberts
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: yus000 @ 1997-03-29  0:00 UTC (permalink / raw)



Hi, i have a urgent question.

I am doing assignment on stacks.  We have to declare the stack as "limited
private type"

As a result, in my main program, i need to initiate the stack.  Do i use

with Text_IO; use Text_IO;
with ordered_stack; use ordered_stack;
procedure main is

begin

declare

    w: stack;   -- line 7
    m: integer := 4;
    n: integer := 3;
    k: integer :=  2;

begin

   push(w, m);
   push(w, n);
   push(w, k);

end;

end main;


*** i get the error" subtype mark required in this context"

How do i arrange my main program???

I tried to change it to : type w is new ordered_stack, but i still get
errors.  Please help!!!

thanks.
----------------------------------------------------------------
with ordered_stack; --use ordered_stack;
with Text_IO; use Text_IO;
procedure testorder is
 a,b,c,d : integer;

begin

declare
    use ordered_stack;
    a : integer := 4;
    b : integer := 3;
    c : integer := 2;
    d : integer := 1;

   -- a, b, c, d : integer;
    type w is new ordered_stack;

    --type p is new ordered_stack;

    --subtype w is p; -- stack;

begin

  -- a := 4;
  -- b := 3;
   --c := 2;
   --d := 1;
--begin

   push(w,a);
   push(w,b);
   push(w,c);
   push(w,d);

   put(" is going to print");
   New_Line;

   print(w);

end;

end testorder;
----------------------------------------------------------
------------------------------------------------------------------
with Gnat.IO; use Gnat.IO;

package body ordered_stack is

   procedure push(s: in out stack; x: in integer) is
      k: cell_ptr;
   begin
      k := new cell'(value=>x, next=>null);
      s.list.next := k;
      s.list := k;

      s.count := s.count + 1;


   end push;
  --////////////////////////////////////////

   function empty (s: stack) return Boolean is
   begin
      return s.list = null;
   end empty;

  --/////////////////////////////////////////////

   procedure pop(s: in out stack; x: out integer)is
   begin
       x:= s.list.value;
       s.list := s.list.next;

   end pop;

  --////////////////////////////////////////////////
function top(s: stack) return integer is
begin
     return s.list.value;
end top;

--////////////////////////////////////////////////////


procedure print(s: out stack) is

  i: integer;
  m: integer;
begin

   m := s.count;

   Put("The ordered stack is as follows");
   New_Line;

   for i in 1 .. m loop

       put(integer(s.list.value));
   end loop;
   New_Line;

end print;

end ordered_stack;
---------------------------------------------------------------------

*******************************************************************
package ordered_stack is

       type stack is limited private;

       procedure push(s: in out stack; x: in integer);

       function empty (s: stack) return Boolean;

       procedure pop (s: in out stack; x: out integer);

    function top (s: stack) return integer;

  --   function top return integer;

       procedure print(s: out stack);


private
          type cell;
          type cell_ptr is access cell;

          type cell is
           record
              value: integer;
              next:  cell_ptr;
           end record;

           type stack is
              record

             --max: constant := 100;
         --type integer_vector is array(integer range<>) of integer;
          --s: interger_vector(1 .. max);
          --top: integer range 0 .. max := 0;

            count: integer:= 0;
           list: cell_ptr;
        end record;
end;
*********************************************************************

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet




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

* Re: urgent help needed!!!
  1997-03-29  0:00 urgent help needed!!! yus000
@ 1997-03-31  0:00 ` Nick Roberts
       [not found]   ` <01bc3dd0$ff5bf600$7e0464c3@edi-c>
  1997-03-31  0:00 ` Robert Dewar
  1997-04-01  0:00 ` Larry Kilgallen
  2 siblings, 1 reply; 5+ messages in thread
From: Nick Roberts @ 1997-03-31  0:00 UTC (permalink / raw)





In reply to the urgent plea of yus000@unbc.edu in article
<859690935.9677@dejanews.com>, my reply is as follows.

Dear YUS,

Looking at your code, I can spot a few simple errors. Look carefully at
your implementation of Push, it doesn't quite do what is required. Also,
look again at the parameter mode for Print. You have forgotten to decrement
Count in Pop.

Otherwise, your code looks very good (if a little messy, perhaps :-). 

I must confess, I cannot see why the compiler should be giving you the
error message it does. All I can think of is that a previous version of
Ordered_Stack is in the library [and this has a different definition of the
type Stack which is indefinite (so that an object of the type could not
be declared)]. Certainly the type Stack as declared in the code you show is
a definite type.

So, the answer may be to try a 'full rebuild'. Failing this, you may wish
to try deleting the library units Ordered_Stack specification and body from
the library, and then rebuilding.

Also, remember that the order in which you present units to the compiler in
a single source text file is the order in which they are going to be
compiled. If you have all three units presented in your posting in one
file, you should either split them into separate files (recommended), or
rearrange them so they occur in the following order: Ordered_Stack
(specification); Ordered_Stack (body); Main.

Finally, delete the 'testorder' procedure, it's doing you no good.

Remember: Ada programmers are the BEST programmers!

Nick.






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

* Re: urgent help needed!!!
  1997-03-29  0:00 urgent help needed!!! yus000
  1997-03-31  0:00 ` Nick Roberts
@ 1997-03-31  0:00 ` Robert Dewar
  1997-04-01  0:00 ` Larry Kilgallen
  2 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1997-03-31  0:00 UTC (permalink / raw)



yus000@unbc.edu asks for help on an assignment.

I really encourage people to do no more than point this student in the
right direction to find the answer for himself. There are two points here.

Always remember that the purpose of assignments is not to solve a problem,
but to LEARN HOW to solve a problem on your own. It is all too easy for
people trying to be helpful to solve students problems for them and 
thus short ciruit the real purpose of the assignment.

Second, there are thousands of students learning Ada. If any appreciable
fraction of them followed yus000's lead, then CLA would be swamped with
beginners looking for other people to do their assignments for them,
and CLA would become useless.





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

* Re: urgent help needed!!!
       [not found]   ` <01bc3dd0$ff5bf600$7e0464c3@edi-c>
@ 1997-03-31  0:00     ` Nick Roberts
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Roberts @ 1997-03-31  0:00 UTC (permalink / raw)




Kurt Svensson <edi-c@algonet.se> wrote in article
<01bc3dd0$ff5bf600$7e0464c3@edi-c>...
> Nick Roberts <Nick.Roberts@dial.pipex.com> wrote:
> > Remember: Ada programmers are the BEST programmers!
> 
> Can You please explain that?

Just showing my prejudice, Kurt! I really do believe that Ada is a superior
language (in general) to others, which shall remain nameless, whose designs
are a dog's breakfast by comparison. (No offence intended to dogs :-)
Thus, Ada is the best, and so are the programmers who use it! No? Perhaps
I'm just getting old.
Nick [:-)





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

* Re: urgent help needed!!!
  1997-03-29  0:00 urgent help needed!!! yus000
  1997-03-31  0:00 ` Nick Roberts
  1997-03-31  0:00 ` Robert Dewar
@ 1997-04-01  0:00 ` Larry Kilgallen
  2 siblings, 0 replies; 5+ messages in thread
From: Larry Kilgallen @ 1997-04-01  0:00 UTC (permalink / raw)



In article <859690935.9677@dejanews.com>, yus000@unbc.edu writes:
> Hi, i have a urgent question.

No, an urgent question would have warranted a descriptive subject.




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

end of thread, other threads:[~1997-04-01  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-29  0:00 urgent help needed!!! yus000
1997-03-31  0:00 ` Nick Roberts
     [not found]   ` <01bc3dd0$ff5bf600$7e0464c3@edi-c>
1997-03-31  0:00     ` Nick Roberts
1997-03-31  0:00 ` Robert Dewar
1997-04-01  0:00 ` Larry Kilgallen

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