How to set up smartphones and PCs. Informational portal
  • home
  • Windows 8
  • Real type in pascal. An example of a description of an enumerated type

Real type in pascal. An example of a description of an enumerated type

In any program, you need to determine the type and type of quantities that will be used to solve the problem. By their appearance, simple quantities (in programming, they are all called data) are divided into constants and variables.

Constants Is data whose values ​​cannot be changed during program execution. Introduced in a const block.

In general, the description of a simple untyped constant is done as follows:

Const constant_name = expression;

Typed constants are described as:

Const constant_name: type = expression;

The following can be used in expressions:

· Numbers or a set of characters in apostrophes;

· Mathematical operations;

· Relation operations and logical operations;

Functions abs (x), round (x), trunc (x);

· Functions chr (x), ord (x), pred (x), succ (x) and others.

Constants description format:

id = value;

1. Integer - defined by means of numbers written in decimal or hexadecimal format that do not contain a decimal point.

2. Real - defined by means of numbers written in decimal data format.

3. Symbolic - this is any character of a personal computer, enclosed in apostrophes.

4. String - defined by a sequence of arbitrary characters enclosed in apostrophes.

5. Logical is either False or True.

The type of the constant is not specified, but it is determined automatically during compilation: the values ​​of the expressions are calculated immediately, and then only substituted instead of names.

Variables Is data that can change during program execution. Each variable has its own named memory location / locations. Those. a variable is a kind of container in which you can put some data and store it there. Variables have a name, type, and value.

Variable name - must begin necessarily with a letter, cannot contain spaces, and can only contain:

· Letters of the Latin alphabet;

· Underscore.

Examples: A, A_1, AA, i, j, x, y, etc. Invalid names: My 1, 1A. Variable names can be up to 126 characters long, so try to choose meaningful variable names. However, the compiler distinguishes the first 63 characters in the names. But it does not distinguish between lowercase and uppercase letters, both in variable names and in the writing of service identifiers.

Variable type - must be defined in the variable declaration block VAR. The value of a variable is a constant of the same type.

Every program works with data. Data is, in the broadest sense of the word, objects that a program processes. The type of a given is its characteristic. Depends on the type:

How this data will be stored,

How many memory cells will be allocated for its storage,

What is the minimum and maximum value it can take,

· What operations can be performed with it.

Some simple Pascal data types:

1. Integer types (ShortInt, Integer, LongInt, Byte, Word).

2. Real types (Real, Single, Double, Extended, Comp).

3. Boolean.

4. Character (Char).

5. String types (String, String [n]).

9. Unconditional operators in Pascal. Description and use.

Operator type

goto<метка>;

Purpose - transfer of control in the program to the operator marked with a label<метка>... A label can be a name (written according to the rules for language names) or an unsigned integer, described in the label description statementLabel, and standing before the marked statement, but only in one place in the program. The label is separated from the operator by the symbol “:.” A jump to a label can occur several times in a block, but the label itself can only occur once. If there is no control transfer to some label, there will be no error.

The unconditional jump operator is generally not allowed in structured programming. Although it allows you to shorten the text of the program, its use in Pascal is limited by a number of rules and guidelines. It is forbidden to go inside a compound statement, inside or to the beginning of a subroutine and exit from the subroutine to the program that called it. It is not recommended to move beyond the bounds of the page (screen) of the program text, except for the transition to the final statements of the program. All this is due to the possibility of skipping important statements for the correct functioning of the program. Usually, the unconditional jump operator is used only to return to the beginning of the loop body if the loop is constructed using conditional and unconditional statements.

Note that the statement following the goto must also be marked with a different label (unless the goto is the last one in the statement group). Otherwise, there is no way to get to the next operator after goto.

10. Branching operators in Pascal. Description and use.

The operators that allow you to select only one of several possible options for executing a program (branches) include

Those. these statements allow you to change the natural order of execution of program statements.

if<условие>then< оператор 1 >

else<оператор 2> ;

if a> = b then Max: = a else Max: = b;

In the if statement, only one statement can be executed on both branches (then and else)!

An example of a task for branching operators in pascal. Enter two integers and display the largest of them.

Solution idea: you need to display the first number if it is greater than the second, or the second if it is greater than the first.

Feature: the actions of the performer depend on some conditions (if ... otherwise ...).

var a, b, max: integer;

writeln ("Enter two integers");

if a> b then max: = a else max: = b;

writeln ("Highest number", max);

Difficult conditions

A complex condition is a condition consisting of several simple conditions (relations) connected by logical

operations:

Not - NOT (negation, inversion)

And - AND (logical multiplication, conjunction,

simultaneous fulfillment of conditions)

Or - OR (logical addition, disjunction,

fulfillment of at least one of the conditions)

Xor - exclusive OR (execution only

one of two conditions, but not both)

Simple conditions (relations)

< <= > >= = <>

Order of execution (priority = seniority)

Expressions in brackets

<, <=, >, >=, =, <>

Feature - each of the simple conditions must be enclosed in parentheses.

Case selection statement

The case statement allows you to choose between several options.

The variant operator consists

Øfrom an expression called a selector,

Ø and a list of operators, each marked with a constant of the same type as the selector.

The selector should only be an ordinal data type, not a longint type.

The selector can be a variable or an expression.

The list of constants can be specified either as an explicit enumeration or as an interval or their union. Repetition of constants is not

allowed.

The switch type and the types of all constants must be compatible.

Case< выражение {селектор}>of

<список констант 1> : < оператор 1>;

< список констант K> : < оператор K>;

The case statement is executed as follows:

1) the value of the selector is calculated;

2) the obtained result is checked for belonging to one or another list of constants;

