The array in the "Pascal".

click fraud protection

Every year the interest in programming increases.And if you specialize in writing programs institutes emphasis is on a programming language like C ++, in schools and colleges, students are introduced to the "Pascal".And based on this programming language begin comprehension through the use of software Delphi.It should immediately be noted that these programming languages ​​provide a huge space for the manifestation of his imagination.And if using the language "Pascal" is available with the basic concepts of programming in Delphi is already possible to write a full-fledged program.And quite an important place in the writing program sometimes takes a decision arrays "Pascal".

presence of a large number of many different variables

The programming language a lot of different variables, which are characterized by the presence of only a single value.They are able to store a single value having a certain type.An exception are the string variables.It is a collection of those data, which are characterized by character type.But these variables are usually considered from the perspective of a single value.

It's no secret that using a computer, you can greatly reduce the time to perform certain work related to the large volumes of data.But by using only those variables which have known human types can be stored in the work memory, and to process the data that contain a large number of lines?Problems are quite common in any field.

Of course, you can always enter a number of variables that you want to accomplish your goals.It is also possible for them to determine some values.But the program code will only increase.It is difficult to read the code, which has a large number of rows.Especially when you need to find errors.

Accordingly, the programmers thought about this question.It is therefore in languages ​​that have been developed to date, are the variables that provide the ability to save a great amount of data in itself.The array in the "Pascal" Much has changed in the approach to programming.Therefore, it is considered an important variable in the programming language.

Using arrays can significantly reduce the amount of code

This term hides an ordered sequence of data, which are characterized by one type.Furthermore, these data are obtained by a single name.It should also be noted that this definition may fit many real-world objects: dictionaries, cartoons and more.However, the most simple array "Pascal" represented as a kind of table.Each individual cell is one variable.With coordinates can determine the position of the variable that it takes a total table.

What does mean a one-dimensional array?

The simplest is the one table that is linear.In this array to determine the location of a parameter is sufficient to specify only one number.More complex arrays are formed on their basis.

In order to describe the one-dimensional arrays in the "Pascal", simply enter the following code: Type & lt; Name Type & gt;Array [& lt; The range of numbers & gt;] of & lt; Item Type & gt ;.

as those numbers are the variables that can have an ordinal type.Pointing range is understood that the seed can not be higher end.Type, which has an element of the array can be absolutely anything - either standard or previously described.The choice will depend on the need to solve a particular problem.

How does the description of a linear array?

is possible to directly describe the one-dimensional arrays in the "Pascal".This must be done in a special section, which is required for this procedure.You need to enter the following code: Var & lt; variable & gt ;: Array [& lt; The range of numbers & gt;] Of & lt; type of the selected element & gt ;.

In order to understand how to describe the array in the "Pascal", enter the following code:

- Var

- S, VV: Array [5..50] Of Real;

- K: Array ['C' .. 'R'] Of Integer;

- Z: Array [-10..10] Of Word;

- E: Array [3..30] Of Real.

In this example, the variables S, VV, and T is an array of the numbers that are real.Under a variable to a character type, and hiding those elements.Who are at integer.The array Z are stored number, the type in which the Word.

Among the actions that can be used when working with an array, you can select the assignment.He may be subjected to the entire table entirely.For example, S: = VV.But it is necessary to understand that the assignment operator can be subjected to only one array in the "Pascal", which has a certain type.

no more operations that can be directly subjected to the entire array.However, you can work with the elements on the same principle as the other prime numbers having a certain type.In order to address some of the parameters it is necessary to specify the name of the array.Through the use of square brackets is necessary to define the index, which is characteristic of the desired item.For example: R [12].

The main differences between arrays from other variables

basic difference between the components of the table from simple variables can be considered that in brackets it is possible to put not only the value of the index, but is an expression that can lead to the desired value.An example of indirect addressing may be as follows: V [K].The variable K for this takes a certain value.From this it follows that one can use a loop during filling, handling and printing of the array.

