chap3_record
chap3_record
INTODUCTION
in computer science, a record (also called a structure, struct, or compound
data) is a basic data structure.A record is a collection of fields, possibly of
different data types, typically in a fixed number and sequence.The fields of a
record may also be called members, particularly in object-oriented
programming; fields may also be called elements, though this risks confusion
with the elements of a collection.
For example, a date could be stored as a record containing a numeric year field,
a month field represented as a string, and a numeric day-of-month field. A
personnel record might contain a name, a salary, and a rank. A Circle record
might contain a center and a radius—in this instance, the center itself might be
represented as a point record containing x and y coordinates.
Records are distinguished from arrays by the fact that their number of fields is
determined in the definition of the record, and by the fact the records are a
heterogenous data type; not all of the fields must contain the same type of data.[6
A record type is a data type that describes such values and variables. Most
modern computer languages allow the programmer to define new record types.
The definition includes specifying the data type of each field and
an identifier (name or label) by which it can be accessed. In type theory, product
types (with no field names) are generally preferred due to their simplicity, but
proper record types are studied in languages such as System F-sub. Since type-
theoretical records may contain first-class function-typed fields in addition to
data, they can express many features of object-oriented programming.
Records can exist in any storage medium, including main memory and mass
storage devices such as magnetic tapes or hard disks. Records are a fundamental
component of most data structures, especially linked data structures.
Many computer files are organized as arrays of logical records, often grouped
into larger physical records or blocks for efficiency.
Fn : typen;
END RECORD;
Or
type
record-name = record
field-1: field-type1;
field-2: field-type2;
...
field-n: field-typen;
end;
Example:
TYPE Employee IS RECORD
ID : IDType;
Name : NameType;
Gender : GenderType;
NumDepend : Natural;
Rate : NonNegFloat;
END RECORD;
Example:
TYPE Fraction IS RECORD
Numerator: Integer;
Denominator: Positive;
END RECORD;
To access any field of a record, we use the member access operator (.).
Example
Clerk : Employee;
Janitor : Employee;
Clerk.ID := 1234;
Clerk.Name := "Caryn Jackson ";
Clerk.Gender := Female;
Clerk.NumDepend := 3;
Clerk.Rate := 7.50;
Eample :
1- write an algorithm that sum two fraction
2- write an algorithm that sum two complexs numbers