Structured data types

Set type

A special place among the data types has a set type that can also contain those values that are sets in turn (allows you to work with some types of sets in a similar way as it is in mathematics). In Lazarus, respectively in Pascal, it is allowed to create sets composed only of elements of the same ordinal type - we call it the base (basic) type.

We can create a set of characters, numbers, days of the week, but we cannot create such a set which would include e. g. numbers and characters. The definition of the data type set is always with the definition of its base type, e. g.

type

Set = set of 1...100;

var

a, b:Set;


We can only assign sets to variables a, b, we can manipulate them with set operations and sessions - we cannot directly write or read them to/from the file, we have to program it.


Operations

+   unification 

-   division

*   intersection 

in   the existence of an element in a set

 smaller

 bigger  

=   equal 

<=   smaller or equal 

>=   bigger or equal

<>   not equal 


Field type

Fields are structured data types, each one of the field elements being composed from a fixed number of components of the same type, that is, we speak of a homogeneous data type. Field elements can be any standard of predefined type.

Each component can be precisely named by index. Indices (the "position" of the element in the field) acquire values of a certain type that must be ordinal. We call it the type index. Through this index, we have direct access to individual field elements. We define the field type as follow:

type

Field=array[index type] of elements_type;


Fields can be single- and multi-dimensional. A one-dimensional array is a series of the same properties that are described by one identifier (field name). Sometimes we call them vectors. A two-dimensional array can also be called a table or matrix. We say that a two-dimensional field is also a vector of vectors or a field of one-dimensional arrays.

When we declare (create) a field, it contains no elements. We must first add some elements, so we need to "fill" the field. This is done by using the assignment command (e. g. a [20] := 10). If any part in a field has an assigned value, we fill it again, so its original value is changed to new, that is, the original value is overwritten. 


Character string type

The character string is a character sequence (closed in apostrophes) that is the identifier string. This data type is introduced specifically in Pascal, which provides procedures and functions for working with this data type. Maximum string length is 255 characters. In the computer´s memory, the string is stored in as many bytes as is its length, plus one. In the zero byte, the string contains the actual string length - how many characters the string contains (the zero is not considered). For a string statement, we can also specify the maximum word length in (square) brackets [ ]. 


Operations

<   smaller

>   bigger

=   equal 

<=   smaller or equal

>= bigger or equal

<> not equal


Standard functions

Length(S)               finds the current chain length (S is a string)

Concat(S1, S2)      combines to strings

Copy(S, I, Maxint) selects the sub-chain from the string (I is the position from

                                        which we start to pick; Maxint determines how many

                                        characters we choose)

Delete(S, I, Maxint)          cancels the sub-string in the string (in this case 

                                           Maxint determines how many characters are 

                                           cancelled)

Insert(S, S1, I)                   inserts a sub-string into a string (S is a string which 

                                          we insert; S1 is a string into which we insert; I 

                                          determines from which character we want to insert)

Pos(S)                               finds the sub-chain position in the string


Record type

One of the basic methods of creating structured data is to link several components of various types into a complex. In mathematics, structures are created in this way called n-tics. This is, for example, date (three numbers with meaning day, month, year) or a citizen´s ID card (contains entries name, surname, date of birth, number of the citizenship card, etc.).

The record type identifier is a record, and this data structure is non-homogeneous and consists of a number of named components that can be of different types and we call it their record items. The names and types of record items are specified by the type description record that has the shape

record

entry1:tp;

entry2:tp;

end


where entry i is the name of the i-th item and tp is the entry type. Record items are standard defined as variables, and we can access individual records of record type variables using the record selector, which is a dot ".". We assign values to individual items using the assignment command. 


File type

When working with your computer and data, it is important to store it after turning off the computer, or after closing the program. The processed data must be stored on an external memory-disk drive. Writing and reading the necessary data from external storage media is mediating us the data type file whose identifier is file. This is a structured data type that consists of a theoretically unlimited number of files of the same type. The number of file folders is limited by the memory capacity.

File properties depend on its type. The file may be a character file, so it will consist of characters only, or an integer file, so it will contain whole numbers only. There is only one file available while processing that is determined by an indicator (under which we will understand some imaginary arrow showing just one file folder).

Very important is the end of the file. We know three file types:

  1. Files without a specified type - it is not determined what kind of data type its components will be.
  2. Files with type listing - it is determined in advance what kind of data type its components will be.
  3. Text files - a special type; a sequence whose components are the characters and line separators.
Vytvorte si webové stránky zdarma! Táto stránka bola vytvorená pomocou služby Webnode. Vytvorte si vlastný web zdarma ešte dnes! Vytvoriť stránky