This form can occur in the case of string variables, which are quite similar in their properties of the array type whose Char.But there are differences.They are as follows:

  1. String variables can always be entered from the keyboard on the screen and print.
  2. String variable in length is limited.You can enter a maximum of 255 characters.The critical capacity of the array is considered to be 64 kb.

By applying what methods can be derived array data on the screen?

should be given to a method for displaying the contents of the array in the display.They are several.

  1. Writeln (A [1], A [2], A [3]).Such an example, although primitive way to show how you can apply directly to each individual element inherent in the table.However, some of the advantages that the arrays in the language, "Pascal" before the simple variables are not visible.
  2. Program A1;
    Var B: Array [1..10] Of Integer;
    K: Integer;
    Begin
    For K: = 1 To 10 Do {This team organizes a cycle with parameter}
    Readln (A [K]);{Occurs input A [I] by using the keyboard}
    For K: = 1 10 Downto Do {Occurs printing table in reverse}
    Write (A [K], 'VVV')
    End.

This program code arrays in the "Pascal" demonstrates how you can use the keypad to enter 10 numbers, print them, rearranging values ​​in reverse order.If the same program rewritten using a large number of variables instead of an array, the code is considerably increased.This substantially complicates the process of reading the program.

Increased capacity through the use of arrays

You can also fill in the table those values ​​that are equal to the square of the index components.There is also the possibility to make such an array of strings in the "Pascal", which will allow to all the numbers have been entered automatically.As you can see, the use of the array significantly increases the possibility of programming language "Pascal".

processing line array is very common in a variety of tasks.Therefore, there is nothing strange in the fact that they are studying in colleges and schools.Besides the opportunities that carry arrays quite extensive.

What is hidden under the two-dimensional array?

can imagine such a table, which consists of several lines at once.Every single line has multiple cells.In this situation, in order to accurately determine the position of the cells, it should be noted more than one index, as in the case of linear arrays, and two - numbers which are characteristic for the row and column.Such perceptions are characterized by two-dimensional arrays in the "Pascal".

How to make a description of the tables of this kind?

That data structure that is found in the language "Pascal" in order to store the values ​​of this table is called a two-dimensional array.Description of this array may immediately using two methods.

  1. Var B: Array [1..15] Of Array [1..30] Of Integer;
  2. Var B: Array [1..15, 1..30] Of Integer.

In all these cases is described by a two-dimensional array that has 15 rows and 30 columns.Those descriptions that are described above, it is absolutely equal.To start working with any one of the elements necessary to identify two of the index.For example, A [6] [5] or A [6,5].

Display will be practically the same as in the case of one-dimensional array.You only need to specify the two indexes.In all other differences as such it is not available, therefore, to talk about this for a long time is not required.

first method by which you can sort the

Sometimes you need to sort the data.For this language are corresponding commands.There are two algorithms, which can be made by sorting the array in the "Pascal".The meaning of the direct selection method lies in the fact that through the nesting cycle absolutely every variable of the table will be compared with other values.In other words, if there is an array of 15 numbers, the first number 1 will take the comparison with other numbers.This will occur until such time as, for example, is found the element which greater than the first number.Subsequently, a comparison will be exactly the figure.It will be repeated until such time until you find the greatest element of all proposed.This method is simple enough for those programmers who are just starting to work in the language.

second method of sorting arrays

second method - a bubble.The essence of this method lies in the fact that there is a comparison of adjacent pairs.For example, 1, and 2, 2 and 3, 3 and 4, and so on.. In the event that the value found will fully comply with the terms of the sort, it will be moved to the end of the entire array, t. E. Will emerge as the "bubble".This algorithm is the most difficult to remember.However, it is not necessary to memorize.The main thing is to understand the whole structure of the code.And only then can apply to achieve great heights in programming.

Conclusion

We hope that you understand what constitutes arrays, as well as the way in which you can sort the list to find a specific value or to achieve a particular goal.If you have been selected to address a particular problem "Pascal" arrays in which play an important role, the need to study them thoroughly to come.At this influences such factors as the presence of a sufficiently large number of language variables to be used in certain situations to simplify the entire code as a whole.Arrays are considered basic values, the study of which should be mandatory.