comp.lang.ada
 help / color / mirror / Atom feed
* Information hiding and Stream IO
@ 2001-04-07 20:52 chris.danx
  2001-04-08  6:23 ` chris.danx
  0 siblings, 1 reply; 2+ messages in thread
From: chris.danx @ 2001-04-07 20:52 UTC (permalink / raw)


Hi again folks,

The question follows this introduction


------------------------ beginning of introduction

I devised the following example:

At a kenel, the records of owners and their dogs are stored in a file.
Unfortuanately the guy who programmed the computer system didn't do a very
good job.  He decided to store the information on the owner and their dog in
a file one after the other like this

Owner, Dog, Owner, Dog, ...

He wanted each owner to be followed by the dog he/she owned, but he's been
careless; the records have become jumbled.  It still follows the owner, dog,
owner pattern but the information on each dog doesn't follow on from the
information on that dog's owner.

You're task is to write a program that reads the records of 10 owners and 10
dogs from the file and create a new file and write the records to it so that
the record of the each dog follow their owners record.

The record on the owner looks like this

type owner_type     is record
                            name        :    name_type;  -- the name;
                            name_len  :   natural;    -- the names length;
                            age           :   natural;    -- age of person;
                            sex           :   sex_type;   -- sex of person;
                               end record;

and that of the dog looks like

type dog_type      is record
                            name          :   dog_name_type;   -- name of
dog;
                            name_len    :   natural;         -- dog name
length;
                            age             :   natural;         -- age of
dog;
                            sex             :   sex_type;        -- sex of
dog;
                            owner         :   owner_name_type; -- owners
name;
                            owner_len   :   natural;         -- owner name
length;
                         end record;

where owners have names of max 30 characters and dogs 10.

and sex_type is
    type sex_type is (female, male);

------------------ end of introduction

I've got a package Owners, which contains a type Owner_Type and some
operations like My_Name, My_Age, My_Sex.

I've also got another package Doggies containing the type Dog_Type and
similar operations with the inclusion of My_Owner.

The example is meant to use streams for files.  Now i've got a tricky
problem, which relates to this example.  I'd like to put the IO routines in
a child package of Owners, and Doggies.

I don't know if i can do this however as Owner_Type and Dog_Type are both
private types.

I should have two routines for each one,

            Owner_Type'read
and      Owner_Type'write

Which ideally i'd like to put in child package but i don't know if this will
work since i've got to access each field in the record separately.  There is
the possibility to use the standard ones provided for each type, but that'd
not make a good example.

What should i do?


I'm just about to start coding the first program which creates the file with
10 owners and 10 dogs all jumbled.


Cheers,
Chris Campbell






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

* Re: Information hiding and Stream IO
  2001-04-07 20:52 Information hiding and Stream IO chris.danx
@ 2001-04-08  6:23 ` chris.danx
  0 siblings, 0 replies; 2+ messages in thread
From: chris.danx @ 2001-04-08  6:23 UTC (permalink / raw)


Hi,

I decided to settle for functions returning each field, rather than make the
type public.

Not ideal, but better than letting people intimately mess with the record.


Regards,
Chris Campbell

p.s. it wasn't homework! It was for Ada Examples pages at Willow.





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

end of thread, other threads:[~2001-04-08  6:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-07 20:52 Information hiding and Stream IO chris.danx
2001-04-08  6:23 ` chris.danx

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