3) if such a list is found, then further checks are no longer performed, but the operator corresponding to

the selected branch, after which control is transferred to the operator following the end keyword, which closes the entire

case construct;

4) if there is no suitable list of constants, then the operator behind the else keyword is executed; if there is no else-branch,

then nothing is done.

In the case branching statement, only one statement can be executed across all branches!

If you need to execute several, you need to use the begin-end operator brackets.

case Index mod 4 of

1: x: = y * y - 2 * y;

11.Operator of option (selection) in Pascal. Description and use.

The choice operator (option, switch) implements the choice of one of the possible alternatives, i.e. options for continuing the program.

Recording format:

Case - choice, option;

S - selector, ordinal type expression;

Ki - selection constants, a constant whose type is the same as the type of the selector;

OPi - any operator including empty;

The select operator implements the following construction:

Pascal selection statement: Evaluates the selector expression. The computed value is sequentially compared with the constants of the alternatives and control is passed to the operator selection constant, which coincides with the computed value of the selector. The statement is executed and control is transferred outside the selection statement. If the computed value of the selector does not match any of the constants, then control is passed to the Else branch, the presence of which is not necessary in this case, the control is transferred outside the selection operator.

Block diagram of the selection operator.

The structure of the select statement can be implemented using nested conditional statements, but this degrades the clarity of the program. Recommended no more than 2-3 levels of attachments.

12. Types of loop operators in Pascal, their purpose.

5. Algorithmic constructions of cycles. Types of cycles.

There are three types of looping algorithms: a parameter loop (called an arithmetic loop), a precondition loop, and a postcondition loop (called iterative loop).

12.13 Arithmetic loop. In an arithmetic cycle, the number of its steps (repetitions) is uniquely determined by the rule for changing the parameter, which is set using the initial (N) and final (K) values ​​of the parameter and the step (h) of changing it. That is, at the first step of the cycle, the parameter value is equal to N, at the second - N + h, at the third - N + 2h, etc. At the last step of the cycle, the value of the parameter is not greater than K, but such that its further change will lead to a value greater than K.

Counter loops are used when the cyclic part of the program must be repeated a fixed number of times. Such loops have an integer variable called the loop counter.

If it is necessary for a program fragment to be repeated a given number of times, then the following construction is used:

FOR<имя счетчика цикла> = <начальное значение>THEN<конечное значение>DO<оператор>;

FOR, TO, DO - reserved words (English: for, to, execute);

<счетчик (параметр) цикла>- a variable of the INTEGER type, which changes on the interval from<начального значения>, increasing by one at the end of each step of the cycle;

<оператор>- any (more often compound) operator.

There is another form of this operator:

FOR<имя счетчика цикла>:= <начальное значение>DOWNTO<конечное значение>DO<оператор> :

Replacing TO by DOWNTO (English: down to) means that the step of changing the cycle parameter is - 1, that is, a step-by-step decrease of the counter by one occurs.

12.14 Loop with precondition. The number of steps in the cycle is not predetermined and depends on the input data of the problem. In this loop structure, the value of the conditional expression (condition) is first checked before executing the next step of the loop. If the value of the conditional expression is true, the body of the loop is executed. After that, control is again transferred to checking the condition, etc. These actions are repeated until the conditional expression evaluates to FALSE. At the first non-observance of the condition, the cycle ends.

This most commonly used repetition operator is:

WHILE<условие>DO<оператор>;

WHILE, DO - reserved words (English: bye, to do);

<условие>- expression of a logical type;

<оператор>- an arbitrary (possibly compound) operator.

A feature of a loop with a precondition is that if the initial conditional expression is false, then the body of the loop will not be executed even once.

Loops with a precondition are used when the execution of the loop is associated with some logical condition. A loop statement with a precondition has two parts: a loop execution condition and a loop body.

12.15 Loop with postcondition (iterative loop). As in a loop with a precondition, in a loop with a postcondition the number of repetitions of the loop body is not predetermined; it depends on the input data of the task. Unlike a loop with a precondition, the body of a loop with a postcondition will always be executed at least once, after which the condition is checked. In this construction, the body of the loop will be executed as long as the value of the conditional expression is false. As soon as it becomes true, the command is terminated.

This operator has the form:

REPEAT<тело цикла>UNTIL<условие>:

REPEAT, UNTIL - reserved words (English: repeat until);

<условие>- an expression of a logical type, if its value is true, then the loop is exited.

It should be noted that in this construction the sequence of statements defining the body of the loop is not enclosed in the operator brackets BEGIN ... END, since they are the REPEAT ... UNTIL pair.

Postconditioning loops are similar to preconditioned loops, but they place the condition after the body of the loop.

Unlike a loop with a precondition, which can finish its work without ever executing the body of the loop (if the execution condition is false during the first pass of the loop), the body of the loop with a postcondition must be executed at least once, after which the condition is checked.

One of the operators of the loop body must affect the value of the loop execution condition, otherwise the loop will repeat an infinite number of times.

If the condition is true, then the loop is exited, otherwise the loop statements are repeated.

16. Array is a set of elements of the same type, united by a common name and occupying a certain area of ​​memory in the computer. The number of elements in an array is always finite. In general, an array is a structured data type that consists of a fixed number of elements of the same type. Arrays are named regular type (or rows) because they combine elements of the same type (logically homogeneous), ordered (regulated) by indices that determine the position of each element in the array. Any data type can be used as array elements, therefore it is quite legitimate for arrays of records, arrays of pointers, arrays of strings, arrays, etc. Array elements can be data of any type, including structured data. The type of array elements is called basic. The peculiarity of the Pascal language is that the number of array elements is fixed during the description and does not change during the program execution. The elements that make up the array are ordered in such a way that each element corresponds to a set of numbers (indices) that determine its location in the general sequence. Each individual element is accessed by indexing the elements of the array. Indices are expressions of any scalar type (most often an integer), except for real ones. The index type defines the extent to which the index values ​​change. The phrase array of is used to describe an array.

