In order for a machine to process any input data, it must “understand” what type the variables in which the values ​​are stored belong. In the absence of information about the data format, the computer will not be able to determine whether this or that operation is permissible in a particular case: for example, it is intuitively clear that it is impossible to raise a letter to a power or take the integral of a string. Thus, the user must determine what actions are allowed to be performed with each variable.

Just like in other programming languages high level, variable types in Pascal are optimized to perform tasks of various types, have a different range of values ​​and length in bytes.

Subdivision of variable types

Variable types in Pascal are divided into simple and structured. Simple types include real and ordinal types. Structured ones include arrays, records, sets and files. Separately, pointers, objects and procedural types are distinguished.

Let's look at ordinal and real types. Ordinal types include 5 integer types, enumeration type and range type.

Ordinal types

There are 5 integer types, differing in byte length and range of values.

The length of Byte and ShortInt is 1 byte. The difference between them is that Byte stores only non-negative values, while ShortInt allows you to store negative ones (from -128 to +127). The Word and Integer types relate to each other in a similar way, with the only difference being that their size is 2 bytes.

Finally, LongInt allows you to store both negative and positive values ​​using 4 bytes - in the 16th power of numeric dimension on either side of zero. Different kinds variables in Pascal contribute to the efficient solution of user tasks, since in each specific case both a small and a large range of values ​​may be required, and it is also possible that there are restrictions on the amount of allocated memory.

It is important to understand that zero takes up as much memory space as any other number. Thus, when forming a range of values, the minimum negative number in absolute value will be one greater than a positive one: for example, from -128 to +127.

Variables belonging to can take the value TRUE (true) or FALSE (false) and require 1 byte of memory.

The CHAR type allows you to store any of the many characters that exist in computer memory. At the same time, in symbolic variables in Pascal, only the code of the sign is actually stored, in accordance with which its graphic form is displayed.

Real types

Among the types of variables in Pascal, there are several numeric ones with the ability to write a fractional part. The differences between Single, Real, Double, and Extended types come down to the range of values ​​accepted, the number of significant digits after the decimal point, and the size in bytes.

According to the order presented above, a variable of each type will occupy 4, 6, 8 or 10 bytes.

Arrays

Structured data types are complex and allow you to combine a number of simple values ​​within a single variable. A prime example is an array, which can be defined as follows:

String=array of char;

Thus, we got a type called String, which allows us to define variables up to 100 characters long. IN last line a one-dimensional array Y of type String is directly specified. Variables in Pascal are described by placing the identifier on the left side and the variable value on the right, after the equal sign.

The range of indices written in allows access to each specific element of the array:

In this case, we read the second element of the previously created array Y.

String variables in Pascal are also a special case of a one-dimensional array, because a string is a sequence of characters, i.e. elements of the char type.

Posts

A record consists of several fields filled with data of any type except file. In general, this type of variable is similar to a database element. For example, you can enter a person’s name and phone number:

type NTel = Record

The first line on the left indicates the name of the type, and on the right - the service word record. The second line contains a field with a name, the third - a phone number. The word “end” means that we have entered all the fields we wanted, and this completes the process of creating a record.

Finally, in the last line we define the variable One, which is of type NTel.

You can access both the record as a whole and its individual components, for example: one.NAME (i.e. variable_name. record_field_name).

Files

Pascal allows you to work with text, typed and untyped files, which are a structured sequence of components that have the same type.

When reading from or writing to a file, either the full address or its short form can be used:

‘C:\Folder\File2.txt’

The short form is used when the file is placed in the folder where the program that accesses it is stored. Full form can be used in any circumstances.

Set variable file type can be done as follows:

f1: file of integer;

Used to work with files various functions and procedures that associate a variable with a file on disk, open it for reading, writing, and overwriting, closing it when finished, allowing you to create a new name, and deleting the file from the computer.

Finally

Without the ability to use Various types variables in Pascal, the user will not be able to implement even the simplest task. In order for the program to execute the algorithm without errors, you need to learn how function words, and syntax, since the machine can “understand” commands only if they are written in the only correct way.

The concept of type is one of the fundamental concepts of any programming language. Objects (constants, variables, functions, expressions) that the program operates on belong to a specific type.

Type is a set of values ​​that program objects can take, and a set of operations allowed on these values.

