SOLUTION RATED A+
✔✔Composite types - ✔✔− have internal structure, defined in terms of simpler types−
arrays, records, sets, lists
✔✔Boolean (Scalar type) - ✔✔implemented on one byte, 1 → true, 0 → false
✔✔Character (Scalar type) - ✔✔− one byte - ASCII encoding− two bytes ("wide
characters") - Unicode character set (Java)
✔✔Integer (scalar type) - ✔✔− length may not be specified by language - vary with
implementation− signed or unsigned varieties
✔✔Fixed point (scalar type) - ✔✔− represented as integers, but with implied decimal
point at aspecified position− currency values: 129.99
✔✔Floating point (real) (scalar type) - ✔✔− internally represented as sign s, mantissa m
and exponent exp− value = (-1)s x m x 2exp
✔✔Compex (scalar type) - ✔✔pair of floating point numbers - real and imaginary parts
✔✔Rational (scalar type) - ✔✔pair of integers - numerator and denominator
✔✔Enumeration Types - ✔✔a type whose legal values consist of a fixed set of
constants
• Values are ordered - allows for comparisons: mon < tue• Predecessor and successor:
tomorrow := succ (today);
• Enumeration-controlled loops:for today := mon to fri do begin ...
• Index in arrays:var daily_attendance : array [weekday] of integer;daily_attendance
[mon] := 40;
• Ordinal value:ord (sun) => 1
✔✔Subrange types - ✔✔contiguous subset of values from a discretebase type
✔✔Why are subranges useful (why not just use integers)? - ✔✔− easier to
read/document programs
− semantic checks to ensure values are within range
− efficient representation
− test_score can be represented on a single byte
✔✔Record (structure) (composite type) - ✔✔− introduced in Cobol
− collection of fields, with (potentially different) simpler types
− mathematical formulation: type of a record. Cartesian product of field types
, ✔✔Variant record (composite type) - ✔✔− only one field is valid at any moment
− type of a variant record: union of field types
✔✔Array (composite type) - ✔✔− components have the same type
− type of an array: function that maps an index type to a componenttype
✔✔Set (composite type) - ✔✔− collection of distinct elements of a base type
✔✔Pointer (composite type) - ✔✔-reference to an object of the pointer's base type
✔✔Lists (composite types) - ✔✔− sequence of elements, no indexing
− implemented as linked lists
✔✔Files (composite type) - ✔✔− notion of current position
− usually accessed in sequential order
✔✔Type Equivalence - ✔✔Two ways to define type equivalence:
− Structural equivalence - same components, put together in the same way
− Name equivalence - each definition introduces a new type
✔✔Name Equivalence - ✔✔Variants:
− Strict name equivalence - aliased types considered distinct.
− Loose name equivalence - aliased types considered equivalent
✔✔Strict name equivalence - ✔✔In strict name equivalence, two types are considered
equivalent only if they have the exact same name.
This means that even if two types have the same structure, properties, and operations,
they are not considered equivalent unless they share the exact same name.
✔✔Loose name equivalence - ✔✔In loose name equivalence, two types are considered
equivalent if they have compatible structures, properties, and operations, even if their
names are different.
✔✔Type Conversion and Casts - ✔✔− Assume that the type provided and the
typeexpected are required to be the same
− Need to use casts - explicit conversions
− Does it involve additional code at run-time?
----
Several cases:
− Types would be structurally equivalent, but language uses name equivalence
- types use same representation
− conceptual conversion → no additional code