An array is called a collection of data that perform similar functions, and denoted by one name. If only one serial number is assigned to each element of the array, then such an array is called linear, or one-dimensional.

17... One-dimensional array Is a fixed number of elements of the same type, united by one name, and each element has its own unique number, and the numbers of the elements go in a row.

To describe such objects in programming, you must first enter the appropriate type in the type description section.

The array type is described as follows:

Type name = Array [type of index (s)] Of element type;

Variable name: type name;

An array variable can be described directly in the Var variable description section:

Var Variable name: array [type of index (s)] Of type of elements;

Array - a service word (translated from English means "array");

Of - a service word (translated from English means "from").

Index type - any ordinal type, except for integer, longint types.

The type of the elements themselves can be any other than the file type.

The number of elements in an array is called its dimension. It is easy to calculate that with the last method of describing the set of indices, the dimension of the array is equal to: the maximum value of the index - the minimum value of the index + 1.

For instance:

mas = array of real;

Array X is one-dimensional, consisting of twenty real-type elements. Array elements are stored in the computer memory sequentially one after another.

When using variables to designate an index, their values ​​must be determined at the time of use, and in the case of arithmetic expressions, their result should not go beyond the boundaries of the minimum and maximum values ​​of the array indices.

Array element indices can start with any integer, including negative ones, for example:

Type bb = Array [-5..3] Of Boolean;

Arrays of this type will contain 9 boolean variables, numbered from -5 to 3.

18. Two-dimensional array in Pascal it is treated as a one-dimensional array, the element type of which is also an array (an array of arrays). The position of elements in two-dimensional Pascal arrays is described by two indices. They can be represented as a rectangular table or matrix.

Consider a two-dimensional Pascal array with dimensions 3 * 3, that is, it will have three lines, and each line has three elements:

Each element has its own number, like in one-dimensional arrays, but now the number already consists of two numbers - the number of the line in which the element is located, and the number of the column. Thus, the item number is determined by the intersection of the row and column. For example, a 21 is the item in the second row and first column.

Description of a two-dimensional Pascal array.

There are several ways to declare a two-dimensional Pascal array.

We already know how to describe one-dimensional arrays, the elements of which can be of any type, and, therefore, the elements themselves can be arrays. Consider the following description of types and variables:

Basic operations with two-dimensional Pascal arrays

Everything that has been said about the basic operations with one-dimensional arrays is also true for matrices. The only action that can be performed on matrices of the same type as a whole is assignment. That is, if our program describes two matrices of the same type, for example,

matrix = array of integer;

then during the execution of the program, you can assign the matrix a the value of the matrix b (a: = b). All other actions are performed element by element, while on the elements you can perform all the allowed operations that are defined for the data type of the array elements. This means that if an array consists of integers, then operations defined for integers can be performed on its elements, but if the array consists of characters, then operations defined for working with characters are applicable to them.

21. Technologies for working with text documents. Text editors and processors: purpose and capabilities.

More advanced text editors (for example, Microsoft Word and OpenOffice.org Writer), sometimes called word processors, have a wide range of document creation capabilities (insert lists and tables, spell checkers, save corrections, etc.).

To prepare for the publication of books, magazines and newspapers in the process of prototyping the publication, powerful word processing programs are used - desktop publishing systems (for example, Adobe PageMaker, Microsoft Office Publisher).

Specialized applications (such as Microsoft FrontPage) are used to prepare Web pages and Web sites for publication on the Internet.

Text editors are programs for creating, editing, formatting, saving and printing documents. A modern document may contain, in addition to text, other objects (tables, diagrams, pictures, etc.).

Editing is a transformation that adds, deletes, moves or corrects the content of a document. Editing of a document is usually done by adding, removing, or moving characters or pieces of text.

Formatting is the decoration of text. In addition to text characters, formatted text contains special invisible codes that tell the program how to display it on the screen and print it on a printer: what font to use, what style and size of characters should be, how paragraphs and headings are formatted.

Formatted and unformatted texts are somewhat different in nature. This distinction must be understood. In formatted text, everything is important: the size of the letters, and their image, and where one line ends and another begins. That is, formatted text is inextricably linked with the parameters of the sheet of paper on which it is printed.

When designing text documents, it is often required to add non-text elements or objects to the document. Advanced text editors allow you to do this - they have ample opportunity to insert pictures, diagrams, formulas, and so on into the text.

Paper and electronic documents. Documents can be paper or electronic. Paper documents are created and formatted for the best presentation when printed on a printer. Electronic documents are created and formatted for the best presentation on the monitor screen. The gradual replacement of paper document flow with electronic is one of the trends in the development of information technology. Reducing paper consumption is beneficial in conserving natural resources and reducing environmental pollution.

The formatting of paper and electronic documents can vary significantly. For paper documents, the so-called absolute formatting is adopted. A printed document is always formatted to fit a printed sheet of a known size (format). For example, the width of a line in a document depends on the width of the paper. If the document was prepared for printing on large-format sheets, then it cannot be printed on small sheets of paper - part of the document will not fit on them. In a word, formatting a printed document always requires a preliminary selection of a sheet of paper with subsequent binding to this sheet. For a printed document, you can always accurately name (in any unit of measurement) the sizes of fonts, margins, spacing between lines or paragraphs, etc.