For example, the values ​​1 and 2 are of integer type and can be added, multiplied, and other arithmetic operations. The meanings “monitor” and “Pascal” are linguistic in nature; they have their own set of valid operations. In most commonly used languages, only strictly defined, pre-known types can be used. Pascal, along with the standard types found in other high-level languages, allows the programmer to create his own types.

All types allowed in the Pascal language are divided into two large groups: simple and complex (structured).

Type Range Mantissa, signs Required memory (bytes)
REAL 2.9*10E-39..1.7*10E38 11-12
SINGLE 1.5*10E-45..3.4*10E38 7-8
DOUBLE 5.0*10E-324..1.7*10E308 15-16
EXTENDED 1.9*10E-4951..1.1*10E4932 19-20
COMP -2E+63+1..2E+63-1 10-20

Effective use of the SINGLE, DOUBLE, EXTEND, COMP types is possible only when the ($N+) directive is enabled. By default it is turned off. To solve engineering and economic problems, values ​​of the REAL type are sufficient.

Example

Var Res, Summa, Itog: real;

Boolean the data type is described by the identifier BOOLEAN. Variables and constants of this type can take only one of two values: TRUE (true) or FALSE (false).

Example

Var Sel1, Sel2: boolean;

A,B,C,D: boolean;

Boolean expressions occupy 1 byte in memory and are used in logical expressions and relational expressions, as well as to control the order in which program statements are executed.

Literal (character) the type is described by the standard CHAR identifier. Constants and variables of this type can take one of the ASCII code table values. The meaning of a constant or variable of this type is enclosed in apostrophes.

For example, Var Bukva, Znak, Symbol: char;

Bukva:=’A’; Znak:=’+’; Symbol:=’!’

Character type variables occupy 1 byte in memory. The use of char data in arithmetic expressions is prohibited. Comparison operations can be applied to literal values, the result depending on the number of the literal variable or constant in the code table.

Except standard types data, Pascal supports scalar types, user defined. These include enumerable And interval types . These types of data occupy 1 byte in memory, so any custom type cannot contain more than 255 elements. Their use significantly improves the visibility of the program, makes it easier to find errors and saves memory.

Enum type is specified directly by listing all the values ​​that a variable of a given type can take. Individual values ​​are separated by commas, and the entire list is enclosed in parentheses.

Format

Type<имя типа>=(<значение1, значение2, ..., значениеN>);

Var<идентификатор, ...>: < имя типа>;

Example

Type Season =(Spring, Summer, Autumn, Winter);

Var S1, S2: Season;

Autumn: (September, October, Nowember);

IN in this example the explicitly described data type of the Season user is shown. Their meanings are determined - designations of the seasons. Variables S1 and S2 can take only one of the listed values. An attempt to assign them any other value will cause a software interrupt. The third type of enumeration is anonymous (has no name) and is specified by enumerating values ​​in the Var section. Autumn is a variable of this type and can take the values ​​September, October, Nowember. Thus, any type can be specified, but this is not always acceptable. The first method is certainly more understandable and more consistent with the nature of the Pascal language.

Interval type allows you to specify two constants that define the boundaries of the range of values ​​for a given variable. For each operation on an interval variable, the compiler generates check routines to determine whether the value of the variable remains within its specified range. Both constants must belong to one of the standard types other than real. The value of the first constant must necessarily be less than the value of the second.

Format

Type<имя типа> = <константа1> .. <константа2>;

Var<идентификатор>: < имя типа>;

Example

Type Days = 1.. 31;

Var Work_d, Free_d: Days;

In this example the variables Work_d, Free_d have type Days and can take any value from the range 1. . 31.

Exiting the range causes a software interrupt.

You can define an interval type by defining the range boundaries not by the values ​​of the constants, but by their names:

Const Min = 1; Max = 31;

Type Days = Min .. Max;

Var Work_d, Free_d: Days;

Structured types data types are based on scalar types and can contain various combinations of them. They define an ordered collection of scalar elements and are characterized by the type of their components. The Pascal language provides the following structured data types:

line - a sequence of characters enclosed in apostrophes;

array - a structured data type consisting of a fixed number of elements of the same type, accessed by index ;

a bunch of - a set of objects selected according to some characteristic or group of characteristics that can be considered as a whole;

record - a set of a fixed number of components of different types;

file- a sequence of components of the same type and the same length.

Two more structured types- procedural and object type - it is difficult to match the data in the usual representation.

