Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Data types and structures Pascal allows the use of enumerated types as index typ

ID: 3832619 • Letter: D

Question

Data types and structures

Pascal allows the use of enumerated types as index types. For example, if we define the enumerated type GreatLakes to have the values Erie, Ontario, Huron, Michigan, and Superior (ordered here by increasing volume of water), then we can define:

type GreatLakes = (Erie, Ontario, Huron, Michigan, Superior);

area: array [ GreatLakes ] of integer,

elevation: array [ GreatLakes ] of real;

and give them values

area := ( 9910, 7340, 23000, 22300, 31700 );

elevation := ( 570.38, 244.77, 578.68, 578.68, 600.38 );

Now we can access individual elements to find, for example, that

area[Erie] = 9910

area[Superior] = 31700

elevation[Huron] = elevation[Michigan] = 576.68

In the above definitions we stored the areas and elevations of the Great Lakes in vectors (1- dimensional arrays). Restate these definitions in order to store the same information in a structure that is:

(a) A vector of records

For defining records, use the syntax:

Person: record

age: integer;

sex: (Male, Female); height, weight: real; married: Boolean

end;

(b) A record of vectors

(c) A 2-dimensional array indexed by type GreatLakes and by another enumerated type.

Please Give me answers for a) b) c)

Explanation / Answer

a.
type GreatLakes = (Erie, Ontario, Huron, Michigan, Superior);

TGreatLakes : record
Area : integer
Elevation : real
end;

TLakes: array [GreatLakes] of TGreatLakes
TLakes:= ( (9910, 570.38), (7340, 244.77), (23000, , 578.68), (22300, , 578.68), (31700, , 600.38 ) );


b.
TGreatLakes : record
   type GreatLakes = (Erie, Ontario, Huron, Michigan, Superior);
   area: array [ GreatLakes ] of integer,
   elevation: array [ GreatLakes ] of real;

   area := ( 9910, 7340, 23000, 22300, 31700 );
   elevation := ( 570.38, 244.77, 578.68, 578.68, 600.38 );
end;


c.
type GreatLakes = (Erie, Ontario, Huron, Michigan, Superior);
TGreatLakes : array[GreatLakes,0..1] of real;
TGreatLakes:= ( (9910, 570.38), (7340, 244.77), (23000, , 578.68), (22300, , 578.68), (31700, , 600.38 ) );