comp.lang.ada
 help / color / mirror / Atom feed
* Record concatenation?
@ 2002-06-08 23:08 devine
  2002-06-09 21:07 ` Eric G. Miller
  0 siblings, 1 reply; 2+ messages in thread
From: devine @ 2002-06-08 23:08 UTC (permalink / raw)


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?





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

* Re: Record concatenation?
  2002-06-08 23:08 Record concatenation? devine
@ 2002-06-09 21:07 ` Eric G. Miller
  0 siblings, 0 replies; 2+ messages in thread
From: Eric G. Miller @ 2002-06-09 21:07 UTC (permalink / raw)


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;



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

end of thread, other threads:[~2002-06-09 21:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-08 23:08 Record concatenation? devine
2002-06-09 21:07 ` Eric G. Miller

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