Picture 1- A set of basic types of the Pascal language

The concept of data is one of the key ones in programming, and in computer science in general. Roughly speaking, data in computer science is information that is in a state of storage, processing or transmission over a certain period of time. In Turing machines, information has a type, and this in turn depends on the type of information.

Data types in Pascal define the possible values ​​of variables, constants, expressions, and functions. They are built-in and custom. Built-in types are initially present in the programming language, and custom types are created by the programmer.

According to the method of presentation and processing, data types are:

  • simple
  • structured
  • pointers
  • objects
  • procedures

This article will consider only the simplest data types, since at the initial stages of training, it will be easier for your program to do without, for example, files and records than without integer or string variables.

Integer type

This includes several integer types, which differ in the range of values, the number of bytes allocated for storing them, and the word with which the type is declared.

Type Range Size in bytes
shortint -128…127 1
integer -32 768…32 767 2
longint -2 147 483 648…2 147 483 647 4
byte 0…255 1
word 0…65 535 2

You can declare an integer variable in the Var section, for example:

All arithmetic and logical operations can be performed on variables in this category with the exception of division (/), which requires a real type. Some can also be applied standard features and procedures.

Real type

In Pascal there are the following real data types:

Type Range Memory, byte Number of digits
Real 2.9e-39 … 1.7e38 6 11-12
Single 1.5e-45 … 3.4e38 4 7-8
Double 5.0e-324…1.7e308 8 15-16
Extended 3.4e-4932 … 1.1e493 10 19-20
Comp -9.2e63…(9.2e63)-1 8 19-20

More operations and functions can be performed on them than on integers. For example, these functions return a real result:

sin(x) – sine;

cos(x) – cosine;

arctan(x) – arctangent;

ln(x) – natural logarithm;

sqrt(x) – square root;

exp(x) – exponent;

Boolean type

A variable of a Boolean data type can take only two values: true and false. Here, true corresponds to the value 1, and false corresponds to zero. You can declare a Boolean variable like this:

Comparison and logical operations can be performed on data of this type: not, and, or, xor.

Character type

A character data type is a collection of characters used in a particular computer. A variable of this type takes the value of one of these characters and occupies 1 byte in computer memory. Word Char defines a value of this type. There are several ways to write a character variable (or constant):

  1. as a single character enclosed in apostrophes: ‘W’, ‘V’, ‘p’;
  2. by specifying the character code, the value of which must be in the range from 0 to 255.
  3. using the ^K construction, where K is the control character code. The value of K must be 64 greater than the corresponding control character code.

Relational operations and the following functions are applicable to values ​​of a character data type:

Succ(x)- returns the next character;

Pred(x)- returns the previous character;

Ord(x)- returns the value of the character code;

Chr(x)- returns the value of a symbol by its code;

UpCase(x)- converts letters from the interval ‘a’..’z’ to upper case.

To work effectively with a character type, I recommend using .

String type

A string in Pascal is a sequence of characters enclosed in apostrophes, and is denoted by the word String. The number of characters (line length) must not exceed 255. If the length of the line is not specified, it will automatically be determined to be 255 characters. The general form of a string variable declaration looks like this:

Var<имя_переменной>:string[<длина строки>];

Each character in a line has its own index (number). The index of the first byte is 0, but it does not store the first character, but the length of the entire string, which means that a variable of this type will occupy 1 byte more than the number of variables in it. The number of the first character is 1, for example, if we have the string S=‘stroka’, then S=s;. In one of the following lessons, the string data type will be discussed in more detail.

Enumerated data type

An enumerated data type represents a limited number of identifiers. These identifiers are enclosed in parentheses and separated by commas.

Type Day=(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);

Variable A can only take the values ​​specified in the Type section. You can also declare a variable of enumerated type in the Var section:

Var A: (Monday, Tuesday);

TO this type relational operations are applicable, and it is predetermined that Monday

Interval data type

When it is necessary to specify a range of values, then in such situations the interval data type is used. The construction used for the declaration is m..n, Where m is the minimum (initial) value, and n– maximum (final); here m and n are constants, which can be of integer, character, enumeration or boolean type. Values ​​of interval type can be described both in the types section and in the variable description section.

General form:

TYPE<имя_типа> = <мин. значение>..<макс. значение>;

Federal Agency for Education

Essay

"DATA TYPES IN PASCAL"