For electronic documents, the so-called relative formatting is adopted. The author of the document cannot predict in advance on what computer, with what screen size the document will be viewed. Moreover, even if the sizes of the screens were known in advance, it is still impossible to predict what the size of the window in which the reader will see the document will be. Therefore, electronic documents are made to fit the current window size and formatted on the fly.

The author of an electronic document also does not know what fonts are available on the computer of the future reader, and therefore cannot rigidly specify in what font the text and headings should be displayed. But he can specify such formatting that on any computer headers will appear larger than the text.

Relative formatting is used to create electronic documents on the Internet (called Web pages), and absolute formatting is used to create printed documents in word processors.

22. The main structural elements of a text document. Fonts, styles, formats.

Formatting the font (characters).

Symbols are letters, numbers, spaces, punctuation marks, special characters. Symbols can be formatted (change their appearance). Among the main properties of symbols are the following: font, size, style and color.

A font is a complete set of characters in a specific style. Each font has its own name, for example Times New Roman, Arial, Comic Sans MS. The font unit is a point (1 pt = 0.367 mm). The font sizes can be changed within a wide range. In addition to the normal (normal) style of characters, bold, italic, and bold italic are usually used.

Bitmap and vector fonts are distinguished by the way they are presented in a computer. Bitmap methods are used to represent bitmap fonts, font characters are groups of pixels. Bitmap fonts can only be scaled by specific ratios.

In vector fonts, symbols are described by mathematical formulas and their arbitrary scaling is possible. Among vector fonts, TrueType fonts are the most widely used.

You can also set additional parameters for formatting characters: underlining characters with different types of lines, changing the appearance of characters (superscript and subscript, strikethrough), changing the distance between characters.

If you plan to print a document in color, you can set different colors for different groups of characters.

To check spelling and syntax, special software modules are used, which are usually included in word processors and publishing systems. Such systems contain dictionaries and grammar rules for several languages, which allows you to correct errors in multilingual documents.

24... Database is an information model that allows you to orderly store data about a group of objects that have the same set of properties.

There are several different types of databases: tabular (relational), hierarchical, and networked.

Tabular databases.

A tabular database contains a list of objects of the same type, that is, objects with the same set of properties. It is convenient to represent such a database in the form of a two-dimensional table.

In relational databases, all data is presented in the form of simple tables, divided into rows and columns, at the intersection of which the data is located. Queries on such tables return tables, which themselves can become the subject of further queries. Each database can include multiple tables.

The main advantage of tables is their comprehensibility. We deal with tabular information almost every day. Take a look, for example, in your diary: the class schedule is presented there in the form of a table. When we arrive at the station, we look at the train schedule. What form does it have? This is a table! And then there is the table of the football championship. And the teacher's journal, where he gives you grades, is also a table.

Briefly, the features of a relational database can be formulated as follows:

1.Data is stored in tables consisting of columns ("attributes", "fields") and rows ("records");

2. There is exactly one value at the intersection of each column and line;

3. Each column has its own name, which serves as its name, and all values ​​in one column are of the same type.

4. Queries to the database return results in the form of tables, which can also act as a query object.

5. Rows in a relational database are unordered - ordering is performed at the moment of generating a response to a request.

6. As a rule, information in databases is stored not in one table, but in several interconnected ones.

In relational databases, a table row is called recording and the column is field... Each field in the table has a name.

Fields- these are various characteristics (sometimes they say - attributes) of an object. Field values ​​on one line refer to one object.

Primary key in the database, a field (or a set of fields) is called, the value of which is not repeated in different records.

There is one more very important property associated with each field - field type... The field type defines the set of values ​​that a given field can take in various records.

There are four main field types used in relational databases:

Numerical;

Symbolic;

Logical.

25. Database management systems and principles of work with them. Searching, deleting and sorting data in the database. Search conditions (logical expressions); order and sort keys.

Database management systems (DBMS).

To create databases, as well as to perform search and sorting operations, special programs are intended - database management systems (DBMS).

Thus, it is necessary to distinguish between the actual database (DB) - ordered data sets, and database management systems (DBMS) - programs that manage the storage and processing of data. For example, the Access application, which is part of the Microsoft Office suite of programs, is a database management system that allows the user to create and manipulate tabular databases.

A relational database is essentially a two-dimensional table. A record here means a row of a two-dimensional table, the elements of which form the columns of the table. Columns can be numeric, text, or date, depending on the data type. The rows of the table are numbered.

Working with a DBMS begins with creating a database structure, i.e., with the definition:

the number of columns;

column names;

column types (text / number / date);

column widths.

The main functions of the DBMS:

Data management in external memory (on disks);

In-memory data management;

Logging changes and recovering the database after failures;

Database languages ​​support (data definition language, data manipulation language).

In DBMS commands, the selection condition is written in the form of a logical expression.

A boolean expression, like a mathematical expression, is executed (evaluated), but the result is not a number, but a boolean value: true or false.

An expression consisting of one logical value or one relation will be called a simple logical expression.

Often there are tasks in which not separate conditions are used, but a set of related conditions (relations). For example, you need to select students whose weight is over 60 and height is less than 168.

An expression containing logical operations will be called a complex logical expression.

The union of two (or more) statements into one using the union "and" is called the operation of logical multiplication or conjunction.

As a result of logical multiplication (conjunction), true is obtained if all logical expressions are true.

The union of two (or more) statements using the union "or" is called the operation of logical addition or disjunction.

As a result of logical addition (disjunction), true is obtained if at least one logical expression is true.

Attaching a particle "not" to a statement is called an operation of logical negation or inversion.

27. Spreadsheets, purpose and basic functions.

Spreadsheet is a numerical data processing program that stores and processes data in rectangular tables.

