Board index » delphi » I need help with Pascal assignment!!!

I need help with Pascal assignment!!!

Hi there,
I have the following assignment at school with which I'm having a little
trouble --> I have a problem with understanding it.  Could you provide me
with a descriptive (visual? - how the array would actually look, etc.)
explanation of the problem (please do not post the reply - e-mail me at
pawel...@igs.net ).  I've been trying to cope with it myself but I guess
I'm just not used to this type of programming problems.  Your help would be
very much appreciated!  Here is the example:

given:
~~~~~~

type    Generation = (Unborn, First, Second);
        Community = record
                        Age: Generation;
                        Occupants: integer;
                    end;
        Land = array [1..49][1..49] of Community;

var Board: Land;

the question:
~~~~~~~~~~~~~

Write a procedure that initializes Board (passed in as a var parameter).
It should read in coordinates from the user and settle each selected
component with a single first-generation component.  Continue until the
user enters 0 0  for a coordinate.  All other components should be given
zero unborn occupants.

Thanx!

Sincerely, Pawel.

 

Re:I need help with Pascal assignment!!!


Sorry my friend,

i'm not gonna do your homework. Good luck. Do it yourself and you feel a
victory upon yourself!

Anco.

Re:I need help with Pascal assignment!!!


Quote
> i'm not gonna do your homework. Good luck. Do it yourself and you feel a
> victory upon yourself!

Boy, I sure hope you aren't a teacher.  Asking for help isn't
the same as asking for the answer.

-Erik Johnson
e...@phidias.colorado.edu
http://phidias.colorado.edu/vgallery.html

Re:I need help with Pascal assignment!!!


In article <01bb99fc$bf35c100$3f11f...@host.igs.net>

Quote
Pawel Michalowski wrote:
>Hi there,
>I have the following assignment at school with which I'm having alittle
>trouble --> I have a problem with understanding it.  Could you provideme
>with a descriptive (visual? - how the array would actually look, etc.)
>explanation of the problem (please do not post the reply - e-mail meat
>pawel...@igs.net ).  I've been trying to cope with it myself but Iguess
>I'm just not used to this type of programming problems.  Your helpwould be
>very much appreciated!  Here is the example:

>given:
>~~~~~~

>type        Generation = (Unborn, First, Second);
>    Community = record
>                    Age: Generation;
>                    Occupants: integer;
>                end;
>    Land = array [1..49][1..49] of Community;

>var Board: Land;

>the question:
>~~~~~~~~~~~~~

>Write a procedure that initializes Board (passed in as a varparameter).
>It should read in coordinates from the user and settle each selected
>component with a single first-generation component.  Continue untilthe
>user enters 0 0  for a coordinate.  All other components should begiven
>zero unborn occupants.

All variables and structures physically exist as a series of bytes.  
Your land structure will consist of 7,203 bytes.  This will be a
sequence consisting of 1-byte for age, 2-bytes for occupants, 1-byte
for age, 2-bytes for occupants, ... that will repeat a total of 2,401
times (49*49).  The 2-byte integers will appear as least significant
byte first, followed by the most significant byte.  

The actual arrangement of this structure in memory is not something
that we would find very comfortable to work with.  For this reason,
we have developed high level languages to organize things in a manner
that is more in line with the way most of us think.  in this case we
would find it more comfortable to look at "land" as a two dimensional
array, or matrix.  To achieve this view, we mentally position 49
occurrences of age and occupants on a line, then begin a new line, or
row, placing another 49 records in sequence under the first.  

We continue to mentally construct rows consisting of 49 repetitions
of age & occupation until we have completed 49 rows.  We don't often
find the linear series of 1-byte age and 2-byte occupants to be very
comfortable.  Unless you are doing some low level manipulations we
really don't care to even consider how may bytes are used by the
variables.  Instead, it is often more comfortable to simply view
age and occupants as two variables that form a simple list.

   age:
   Occupation:

The logical view that "land" portrays in my mind is simply a matrix
of 49 by 49 lists of age and occupants.

      1     2     3     4     5     .....   48    49
    +-----+-----+-----+-----+-----+       +-----+-----+
  1 | age | age | age | age | age | . . . | age | age |
    | occ | occ | occ | occ | occ |       | occ | occ +
    +-----+-----+-----+-----+-----+       +-----+-----+
  2 | age | age | age | age | age | . . . | age | age |
    | occ | occ | occ | occ | occ |       | occ | occ +
    +-----+-----+-----+-----+-----+       +-----+-----+
  3 | age | age | age | age | age | . . . | age | age |
    | occ | occ | occ | occ | occ |       | occ | occ +
    +-----+-----+-----+-----+-----+       +-----+-----+
      .      .     .     .     .             .     .
      .      .     .     .     .             .     .
    +-----+-----+-----+-----+-----+       +-----+-----+
 48 | age | age | age | age | age | . . . | age | age |
    | occ | occ | occ | occ | occ |       | occ | occ +
    +-----+-----+-----+-----+-----+       +-----+-----+
 49 | age | age | age | age | age | . . . | age | age |
    | occ | occ | occ | occ | occ |       | occ | occ +
    +-----+-----+-----+-----+-----+       +-----+-----+

In this logical view records are accessed by referencing row and
column.  Thus Land[1,2] is the seconds cell of the first row and
Land[49,5] is the fifth cell of the 49th row.  Extending this one
step further we have Land[12,48].Age referring to the age of the 48th
community in the 12th row.

As you can see, the logical view I perceive in my mind is far easier
than trying to make order out of a sequence of 7,203 bytes.  I
suggest  you "paint" similar pictures of data in your mind using a
logical structure that makes it easier for you to envision the task
at hand.  

One of the benefits of using a programming language is so that we
don't have to worry or be overly concerned with the physical view of
bits and bytes, but may look at things in a logical way, creating a
matrix here and a list there and not really caring where here or
there might actually be.  So don't spend too much time trying to box
yourself in.  You'll find that each programming language creates a
different kind of prison.  No need to make things worse.  :-)

Hope this helps.

    ...red

Other Threads