1. Data types

Any data, i.e. constants, variables, properties, function values ​​or expressions are characterized by their types. A type defines the set of valid values ​​that an object can have, as well as the set of valid operations that can be applied to it. In addition, the type also determines the format of the internal representation of data in the PC memory.

In general, the Object Pascal language is characterized by a branched structure of data types (Fig. 1.1). The language provides a mechanism for creating new types, thanks to which the total number of types used in a program can be as large as desired.

The data processed in the program is divided into variables, constants and literals:

Constants represent data whose values ​​are set in the constant declaration section and do not change during program execution.

Variables are declared in the variable declaration section, but unlike constants, they receive their values ​​during program execution, and these values ​​can be changed. Constants and variables can be referred to by name.

Literal has no identifier and is represented directly by the value in the program text.

Type defines the set of values ​​that data elements can take and the set of operations allowed on them.

This and the four subsequent chapters provide detailed descriptions of each type.

1.1 Simple types

Simple types include ordinal, real, and datetime types.

Ordinal types differ in that each of them has a finite number of possible values. These values ​​can be ordered in a certain way (hence the name of the types) and, therefore, each of them can be associated with some integer - the ordinal number of the value.

Real types, strictly speaking, also have a finite number of values, which is determined by the format of the internal representation of a real number. However, the number of possible values ​​of real types is so large that it is not possible to associate an integer (its number) with each of them.

Date-time type designed to store date and time. In fact, it uses the real format for these purposes.

1.1.1 Ordinal types

Ordinal types include (see Figure 1.1) integer, logical, character, enumerated, and range types. The Ord(x) function can be applied to any of them, which returns the ordinal number of the value of the expression X.


Rice. 1.1 - Data type structure

For whole types, the function ord(x) returns the value of x itself, i.e. Ord(X) = x for x belonging to any whole type. Applying Ord(x) to logical , symbolic and enumerable types gives a positive integer in the range 0 to 1 ( boolean type), from 0 to 255 ( symbolic), from 0 to 65535 ( enumerable). Type-range preserves all the properties of the base ordinal type, so the result of applying the ord(x) function to it depends on the properties of this type.

You can also apply functions to ordinal types:

