From: "Egil Høvik" <egilhovik@hotmail.com>
Subject: Re: Ada code snippet help (array of arrays)
Date: Thu, 14 May 2009 01:05:12 -0700 (PDT)
Date: 2009-05-14T01:05:12-07:00 [thread overview]
Message-ID: <5628eb43-3d56-4b20-976a-6bb0f40dcd49@s31g2000vbp.googlegroups.com> (raw)
In-Reply-To: b6f7e019-522b-4eb8-9bb3-ae920d98a06d@n21g2000vba.googlegroups.com
On May 13, 4:11 pm, Vamp4L <vampir...@gmail.com> wrote:
> Trying to figure out why my code doesn't work
> This line in particular doesn't compile "if Theater(Seat)(reserved) =
> F then" :
>
> with Ada.Text_Io; use Ada.Text_Io;
> procedure Ch4Ex22 is
> package Int_Io is new Integer_Io(Integer);
> use Int_Io;
> package Boolean_Io is new Enumeration_Io(Boolean);
> use Boolean_Io;
>
> T: constant Boolean := True;
> F: constant Boolean := False;
No need to define your own constants... True and False are
already enumerated values (constants) of type Boolean.
> type Seatattributes is (Reserved, Balcony);
> type SeatType is array(SeatAttributes) of Boolean;
Attributes of a type are usually represented as a record:
type Seating is
record
Reserved : Boolean;
Balcony : Boolean;
end record;
> type Theater is array (1..50) of SeatType;
> A: Theater := (1=>(T,F),2..7=>(F,F),8=>(T,F),9..15=>(F,F),16=>
> (T,F),
> 17..23=>(F,F),24=>(T,F),25..29=>(F,F),30..31=>(F,T),32=>(T,T),
> 33..49=>(F,T),50=>(T,T));
>
How about:
A : Theater := (
1 | 8 | 16 | 24 => (Reserved => True, Balcony => False),
2..7 | 9..15 | 17..23 | 25..29 => (Reserved => False, Balcony =>
False),
30..31 | 33..49 => (Reserved => False, Balcony => True),
32 | 50 => (Reserved => True, Balcony => True ));
> begin
>
> for Seat in Theater'range loop
> if Theater(Seat)(reserved) = F then
> Put(Seat, 1); New_Line;
> end if;
> end loop;
>
> end Ch4Ex22;
next prev parent reply other threads:[~2009-05-14 8:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-13 14:11 Ada code snippet help (array of arrays) Vamp4L
2009-05-13 14:25 ` Georg Bauhaus
2009-05-13 14:28 ` Vamp4L
2009-05-13 15:05 ` Jacob Sparre Andersen
2009-05-14 8:05 ` Egil Høvik [this message]
2009-05-14 15:16 ` Adam Beneschan
2009-05-14 17:14 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox