From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,697fa9e83df511c1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-22 10:45:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3CEBD61F.84A70F3C@raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Help setting up an array of records References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 22 May 2002 12:32:15 -0500 NNTP-Posting-Host: 192.27.48.39 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1022088760 192.27.48.39 (Wed, 22 May 2002 12:32:40 CDT) NNTP-Posting-Date: Wed, 22 May 2002 12:32:40 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:24536 Date: 2002-05-22T12:32:15-05:00 List-Id: Matt Thomas wrote: > [help for homework] > I'm using an array of records to represent the items in the vending machine > but I dont know how to actually get the information into my array. I need > to specify the name of the item, its cost and the quantity left. > > Here is the record and array declaration, any help would be grateful. > > MACHINE_SLOTS : constant := 6; -- > > type PRODUCT_TYPE is > record > NAME : STRING (1..12); > LEN : POSITIVE; > PRICE : INTEGER; > QUANTITY : INTEGER; > end record; > > type PRODUCT_TYPE_ARR is array (1..MACHINE_SLOTS) of PRODUCT_TYPE; > > PRODUCT : PRODUCT_TYPE_ARR; You didn't say much, so I can't judge what you know or don't know. You also didn't say which text book you are using, so I'll make a couple references to the ever so helpful Ada Reference Manual :-). [I don't recommend reading the ARM unless you want to be a "language lawyer" because it is not so easy to read...] You could look up the terms I refer to in your text book to find the chapters where this is described. - 4.1 Names, o 4.1.1 - indexed components (into the array) o 4.1.3 - selected components (elements of the record) the methods described can be combined to refer to a single (or more than one) component of the record within a single component (or slice) in the array - 4.2 Literals, a specific value of the appropriate type - 4.3 Aggregates, o 4.3.1 - record aggregates (for Product_Type) o 4.3.3 - array aggregates (for Product_Type_Arr) if you want to initialize several values at once (e.g., an "empty product") - 5.2 Assignment statement, to replace the current value of a variable with the result of an expression There is a lot more than what I refer to that will likely confuse at this point. For example, continue to use simple types until you understand the rules of type conversion. Don't use slices unless you clearly understand them as well. Do a simple example first and generalize until you understand the basic rules. --Mark