comp.lang.ada
 help / color / mirror / Atom feed
From: "Eric G. Miller" <egm2@jps-nospam.net>
Subject: Re: Record concatenation?
Date: Sun, 09 Jun 2002 21:07:41 GMT
Date: 2002-06-09T21:07:41+00:00	[thread overview]
Message-ID: <pan.2002.06.09.21.09.33.835510.30775@jps-nospam.net> (raw)
In-Reply-To: d8wM8.115863$Ka.8171211@news2.calgary.shaw.ca

In <d8wM8.115863$Ka.8171211@news2.calgary.shaw.ca>, devine wrote:

> Can someone tell me how to concant records in ada? For example say you have
> a record:
> 
> TYPE Sales IS RECORD
>   SaleNo : Integer;
>   SalesmanNo : String(1..20);
> END RECORD;
> SalesData : Array(1..10) OF Sales;
> 
> The data for the record is read from a file, say the file contains:
> 1234 Some Name
> 1234 Some Name
> 1235 Someone Else
> 
> What is the easiest way to join the first 2 records so that if you write
> back to the file or display the data to the screen it displays:
> 1234 Some Name
> 1235 Someone Else
> 
> I was thinking of checking if the previous number was the same as the next
> number and then add the previous number to a subtotal, and if the number was
> diff it would do to the next number and so on. Is thier a simpler way?

You're not wanting concatenation, but elimination.  Easiest way is to sort
the records, then eliminate duplicates by comparing each record to its
predecessor (you always keep the first record of the sorted set).

If you're going to use arrays, you probably want to create an array
type for your sales, so the length can be easily varied.

type Sales_Array is array (Natural <>) of Sales;

-- write a comparison function
function "<" (Left, Right : Sales) return Boolean;

-- write a sort routine (quick sort...)
procedure Sort (Data : in out Sales_Array);

-- function returns a Sales_Array with unique entries
-- data must be in sorted order
function  Unique (Data : Sales_Array) return Sales_Array;



      reply	other threads:[~2002-06-09 21:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-08 23:08 Record concatenation? devine
2002-06-09 21:07 ` Eric G. Miller [this message]
replies disabled

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