A spreadsheet is made up of columns and rows. Column headings are designated by letters or letter combinations (A, G, AB, etc.), row headings by numbers (1, 16, 278, etc.). Cell is the intersection of a column and a row.

Each cell in the table has its own address. A spreadsheet cell address is composed of a column header and a row header, for example: A1, F123, R1. The cell with which some actions are performed is highlighted with a frame and is called active.

Data types. Spreadsheets allow you to work with three basic types of data: number, text, and formula.

Numbers in Excel spreadsheets can be written in the usual numerical or exponential format, for example: 195.2 or 1.952E + 02. By default, numbers are right-aligned in a cell. This is due to the fact that when placing numbers one under another (in a table column), it is convenient to have an alignment by digits (units under units, tens under tens, etc.).

A formula must begin with an equal sign and can include numbers, cell names, functions (Math, Statistical, Financial, Date and Time, etc.), and math operation signs. For example, the formula "= A1 + B2" adds the numbers stored in cells A1 and B2, and the formula "= A1 * B" multiplies the number stored in cell A1 by 5. When you enter a formula, the cell does not display the formula itself, and the result of calculations using this formula. When you change the original values ​​included in the formula, the result is recalculated immediately.

Absolute and relative links. Formulas use references to cell addresses. There are two main types of links: relative and absolute. The differences between them appear when you copy a formula from an active cell to another cell.

A relative reference in a formula is used to indicate a cell address, calculated relative to the cell in which the formula resides. When you move or copy a formula from the active cell, relative references are automatically updated based on the new position of the formula. Relative references are as follows: A1, B3.

If the dollar sign is in front of a letter (for example: $ A1), then the column coordinate is absolute and the row coordinate is relative. If the dollar sign is in front of a number (for example, A $ 1), then, on the contrary, the column coordinate is relative, and the rows are absolute. Such links are called mixed links.

For example, suppose that cell C1 contains the formula = A $ 1 + $ J31, which, when copied to cell D2, becomes = B $ 1 + $ B2. Relative links changed when copied, but absolute ones did not.

Sorting and searching data. Spreadsheets allow you to sort your data. Data in spreadsheets is sorted in ascending or descending order. Sorting arranges data in a specific order. You can carry out nested sorts, that is, sort the data by several columns, while the order of sorting the columns is assigned.

In spreadsheets, you can search for data in accordance with the specified conditions - filters. Filters are defined using search terms (greater than, less than, equal, and so on) and values ​​(100, 10, and so on). For example, more than 100. The search will find those cells that contain data that matches the specified filter.

Construction of diagrams and graphs. Spreadsheets allow you to present numerical data in the form of charts or graphs. There are various types of charts (bar, pie, etc.); the choice of chart type depends on the nature of the data.

28. Technology of information processing in electronic tables (ET). The structure of the spreadsheet.

A spreadsheet is a numerical data processing program that stores and processes data in rectangular tables. A spreadsheet is made up of columns and rows. Column headings are designated by letters or letter combinations (A, G, AB, etc.), row headings by numbers (1, 16, 278, etc.). Cell is the intersection of a column and a row. Each cell in the table has its own address. A spreadsheet cell address is composed of a column heading and a row heading, for example: Al, B5, E7. The cell with which some actions are performed is highlighted with a frame and is called active. The spreadsheets that the user works with in the application are called worksheets. You can enter and modify data on multiple worksheets at the same time, and perform calculations based on data from multiple sheets. Spreadsheet documents can include multiple worksheets and are called workbooks.

29. Types of data in electronic tables (ET): numbers, formulas, text. Rules for writing formulas.

Data types.

Spreadsheets allow you to work with three basic types of data: number, text, and formula.

Numbers in Excel spreadsheets can be written in the usual numerical or exponential format, for example: 195.2 or 1.952О + 02. By default, numbers are right-aligned in a cell. This is due to the fact that when placing numbers one under another (in a table column), it is convenient to have an alignment by digits (units under units, tens under tens, etc.).

Text in Excel spreadsheets is a sequence of characters consisting of letters, numbers, and spaces, for example, “32 MB” is text. By default, text is left-aligned in a cell. This is due to the traditional way of writing (from left to right).

A formula must start with an equal sign and can include numbers, cell names, functions (Math, Statistical, Financial, Date and Time, etc.), and math signs: operations. For example, the formula "= A1 + B2" adds the numbers stored in cells A1 and B2, and the formula "= A1 * 5" multiplies the number stored in cell A1 by 5. When you enter a formula, the cell does not display the formula itself, and the result of calculations using this formula. When you change the original values ​​included in the formula, the result is recalculated immediately.

Rules for writing formulas in spreadsheets

1. Formulas contain numbers, cell names, operation signs, parentheses, function names

2. Arithmetic operations and their signs:

Operation name Symbol Key combination

addition + (Shift + + =) or (+) on the additional keyboard

subtraction - (-)

multiplication * (Shift + 8) or (*) on additional keyboard

division / (Shift + | \) or (/) on additional keyboard

exponentiation ^ (Shift + 6) in English

3. The formula is written in a line, the symbols are sequentially lined up one after another, all the signs of operations are put down; parentheses are used.

4. First of all, operations in brackets are performed, if there are no brackets, then the order of execution is determined by the precedence of the operations. In descending order of seniority, operations are arranged in the following order:

1.exponentiation

2.multiplication, division

3.addition, subtraction

Operations of the same precedence are performed in the order they are written from left to right.

5. Formulas can be entered in the calculation display mode, ie. The user starts writing a formula in the current cell with the = sign and after pressing the Enter key, the result of the formula calculation is displayed in the cell.

6. Formulas can be entered in the formulas display mode, ie. the user writes an unsigned = formula in the current cell and the formula is displayed in the cell after pressing the Enter key.

