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

Pascal allows the use of enumerated types as index types. For example, if we def

ID: 3838880 • Letter: P

Question

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.

Explanation / Answer

Some early programming dialects did not initially have counted sorts. In the event that a software engineer needed a variable, for instance myColor, to have an estimation of red, the variable red would be announced and doled out some discretionary esteem, for the most part a whole number steady. The variable red would then be appointed to myColor. Different strategies doled out discretionary qualities to strings containing the names of the enumerators.
These subjective qualities were some of the time alluded to as enchantment numbers since there frequently was no clarification in the matter of how the numbers were acquired or whether their genuine qualities were noteworthy. These enchantment numbers could make the source code harder for others to comprehend and keep up.
Specified sorts, then again, make the code more self-archiving. Contingent upon the dialect, the compiler could consequently appoint default qualities to the enumerators in this way concealing pointless detail from the software engineer. These qualities may not be unmistakable to the developer (see data covering up). Specified sorts can likewise keep a software engineer from composing unreasonable code, for example, performing scientific operations on the estimations of the enumerators. On the off chance that the estimation of a variable that was allocated an enumerator were to be printed, some programming dialects could likewise print the name of the enumerator as opposed to its hidden numerical esteem. A further favorable position is that listed sorts can enable compilers to authorize semantic rightness. For example:
myColor = TRIANGLE
can be prohibited, while
myColor = RED
is acknowledged, regardless of the possibility that TRIANGLE and RED are both inside spoken to as 1.
Theoretically, a specified sort is like a rundown of nominals (numeric codes), since every conceivable estimation of the sort is doled out a particular common number. A given identified sort is in this manner a solid usage of this thought. At the point when request is important as well as utilized for correlation, then an identified sort turns into an ordinal sort.