pred(x)- returns the previous value of the ordinal type (the value that corresponds to the ordinal number ord(x) -1, i.e. ord(pred(x)) = ord(x) - 1;

succ(x)- returns the next value of the ordinal type, which corresponds to the ordinal number ord(x) +1, i.e. ord(Succ(x)) = ord(x) + 1.

For example, if a program defines a variable

then the function PRED(c) will return the character "4", and the function SUCC(c) will return the character "6".

If we imagine any ordinal type as an ordered set of values ​​increasing from left to right and occupying a certain segment on the number axis, then the function pred(x) is not defined for the left end, and succ (x) is not defined for the right end of this segment.

Integer types . The range of possible values ​​of integer types depends on their internal representation, which can be one, two, four, or eight bytes. In table 1.1 shows the names of integer types, the length of their internal representation in bytes and the range of possible values.

Table 1.1 - Integer types

Name Length, bytes Range of values
Cardinal 4 0. .. 2 147 483 647
Byte 1 0...255
Shortint 1 -128...+127
Smallint 2 -32 768...+32 767
Word 2 0...65 535
Integer 4
Longint 4 -2 147 483 648...+2 147 483 647
Int64 8 -9*1018...+9*1018
LongWord 4 0. . .4 294 967 295

Types LongWord And Int64 were first introduced in version 4, and the types Smallint And Cardinal not available in Delphi 1. Type integer for this version it takes 2 bytes and has a value range from -32768 to +32767, i.e. the same as Smallint .

When using procedures and functions with integer parameters, you should be guided by the “nesting” of types, i.e. wherever it can be used word, allowed to use Byte(but not vice versa), in Longint“enters” Smallint, which in turn includes Shortint .

The list of procedures and functions applicable to integer types is given in table. 1.2. The letters b, s, w, i, l denote expressions of the following type: Byte , Shortint, Word, Integer and Longint ,

x is an expression of any of these types; the letters vb, vs, vw, vi, vl, vx denote variables of the corresponding types. An optional parameter is indicated in square brackets.

Table 1.2 - Standard procedures and functions applicable to entire types

Appeal Result type Action
abs(x) x Returns module x
chr(b) Char Returns a character by its code
dec(vx[,i]) - Decreases the value of vx by i, and in the absence of i - by 1
inc(vx[,i]) - Increases the value of vx by i, and in the absence of i - by 1
Hi(w) Byte Returns the highest bow of the argument
Hi(I) Same Returns the third byte
Lo(i) Returns the low byte of the argument
Lo(w) Same
odd(l) Boolean Returns True if the argument is an odd number
Random(w) Same as parameter Returns a pseudorandom number uniformly distributed in the range 0...(w-l)
sqr(x) X Returns the square of the argument
swap(i) Integer Swaps bytes in a word
swap(w) Word Same

When operating with integers, the result type will correspond to the type of the operands, and if the operands are of different integer types, the general type that includes both operands. For example, when operating with shortint And word the common type will be integer. In the default setting, the Delphi compiler does not produce code to check whether a value is out of range, which can lead to misunderstandings.

Boolean types . Logical types include Boolean, ByteBool, Bool, wordBool And LongBool. In standard Pascal, only the type is defined Boolean, other logical types are introduced into Object Pascal for compatibility with Windows: types Boolean And ByteBool each takes up one byte, Bool And WordBool- 2 bytes each, LongBool- 4 bytes. Boolean values ​​can be one of the pre-declared constants False or True.

Since the Boolean type is an ordinal type, it can be used in a loop statement of a countable type. In Delphi 32 for Boolean meaning

Ord (True) = +1, while for other types ( Bool, WordBool etc.)

Ord(True) = -1, so these kinds of operators should be used with caution! For example, for Delphi 6 version, the executable showMessage(" --- ") statement in the following loop for will never be executed:

for L:= False to True do

ShowMessage("--);

If we replace the loop parameter type L in the previous example with Boolean, the loop will run and the message will appear on the screen twice. [For Delphi versions 1 and 2 ord (True) =+1 for any boolean type.]

Character type . The value of a character type is the set of all PC characters. Each character is assigned an integer in the range 0...255. This number serves as the code for the internal representation of the symbol; it is returned by the ord function.

For encoding in Windows, the ANSI code is used (named after the American National Standard Institute, the American standardization institute that proposed this code). The first half of PC characters with codes 0... 127 corresponds to Table 1.3. The second half of characters with codes 128...255 varies for different fonts. Standard Windows fonts Arial Cyr, Courier New Cyr and Times New Roman use the last 64 codes (from 192 to 256) to represent Cyrillic characters (without the letters “ё” and “Ё”): “A”... “Z” are encoded values ​​192..223, “a”... “i” - 224...255. The symbols “Ё” and “е” have codes 168 and 184, respectively.

Table 1.3 - Character encoding in accordance with the ANSI standard

Code Symbol Code. Symbol Code. Symbol Code Symbol
0 NUL 32 B.L. 64 @ 96 "
1 ZON 33 ! 65 A 97 A
2 STX 34 66 IN 98 b
3 ETX 35 # 67 WITH 99 With
4 EOT 36 $ 68 D 100 d
5 ENQ 37 % 69 E 101 e
6 ACK 38 & 70 F 102 f
7 BEL 39 " 71 G 103 d
8" B.S. 40 ( 72 N 104 h
9 HT 41 ) 73 I 105 i
10 LF 42 * 74 J 106 j
11 VT 43 + 75 TO 107 k
12 FF 44 F 76 L 108 1
13 CR 45 - 77 M 109 m
14 SO 46 78 N 110 n
15 S.I. 47 / 79 0 111 O
16 DEL 48 0 80 R 112 P
17 DC1 49 1 81 Q 113 q
18 DC2 50 2 82 R 114 r
19 DC3 51 3 83 S 115 s
20 DC 4 52 4 84 T 116 t
21 N.A.K. 53 5 85 U 117 u
22 SYN 54 6 86 V 118 v
23 ETB 55 7 87 W 119 W
24 CAN 56 8 88 X 120 x
25 E.M. 57 9 89 Y 121 U
26 SUB 58 : 90 Z .122 z
27 ESC 59 ; 91 t 123 {
28 FS 60 < 92 \ 124 1
29 G.S. 61 = 93 ] 125 }
30 R.S. 62 > 94 L 126 ~
31 US 63 F 95 127 r

Characters with codes 0...31 refer to service codes. If these codes are used in the program's character text, they are considered whitespace.