30. Main built-in functions. Absolute and relative references in electronic tables (ET).

A relative reference in a formula is used to indicate a cell address, calculated relative to the cell in which the formula resides. When you move or copy a formula from the active cell, relative references are automatically updated based on the new position of the formula. Relative references are as follows: A1, OT.

An absolute reference in a formula is used to specify a fixed cell address. Absolute references do not change when you move or copy a formula. In absolute references, a dollar sign (for example, $ A $ 1) is placed in front of the immutable value of the cell address.

If the dollar symbol is in front of a letter (for example: $ A1), then the column coordinate is absolute, and the row coordinate is relative. If the dollar sign is in front of a number (for example, A $ 1), then, on the contrary, the column coordinate is relative, and the rows are absolute. Such links are called mixed links. Suppose, for example, the formula = A $ 1 + $ B1 is written in cell C1, which, when copied into cell D2, becomes = B $ 1 + $ B2. Relative links changed when copied, but absolute ones did not.

In Pascal variables are characterized by their type... A type is a property of a variable, by which a variable can take on a variety of values ​​allowed by this type and participate in a set of operations allowed on a given type.

A type defines the set of valid values ​​that a variable of a given type takes. It also defines the set of permissible operations from a variable of this type and determines the representation of data in the computer's RAM.

For instance:

n: integer;

Pascal is a static language, from this it follows that the type of a variable is determined during its description and cannot be changed. The Pascal language has a developed system of types - all data must belong to a previously known data type (either a standard type created during the development of the language or a user-defined type that is defined by the programmer). The programmer can create his own types with an arbitrary complexity structure based on standard types, or already user-defined types. The number of created types is unlimited. User-defined types in the program are declared in the TYPE section by format:

[name] = [type]

The system of standard types has a branched, hierarchical structure.

Primary in the hierarchy are simple types... These types are found in most programming languages ​​and are called simple, but in Pascal they have a more complex structure.

Structured types are built according to certain rules from simple types.

Pointers are formed from simple types and are used in programs to set addresses.

Procedural types are new to Turbo Pascal, and they allow subroutines to be treated like variables.

Objects are also new, and they are designed to use the language as an object-oriented language.

There are 5 types of integer types in Pascal. Each of them characterizes the range of accepted values ​​and their occupied memory space.

When using integer numbers, you should be guided by the nesting of types, i.e. types with a smaller range can be nested within types with a larger range. The Byte type can be nested in all types that are 2 and 4 bytes long. At the same time, the Short Int type, which occupies 1 byte, cannot be nested into the Word type, since it does not have negative values.

There are 5 real types:

In a computer, integer types are represented absolutely exactly. Unlike integer types, the value of real types defines an arbitrary number only with some finite precision, depending on the format of the number. Real numbers are represented in a computer with fixed or floating point.

2358.8395

0.23588395*10 4

0.23588395 * E 4

A special position in Pascal is occupied by the type Comp, in fact it is a large signed integer. This type is compatible with all real types and can be used for large integers. When representing real numbers with floating point, the decimal point is always implied before the left or high mantissa, but when acting with a number it is shifted left or right.

Ordinal types

Ordinal types combine several simple types. These include:

  • all integer types;
  • character type;
  • boolean type;
  • range type;
  • enumerated type.

Common features for ordinal types are: each type has a finite number of possible values; the value of these types can be ordered in a certain way and a certain number can be associated with each number, which is an ordinal number; adjacent values ​​of ordinal types differ by one.

The ODD (x) function can be applied to values ​​of ordinal type, which returns the ordinal number of the argument x.

PRED (x) function - Returns the previous value of the ordinal type. PRED (A) = 5.

SUCC (x) function - Returns the next value of the ordinal type. SUCC (A) = 5.

Character type

The character type values ​​are 256 characters from the set allowed by the code table of the computer being used. The starting area of ​​this set, that is, the range from 0 to 127, corresponds to the set of ASCII codes, into which alphabet characters, Arabic numbers, and special characters are loaded. The start area characters are always present on the PC keyboard. The senior area is called alternative, it contains symbols of national alphabets and various special characters, and pseudo-graphic symbols that do not correspond to the ASCII code.

A character type value occupies one byte in RAM. In the program, the value is enclosed in apostrophes. Also, values ​​can be specified in the form of its ASCII code. In this case, the # sign must be placed before the number with the character code.

C: = 'A'

Boolean type

There are two Boolean values: True and False. Variables of this type are specified with the BOOLEAN service word. Boolean values ​​occupy one byte in RAM. Values ​​True and False correspond to the numeric values ​​1 and 0.

Range type

There is a subset of its base type, which can be any ordinal type. Range-type is defined by boundaries within the base type.

[min-value] ... [max-value]

The range-type can be specified in the Type section as a specific type, or directly in the Var section.

When defining a range-type, it is necessary to be guided by:

  • the left border should not exceed the right border;
  • range-type inherits all properties of the base type, but with restrictions related to its lower cardinality.

Enumerated type

This type belongs to ordinal types and is specified by an enumeration of those values ​​that it can enumerate. Each value is named by some identifier and is located in the list framed in parentheses. An enumerated type is specified in Type:

Peoples = (men, women);

The first value is 0, the second value is 1, and so on.

Maximum power 65535 values.

String type

The string type belongs to the group of structured types and consists of the base type Char. The string type is not an ordinal type. It defines a set of character strings of arbitrary length up to 255 characters.

In the program, the string type is declared by the word String. Since String is a base type, it is described in the language, and a variable of type String is declared in Var. When declaring a variable of a string type behind String, it is advisable to indicate the length of the string in square brackets. An integer from 0 to 255 is used to indicate.

