The main concept of OOP and the element of the program is an object that combines both a set of data and actions on them. The object type in Turbo Rascal resembles a record type, but instead of the reserved word record, the word object is used, and in addition to the fields representing data, it also lists the headers of subroutines called methods. When specifying this type, after the reserved word object, all fields of the object and method headers are listed, after which the word end is written. So, in the example under consideration, the type (Connection) is used:
tConnection = object
PredElem: Pointer;
NextElem:Pointer;
In this type, PredElem and NextElem are pointers to the previous and subsequent elements in the structure (if there is no corresponding element, the pointer has the value nil). Pointers of the Pointer type are used, because elements can be different: they can be both line elements and strings. Next are the headers of two procedures and two functions that allow you to either set or get the values of object pointers.
Naturally, then all the methods used must be described in the same way as is done for subroutines in modules. In this case, it is allowed to write an abbreviated title of the method, but before it you should write the name of the object type to which this subroutine belongs, separated by a dot:
procedure tConnection.PutPredElem;
PredElem:=PredEl;
This is necessary because several different methods belonging to different objects can have the same name, as well as fields in different record types.
Some program objects, especially those at the beginning of the hierarchical tree, may not correspond to any real objects. So, for example, objects of the types tConnection (connection), tStructure (structure) and tOperation (operation) do not have any physical embodiment - they indicate only some dualities of other, real objects, such as strings and string elements. However, isolating these general properties into separate objects can be convenient, since it then allows them not to be repeated many times when describing real objects. Such objects are called abstract, and, as a rule, there are no variables of such types in a program.
12.2.1. Encapsulation
The term “encapsulation” refers to the combination of both parameters and actions on them in one object. In this case, the subroutines (methods) included in the object, as a rule, operate with data this object or access the methods of ancestor objects (see section 14.2.2). This allows you to combine all the properties of an object in one place, which makes it easier to understand the operation of the program, its debugging, and modification. So, for example, all properties of connections between elements in the structure of text are concentrated in the tConnection type. Typically, object data is not directly accessed from outside, although this is possible. Appropriate methods are usually used to access data. So, in the example under consideration, four methods are used for this purpose: PutPredElem, PutNextElem, GetPredElem and GetNextElem, with the help of which you can set and get the values of pointers to the previous and subsequent element. This circumstance is not far-fetched. This is what usually happens in our everyday life - we use certain parameters indirectly. If we take the already mentioned example of a computer, then it has such a parameter as the size of free memory on the hard drive. However, it is unlikely that the computer owner will directly count bytes to determine this parameter - special subroutines are used for this purpose.
Such indirect access to data allows us to avoid, in many cases, unexpected unwanted changes in parameters. In Turbo Rascal, for this purpose, a special reserved word private is used, which in principle prohibits direct access to certain data and methods of an object outside the module in which the object is described. In version 7.0 (a private section can be placed anywhere in the object (previously - only at the end (after the usual, available parameters and methods). So, if it is necessary to prohibit access to the data of an object of type tСonnection from the main program (remember that the main editor program is located in a separate file), this type can be described as follows:
tConnection = object
procedure РutPredElem(PredEl: Pointer);
procedure РutNextElem(NextEl: Рinter);
function GetPredElem: Рinter; I
function GetNextElem: Pointer;
private
PredElem: Pointer;
NextElem:Pointer;
If the private section is not at the end of the object, then to limit the range of the reserved word Rrivate you should place a reserved word after the private section public(accessible from outside) - only in version 7.0:
tConnection = object
PredElem: Pointer;
NextElem:Pointer;
procedure РutPredElem(PredEl: Pointer);
procedure РutNextElem(NextEl: Рinter);
function GetPredElem: Рinter; I
function GetNextElem: Pointer;
The main objects of Windows are files, folders and shortcuts.
File– a named collection of data on external media. In Windows OS they are also called documents. The file name consists of the actual name and extension. The name can be up to 255 characters long and can include numbers, space, and some special characters (! @ # $ % ^ & () ( ) _ -). The extension specifies the type of information contained in the file.
For example: doc txt frm wri - text
Bmp pcx tif pif wpg jpg - graphics pst pab – Email dbf db – databases xls – spreadsheet lib obj dll – libraries hlp – help files arj zip rar – archive files
In addition, in Windows, each file is associated with an icon corresponding to the file type, determined by the extension.
For example:
You can open the file double click according to his pictogram. Files are registered in folders (directories). Folder is a way of organizing and presenting system resources. A folder can contain other folders (subfolders), files, as well as objects such as a printer, disks, etc.
Folders are:
Window– a rectangular area of the screen designed to display objects, controls and information on the screen. In Windows OS there are four types of windows:
Dialog boxes are used when you need to configure or change something. Unlike folder windows, dialog boxes are not standardized, although they are standardized through the use of generic controls.
Majority dialog boxes contain more information than can fit on one window screen page. In this case, the dialog box creates tabs. Switching between tabs is done by clicking on its name.
Dialog boxes usually contain command buttons, which are used to execute commands.
For example:
- OK– closes the window and saves all settings made in it.
- Cancel- closing the window without saving the changes made.
- Review…- opens a dialog box with which you can conveniently search and select an object.
- Seal– Printing the current settings on the printer.
- Next>,<Назад - transition to the next stage of the wizard program or return to the previous stage.
Dialog boxes can also contain many other different controls,
For example:
- Text field– area for entering text information from the keyboard;
- Listbox, Combo Box, Dropdown List– allow you to select one parameter from a given set;
- Switches– allow you to select only one setting option out of several;
- Checkboxes– similar to switches, but unlike them, several checkboxes can be selected simultaneously;
- Counter– to enter numerical parameters;
- Positioning engine- clearly changes the adjustable parameters.
Examples of dialog boxes:
Topic 1. 2. Data type concept
The concept of a variable
Any program that processes data uses variables as operands in expressions. A variable is often defined as a “name” - “value” pair. The name corresponds to the address of the memory section allocated to the variable, and the value is the contents of this section.
Variable is a named area of computer memory allocated to store specific data, the value of which, in general, can change during program execution.
The description of variables in the program has the following format:
Let's look at each element of this description.
Name– identifier;
Every variable, constant, function, every expression in a program written in a high-level language has a specific type. Different types of data are stored and processed differently.
Data type defines:
Internal representation of data in computer memory;
Operations and functions that can be applied to objects of this type;
The set of values that values of this type can take.
All types of the C++ language are divided into basic And derivatives (compounds).
Basic Data Types
In programming languages, the main data types include data types for storing numbers (integer type, real type) and characters.
The C++ language defines seven basic data types: six for representing integer, real, character and logical values, and one special type void. The following keywords are defined to describe the six main ones:
int-whole,
char, wchar_t– symbolic,
float, double– real,
bool– logical.
In addition, there are four specifiers that specify the internal representation and range of values of standard types:
short - short ,
long - long ,
signed - signed (the most significant bit is interpreted as signed, 0 is positive, 1 is negative) ,
unsigned - unsigned .
Integer, character, and real types are also called arithmetic types.
Examples of variable descriptions:
int a,b;//two variables of integer type
float summa; // variable of real type
Let's look at the main types in more detail.
Under variable integer type (int) 2 or 4 bytes are allocated (for a 16-bit and 32-bit processor, respectively). short int – 2 bytes, long int – 4 bytes. Constants are assigned a type according to their type. By default, integer constants are interpreted as short and signed. To change this interpretation, you can use the suffixes – L,l,U,u. For example, 8L, 71u.
Character type(char) – 1 byte. (For wchar_t– implementation dependent, usually 2 bytes).
Let's look at the internal representation of a range of values using the char type as an example.
The smallest unsigned number, one byte long, is 00000000 2 =0
The largest unsigned number one byte long is 11111111 2 =255.
Therefore, the unsigned char type allows you to store 256 different characters with codes from 0 to 255.
The smallest positive number, one byte long, is 00000000 2 =0
The largest positive number one byte long is 01111111 2 =127
Largest negative number one byte long 11111111 2 =-1
The smallest negative number, one byte long, is 10000000 2 = -128
Recall that to obtain the absolute value of a negative number, it is inverted, that is, 0 is replaced by 1, 1 by 0, and one is added. For example, a negative number is 10000000. Invert - 01111111. Add 1
Therefore, the signed char type allows you to store 256 different characters with codes from -128 to 127.
Boolean type (bool)- 1 byte. The value of quantities of this type is either true ( true or 1), or false ( false or 0). Any zero value is interpreted as false, any non-zero value is interpreted as true.
Real type(float, double, long double). The internal representation of real quantities consists of two things - the mantissa and the order. For example, 148.35 can be represented as 1.4835*10 2, where 1.4835 is the mantissa, 2 is the order. Mantissa >1 and< 2. Длинна мантиссы определяет точность числа, а длина порядка его диапазон. Для float отводится 4 байта = 1 знак + 8 порядок + 23 мантисса). Так как старшая цифра мантиссы =1, то она не хранится. Для double отводится 8 байт = 1 знак+11 порядок+52 мантисса. Константы вещественного типа по умолчанию имеют тип double. Для его изменения можно использовать суффиксы F,f,L,l.
type void is a special type, the set of values of this type is empty. It is not used when describing variables.
In addition, I use the specifier typedef You can enter convenient descriptions for complex types. For example,
typedef unsigned char UC;
UC symbol; // symbol this type variable UC, that is, unsigned character
Let's continue to consider the syntax for describing variables:
[memory class]type name1 [initial_expression1], name2 [initial_expression2],...;
In order to understand what it is memory class Let us introduce several definitions.
Each program object, in particular a variable, is characterized by such parameters as
Scope;
Area of visibility;
Lifetime (duration of existence).
Scope is a part of a program in which an identifier can be used to access a variable. If a variable is declared inside a block, then it is called local and its scope from the point of description to the end of the block. If a variable is declared outside the block, then the variable is called global and its scope is from the point of description to the end of the file.
Area of visibility- this is the part of the program from which it is possible ordinary variable access. Most often, the scope of visibility coincides with the scope of action, but there are exceptions - if variables with the same names are used in nested blocks (the external variable is invisible in this case).
#include