Ordinal types include (see Figure 4.1) integer, logical, character, enumerated and range types. The ORD(X) function is applicable to any of them, which returns the ordinal number of the value of the expression X. For integer types, the ORD(X) function returns the value of X itself, i.e. ORD(X) = X for X belonging to any shell type. Applying ORD(X) to boolean, character, and enumeration types produces a positive integer in the range 0 to 1 (boolean), 0 to 155 (character), 0 to 65535 (enumeration). A range type retains all the properties of the underlying ordinal type, so the result of applying the ORD(X) function to it depends on the properties of that type.

You can also apply functions to ordinal types:

PRED (X) - returns the previous value of the ordinal type (the value that corresponds to the ordinal number ORD(X) - 1), i.e.

ORD(PRED(X)) = ORD(X) - 1;

SUCC (X) - returns the next ordinal value that matches the ordinal number ORD(X) +1, i.e.

ORD(SUCC(X)) = ORD(X) + 1.

For example, if a program defines a variable

then the PRED(C) function will return the value "4", and the SUCC(C) function will return the value "6".

If we imagine any ordinal type as an ordered set of values, increasing from left to right and occupying a certain segment on the number axis, then the function PRED(X) is not defined for the left, and SUCC(X) for the right end of this segment.

Whole types. The range of possible values ​​of integer types depends on their internal representation, which can be one, two, or four bytes. In table 4.1 shows the name of integer types, the length of their internal representation in bytes and the range of possible values.

Table 4.1

When using procedures and functions with integer parameters, you should be guided by the “nesting” of types, i.e. wherever WORD can be used, BYTE can be used (but not vice versa), LONGINT “includes” INTEGER, which, in turn, includes SHORTINT.

The list of procedures and functions applicable to integer types is given in Table 4.2. Letters b, s, w, i, l expressions of type BYTE, SHORTINT, WORD, INTEGER and LONGINT are designated, respectively, x is an expression of any of these types; letters vb, vs, vw, vi, vl, vx denote variables of the corresponding types. An optional parameter is indicated in square brackets.

Table 4.2

Standard procedures and functions applicable to entire types
Appeal Result type Action
abs(x) x Returns module x
chr(b) Char Returns a character by its code
dec(vx[, i]) - Decreases the value of vx by i, and in the absence of i - by 1
inc(vx[, i]) - Increases the value of vx by i, and in the absence of i - by 1
Hi(i) Byte Returns the high byte of the argument
Hi(w) Same Same
Lo(i) " Returns the low byte of the argument
Lo(w) " Same
odd(l) Boolean Returns True if the argument is an odd number
Random (w) Same as parameter Returns a pseudorandom number uniformly distributed in the range 0...(w-l)
sgr(x) X Returns the square of the argument
swap(i) Integer Swaps bytes in a word
swap(w) Word

When operating with integers, the type of the result will correspond to the type of the operands, and if the operands are of different integer types, the type of the operand that has the maximum power (maximum range of values). Possible overflow of the result is not controlled in any way, which can lead to misunderstandings, for example:

a:= 32767; (Maximum possible INTEGER value)

x:= a + 2; (Overflow while evaluating this expression !}

y:= LongInt(a)+2; (No overflow after casting the variable to a more powerful type)

WriteLn(x:10:0, y:10:0)

As a result of running the program we get

Boolean type. Boolean values ​​can be one of the pre-declared constants FALSE or TRUE. The rules apply to them:

False< True;

succ(False)= True;

pred(True) = False.

Since the Boolean type is an ordinal type, it can be used in a countable type operator, for example:

for 1:= False to True do ....

Character type. The value of a character type is the set of all PC characters. Each character is assigned an integer in the range 0...255. This number serves as the code for the internal representation of the symbol; it is returned by the ORD function.

ASCII code is used for encoding ( American Standard Code for Information Interchange- American Standard Code for Information Interchange). This is a 7-bit code, i.e. it can only encode 128 characters in the range from 0 to 127. At the same time, in the 8-bit byte allocated for storing a character in Turbo Pascal, you can encode twice as many characters in the range from 0 to 255. The first half of the characters PC with codes 0...127 corresponds to the ASCII standard (Table 4.3). The second half of characters with codes 128...255 is not limited by the rigid framework of the standard and can be changed on a PC different types(Appendix 2 shows some common encoding options for these characters).

Table 4.3