Fam: String;

Specifying the string length allows the compiler to allocate a specified number of bytes in RAM for the variable. If the string length is not specified, then the compiler will assign the maximum possible number of bytes (255) for the value of this variable.

The simplest numeric data type in Pascal is integer types, which are used to store integers. Integers in Pascal are usually divided into two types: signed and unsigned. Signed numbers are an integer type that includes both positive and negative numbers, unsigned - only positive ones.

Following are two tables with integer types. First, we write out signed integer types:


A typeByteRange of values
shortint1 -128 ... 127
smallint2 -32768 ... 32767
integer, longint4 -2147483648 ... 2147483647
int648 -9223372036854775808 ... 9223372036854775807

And this unsigned integer types:


A typeByteRange of values
byte1 0 ... 255
word2 0 ... 65535
longword, cardinal4 0 ... 4294967295
uint648 0 ... 18446744073709551615

As you can see, the first column contains the name of the type, the second - the number of bytes occupied in memory by numbers of this type, in the third - the range of possible values, respectively. There are two types of signed numbers - integer and longint (literally "whole" and "long integer"), which are synonyms. That is, you can use both one name and another in the descriptions section.

Likewise, in the second table (non-negative integers in Pascal) there are also two 4-byte integer synonym types - longword and cardinal, so use either one or the other.

You can also notice that if the numbers of the first table are conditionally transferred to the right side relative to zero (shift the interval to the right so that the minimum number is 0), then we will get the intervals of integers of the second table lying in the corresponding rows. So, if we add 128 to the left and right borders in a 1-byte shortint type, we get the byte type (0..255); if in the 2-byte type smallint we add 32768 to the boundaries, we get the corresponding 2-byte unsigned type word (0..65535), and so on.

All this happens because in unsigned integer types the numbers can be split exactly in two: half of the numbers - into the negative part, half - into the positive part. And why, then, in signed numbers, the absolute value of the left border is 1 more than the right border? - you ask. For example, in the shortint type the minimum is -128, while the maximum is only 127 (modulo 1 less). And this is because the right side also includes 0, and this must be known and remembered.

So why divide integers in Pascal by so many types? Why not do, for example, with the largest of the integer types in PascalABC.Net and Free Pascal - int64 - this is almost 9 and a half quintillion (!) With both minus and plus? Yes, for a simple banal (?) Reason - saving memory. If you need to add two small one-byte positive numbers (0..255), and you described these numbers as int64 (8 bytes), then it took 8 times more memory. And if the program is large and there are many variables, then the memory savings rises very sharply. Moreover, it makes no sense to use signed integer types if the problem deals with such quantities as length, mass, distance, time, etc.

In the section of the site Abrahamyan's Problem Book (subsection Integer), observe the use of various integer types in Pascal.

The lesson discusses the main standard data types in Pascal, the concept of a variable and a constant; explains how to work with arithmetic operations

Pascal is a typed programming language. This means that the variables that store the data are of a specific data type. Those. the program must directly indicate what data can be stored in a particular variable: text data, numeric data, if numeric, then integer or fractional, etc. This is necessary primarily so that the computer "knows" what operations can be performed with these variables and how to perform them correctly.

For example, the addition of textual data, or as it is correctly called in programming - concatenation is the usual concatenation of strings, while the addition of numeric data occurs bitwise, in addition, fractional and integer numbers are also added in different ways. The same goes for other operations.

Let's consider the most common data types in Pascal.

Integer data types to Pascal

A type Range Required memory (bytes)
byte 0..255 1
shortint -128..127 1
integer -32768.. 32767 2
word 0..65535 2
longint -2147483648..2147483647 4

It should be borne in mind that when writing programs in pascal integer(translated from English. integer) is the most commonly used, since the range of values ​​is most in demand. If a wider range is required, use longint(long integer, translated from English.Long integer). A type byte in Pascal it is used when there is no need to work with negative values, the same goes for the type word(only the range of values ​​is much larger here).

Examples of how variables are described (declared) in Pascal:

program a1; var x, y: integer; (integer type) myname: string; (string type) begin x: = 1; y: = x + 16; myname: = "Peter"; writeln ("name:", myname, ", age:", y) end.

Result:
name: Peter, age: 17

Comments in Pascal

Notice how uses comments in Pascal... In the example, the comments, i.e. service text that is "invisible" to the compiler are enclosed in curly braces. Usually comments are made by programmers for the purpose of explaining code fragments.

Objective 3. The population of Moscow is a = 9,000,000 inhabitants. The population of New Vasyuki is b = 1000 inhabitants. Write a program that determines the difference in the number of inhabitants between two cities. Use variables

Real data types in Pascal

Real numbers in Pascal and in general in programming are the name of fractional numbers.

A type Range Required memory (bytes)
real 2.9 * 10E-39 .. 1.7 * 10E38 6
single 1.5 * 10 E-45 .. 3.4 * 10E38 4
double 5 * 10E-324 .. 1.7 * 10E308 8
extended 1.9 * 10E-4951 .. 1.1 * 10E4932 10

The real type in Pascal is the most commonly used of the real types.

Above were presented simple data types in Pascal, which include:

  • Ordinal
  • Whole
  • brain teaser
  • Character
  • Enumerated
  • Interval
  • Real

To display the values ​​of variables of a real type, formatted output is usually used:

  • in the format, either one number is used, indicating the number of positions allocated to this number in exponential form;
  • p: = 1234.6789; Writeln (p: 6: 2); (1234.68)

    Along with simple types, the language also uses structured data types and pointers, which will be devoted to subsequent lessons in Pascal.

    Constants in Pascal

    Often, a program knows in advance that a variable will take on a specific value and will not change it throughout the execution of the entire program. In this case, you must use a constant.

    The declaration of a constant in Pascal occurs before the declaration of variables (before the function word var) and looks like this:

    An example of describing a constant in Pascal:

    1 2 3 4 5 6 const x = 17; var myname: string; begin myname: = "Peter"; writeln ("name:", myname, ", age:", x) end.

    const x = 17; var myname: string; begin myname: = "Peter"; writeln ("name:", myname, ", age:", x) end.

    "Nice" display of integers and real numbers

    In order to leave indents after displaying the values ​​of variables, so that the values ​​do not "merge" with each other, it is customary to indicate through a colon how many characters must be provided for displaying the value:


    Arithmetic operations in Pascal

    The order of operations

    1. evaluation of expressions in brackets;
    2. multiplication, division, div, mod from left to right;
    3. addition and subtraction from left to right.

    Pascal Standard Arithmetic Procedures and Functions

    Here it is worth dwelling in more detail on some arithmetic operations.

    • The Pascal inc operation, pronounced increment, is the standard pascal procedure, which means increment by one.
    • An example of an inc operation:

      x: = 1; inc (x); (Increases x by 1, i.e. x = 2) writeln (x)

      More complex use of inc procedure:
      Inc (x, n) where x - ordinal type, n - integer type; inc procedure increments x by n.

    • The Dec procedure in Pascal works in a similar way: Dec (x) - decreases x by 1 (decrement) or Dec (x, n) - decreases x by n.
    • The abs operator is the modulus of a number. It works like this:
    • a: = - 9; b: = abs (a); (b = 9)

      a: = - 9; b: = abs (a); (b = 9)

    • The div operator in pascal is a commonly used one because there are a number of tasks involved with integer division.
    • The remainder of the division or the mod operator in pascal is also indispensable for solving a number of problems.
    • Noteworthy is Pascal's standard odd function, which determines whether an integer is odd. That is, it returns true for odd numbers, false for even numbers.
    • An example of using the odd function:

      var x: integer; begin x: = 3; writeln (sqr (x)); (answer 9) end.

    • Exponentiation in Pascal absent as such. But in order to raise a number to a power, you can use the exp function.
    • The formula is as follows: exp (ln (a) * n), where a is a number, n is a degree (a> 0).

      However, in the pascal abc compiler, exponentiation is much easier:

      var x: integer; begin x: = 9; writeln (sqrt (x)); (answer 3) end.

    Task 4. The dimensions of the matchbox are known: height - 12.41 cm, width - 8 cm, thickness - 5 cm.Calculate the area of ​​the base of the box and its volume
    (S = width * thickness, V = area * height)

    Task 5. The zoo has three elephants and quite a few rabbits, with the number of rabbits changing frequently. An elephant is supposed to eat one hundred carrots a day, and a rabbit two. Every morning the zoo attendant tells the computer the number of rabbits. The computer, in response to this, must tell the minister the total number of carrots that today need to be fed to rabbits and elephants.

    Task 6. It is known that x kg of sweets is worth a rubles. Determine how much it costs y kg of these sweets, as well as how many kilograms of sweets you can buy at k rubles. All values ​​are entered by the user.

    In order for the machine to be able to process any input data, it must "understand" what type the variables into which the values ​​are assigned 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 you cannot raise a letter to a power or take an integral from a string. Thus, the user must determine what actions are allowed on each variable.

    As in other high-level programming languages, the types of variables in Pascal are optimized to perform tasks of different directions, have a different range of values ​​and length in bytes.

    Subdivision of variable types

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

    Consider ordinal and real types. Ordinal types include 5 integer types, enumeration and range type.

    Ordinal types

    There are 5 integer types that differ in byte length and range of values.

    Byte and ShortInt are 1 byte long. The difference between the two is that Byte only stores non-negative values, while ShortInt can store negative values ​​as well (-128 to +127). The types Word and Integer have a similar relationship with each other, with the only difference that their size is 2 bytes.

    Finally, LongInt allows you to store both negative and positive values ​​using 4 bytes - in the numerical dimension of the 16th power on either side of zero. Various types of variables in Pascal contribute to the effective solution of user tasks, since in each case, both a small and a large range of values ​​may be required, and it is also possible that there are limitations 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 more than the positive one: for example, from -128 to +127.

    Variables belonging to can be TRUE or FALSE and require 1 byte of memory.

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

    Real types

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

    In the order shown above, each variable type will be 4, 6, 8, or 10 bytes.

    Arrays

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

    String = array of char;

    Thus, we got a type called String, which allows us to set variables with a length of 100 characters. The last line contains a directly one-dimensional array Y of type String. The description of variables in Pascal is carried out by placing on the left side of the identifier, and on the right, after the equal sign, the value of the variable.

    The range of indices, written in, allows you to refer 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 a special case of a one-dimensional array, because a string is a sequence of characters, that is, elements of type char.

    Recordings

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

    type NTel = Record

    The first line on the left contains 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 that we wanted, and this completes the process of creating a record.

    Finally, on the last line, we set the variable One, which is of type NTel.

    You can refer to the record as a whole or to 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 of 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 a file is placed in a folder where the program itself is stored, which is accessing it. The full form can be used in any circumstance.

    You can set a file-type variable as follows:

    f1: file of integer;

    To work with files, various functions and procedures are used that bind a variable to a file on the disk, open it for reading, writing, and overwriting, close it at the end of the work, allowing you to create a new name and delete the file from the computer.

    Finally

    Without the ability to use various types of 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, it is required to learn both the service words and the syntax, since the machine can “understand” commands only if they are written in the only correct way.

    Top related articles