Character encoding according to the ASCII standard
Code Symbol Code Symbol Code Symbol Code Symbol
NUL B.L. ® "
ZON ! A a
STX " IN b
ETX # WITH With
EOT $ D d
ENQ % E e
ASK & F f
BEL " G g
B.S. ( H h
NT ) I i
LF * J j
VT + k k
FF , L i
CR - M m
SO . N n
S.I. / ABOUT
DEL p P
DC1 Q q
DC2 R r
DC3 S s
DC4 T t
N.A.K. U u
SYN V V
ETB w w
CAN X X
E.M. U U
SUB : z z
ESC / [ {
FS < \ l
G.S. = ] }
R.S. > ^ ~
US ? - n

Characters with codes 0...31 refer to service codes. If these codes are used in the program's character text, they are considered whitespace. When used in I/O operations, they can have the following independent meaning:

Symbol Code Meaning
BEL Call; The display of this symbol is accompanied by sound signal
NT Horizontal tabulation; when displayed on the screen, moves the cursor to a position that is a multiple of 8 plus 1 (9, 17, 25, etc.)
LF Line translation; when displaying it on the screen, all subsequent characters will be output starting from the same position, but on the next line
VT Vertical tab; when displayed on the screen, it is replaced with a special character
FF Page run; when output to a printer, it forms a page; when output to the screen, it is replaced with a special character
CR Carriage return; entered by pressing the Enter key (when entered using READ or READLN, it means the “Enter” command and is not placed in the input buffer; when output, it means the “Continue output from the beginning of the current line” command)
SUB End of file; entered from the keyboard by pressing Ctrl-Z; when output it is replaced with a special sign
SSC End of work; entered from the keyboard by pressing the ESC key; when output it is replaced with a special sign

Relational operations, as well as built-in functions, are applicable to the CHAR type: СНR(В) - function of the CHAR type; converts an expression B of type BYTE into a character and returns it with its value;

UPCASE(CH) - CHAR type function; returns the uppercase letter if CH is a lowercase Latin letter, otherwise returns the CH character itself, for example:

cl:= UpCase("s") ;

c2:= UpCase ("Ф") ;

WriteLn(cl," ",c2)

Since the UPCASE function does not process Cyrillic, the result of running this

programs will be displayed on the screen

Enum type. An enumerated type is specified by an enumeration of the values ​​it can receive. Each value is named by some identifier and is located in a list surrounded by parentheses, for example:

colors =(red, white, blue);

The use of enumerated types makes programs more visual. If, for example, the program uses data associated with the months of the year, then the following fragment of the program:

TypeMonth=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);

month: TypeMonth;

if month = Aug then WriteLn("It would be nice to go to the sea!");

It would be, you see, very clear. Alas! In Turbo Pascal you cannot use Cyrillic in identifiers, so we are forced to write like this:

TypeMonth=(jan,feb,mar,may,jun,jul,aug,sep,oct,nov,dec);

month: TypeMonth;

if month = aug then WriteLn("It would be nice to go to the sea!");

The correspondence between the values ​​of an enumerated type and the ordinal numbers of these values ​​is established by the enumeration order: the first value in the list receives the ordinal number 0, the second - 1, etc. Maximum power the enumerated type has 65536 values, so in fact the enumerated type defines some subset of the whole WORD type and can be considered as a compact declaration of a group of integer constants with values ​​0, 1, etc.

Using enumerated types increases the reliability of programs by allowing you to control the values ​​that corresponding variables receive. For example, let the following enumerated types be given:

colors = (black, red, white);

ordenal= (one, two, three);

days = (monday, tuesday, Wednesday);

In terms of power and internal representation, all three types are equivalent:

ord(black)=0, ..., ord(white)=2,

ord(one)=0, ...ord(three)=2,

ord(monday)=0, ...ord(Wednesday)=2.

However, if the variables are defined

col:colors; num:ordenal;

then the operators are allowed

num:= succ(two);

day:= pred(tuesday);

but unacceptable

As already mentioned, there is a one-to-one correspondence between the values ​​of an enumerated type and the set of integers, specified by the ORD(X) function. In Turbo Pascal it is also possible inverse conversion: Any expression of type WORD can be converted to a value of an enumeration type, as long as the value of the integer expression does not exceed the power1™ of the enumeration type. This conversion is achieved by using an automatically declared function with the name of the enumerated type (see section 4.4). For example, for the type declaration discussed above, the following assignments are equivalent:

col:= colors(0);

Of course, assignment

will be unacceptable.

Variables of any enumerated type can be declared without first declaring that type, for example:

col: (black, white, green);

Type-range. A range type is a subset of its own basic type, which can be any ordinal type, except a range type. A range type is defined by the boundaries of its values ​​within the base type:

<мин.знач.>..<макс.знач.>

Here<мин.знач. >- minimum value of the type-range;

<макс.знач.>- its maximum value.

For example:

digit = "0".."9";

The range type does not have to be described in the TYPE section, but can be specified directly when declaring a variable, for example:

Ichr: "A".."Z";.

When determining a range type, you must follow the following rules:

  • two ".." characters are treated as one character, so spaces between them are not allowed;
  • the left border of the range should not exceed its right border. A range type inherits all the properties of its base type, but with the limitations of its lower power. In particular, if a variable is defined

days = (mo,tu,we,th,fr,sa,su);

WeekEnd = sa .. su;

then ORD(W) will return the value 5 while PRED(W) will result in an error.

The Turbo Pascal standard library includes two functions that support working with range types:

HIGH(X) - returns the maximum value of the range type to which the variable X belongs;

LOW(X) - returns the minimum value of the range type.

The following short program will print the line

WriteLn(Low(k),"..",High(k))

The set of integers is infinite, but we can always choose the number of bits to represent any integer that arises when solving a specific problem. The set of real numbers is not only infinite, but also continuous, so no matter how many bits we take, we will inevitably encounter numbers that do not have an exact representation. Floating point numbers are one of the possible ways representation of real numbers, which is a trade-off between accuracy and range of accepted values.

A floating point number consists of a set of individual digits, conventionally divided into sign, exponent, and mantissa. The exponent and mantissa are integers that, together with the sign, give the following representation of a floating point number:

Mathematically it is written like this:

(-1) s × M × B E, where s is the sign, B is the radix, E is the exponent, and M is the mantissa.

The base determines the digit number system. It has been mathematically proven that floating point numbers with base B=2 (binary representation) are most resistant to rounding errors, therefore in practice only bases 2 and, less commonly, 10 are encountered. For further presentation, we will always assume B=2, and the formula for a number with floating point will look like:

(-1) s × M × 2 E

What is mantissa and order? Mantissa is a fixed-length integer that represents the most significant bits of a real number. Let's say our mantissa consists of three bits (|M|=3). Take, for example, the number “5”, which in the binary system will be equal to 101 2. The most significant bit corresponds to 2 2 =4, the middle bit (which is equal to zero) is 2 1 =2, and the least significant bit is 2 0 =1. Order– this is the power of the base (two) of the highest digit. In our case E=2. It is convenient to write such numbers in the so-called “scientific” standard form, for example "1.01e+2". It is immediately clear that the mantissa consists of three signs, and the order is two.

Let's say we want to get a fractional number using the same 3 bits of the mantissa. We can do this if we take, say, E=1. Then our number will be equal

1.01e+1 = 1×2 1 +0×2 0 +1×2 -1 =2+0.5=2.5

Obviously, in this way the same number can be represented in different ways. Let's consider an example with the length of the mantissa |M|=4. The number “2” can be represented as follows:

2 = 10 (in binary) = 1.000e+1 = 0.100e+2 = 0.010e+3.

Therefore, already in the very first machines, numbers were represented in the so-called normalized form, when the first bit of the mantissa was always assumed to be equal to one.

This saves one bit (since the implicit one does not need to be stored in memory) and ensures that the number is represented uniquely. In our example, “2” has a single representation (“1.000e+1”), and the mantissa is stored in memory as “000”, because the leading unit is implied implicitly. But a new problem arises in the normalized representation of numbers - it is impossible to represent zero in this form.

  • Data analysis using the Parameter Selection and Solution Search commands
  • Analysis and interpretation of experimental psychological research data.
  • Analysis of source data. Technical standards for city roads.
  • ANALYSIS OF OBTAINED DATA. MAKING A DECISION ABOUT THE SUFFICIENCY OR INSUFFICIENCY OF WATER SUPPLY CHARACTERISTICS FOR THE NEEDS OF THE IRRIGATION SYSTEM.
  • Communication line equipment: data transmission equipment, terminal equipment, intermediate equipment.