Pascal - programming basics for beginners. Introduction to the Pascal programming language. Beginner level Examples of how to program in Pascal school curriculum

💖 Do you like it? Share the link with your friends

This article will describe the basics of the Pascal programming language, necessary for writing the first programs: program structure, the concept of a variable, data types, mathematical operators and functions, assignment operator, data input and output. Once again I will emphasize that this article is for the very first steps in learning the language for students in grades 7-8. There will be no in-depth discussion here (there is appropriate literature for that).

Program structure

Program structure is the set of sections that make up the program.

To write your first program in Pascal, you only need to know two sections (actually there are more):

  • variable description section - var— this section lists the variable names used in the program, separated by commas. Their type is indicated below.
  • body of the program - begins with the word begin and ends with the word end.(with a dot). This section contains the text of the program itself.
var variables: datatype; begin program body end.

Variables

What is a variable?

Let's imagine a variable as a memory cell to which we assign a name and in which we can store something (a number or text).

Memory cells named a, b, c

The variable name must satisfy the following requirements:

  • consist of letters of the Latin alphabet (a-z, A-Z), numbers and the underscore “_”;
  • The variable name must not begin with a number (but may begin with a "_" sign ( For example: _primer).
  • variable name must not contain spaces

Variable primer And PriMer for Pascal are equivalent

Data types

After we list the variables in the section var, we must specify their type:

  • integer- integer type
  • real— real type (fractional numbers)
  • string- string type

For example:

var a, b, c : integer ;

where a, b, c are variables, integer is the type of these variables. Those. variables (memory cells) a, b, c can only contain integers.

There are many other types of data, but the three voiced ones will be enough to write the first programs.

If it is necessary that some variables be of one type, and some of another:

var a, b: integer; with :real ;

those. variables a, b are integers, and a variable With— real number (non-integer).

Assignment operator

The assignment operator is used to assign a value to a variable.

:= assignment operator

Record a:=23; reads "Variable" A assigned value 23 ". Now in a memory cell with the name A number is stored 23.

Input operator

There is another operator with which you can write a value to a variable, but using the keyboard.

readln(a)

As soon as pascal executes the command readln(a), it will require us to enter a value from the keyboard, which will be written to the variable in parentheses. In our case - into a variable a.

Mathematical operations

+ - addition operation

- subtraction operation

* - multiplication operation

/ - division operation

mod- remainder of the division

div- integer part from division

Example:

S:=22 mod 5; After executing this when the variable S will become equal 2 .

S:= 22 div 5; After executing this code, the variable S will become equal 4.

Inference operator

To display the value of a variable on the screen, use the command write(a) or writeln(a). After executing the command writeln a transition to a new line occurs, but after executing the write command it does not.

If you need to display text on the screen, then it is enclosed in apostrophes:

writeln('Mom washed the frame');

You can also display text along with the value of the variable:

a:=6;
writeln(‘ Variable value a = ‘, a);

On the screen we will see: The value of the variable a=6.

Let's consider the problem:

Using the length and width values ​​entered from the keyboard, find the area and perimeter of the rectangle.

var a,b,S,P:integer; //declare variables begin writeln(" Enter the length of the rectangle"); readln( a); //enter the length writeln(" Enter the width of the rectangle"); readln( b); //enter the width S:=a*b; //calculate the area of ​​the rectangle P:=2*(a+b); //calculate the perimeter of the rectangle writeln(" The area of ​​the rectangle is ",S); //display writeln(" The perimeter of the rectangle is ",P); end.

Professional development environment for creating programs and applications of any level of complexity. Combines the classic simplicity of Pascal with all the capabilities of the modern .NET development environment used by professional developers around the world. In addition, the Pascal programming language is studied in a school computer science course, giving students basic knowledge about operators and variables. Thus, learning Pascal abs is better for beginners than learning other programming languages.

The course of seven practical video lessons is ideal for those who want to learn how to make a program in Pascal ABC, regardless of their skill level. Each lesson has its own topic, so you can watch them either in order or selectively to deepen and expand your knowledge in a particular area.

Pascal ABC Lessons

The Pascal ABC lessons presented in the video course are based on the development of application programs and provide practical knowledge. All the programs that you write during the video course are fully working and can be used in everyday life - there is no “water” or empty theory in the course.

We master the editor interface and write our first lines of code.


We study the logic of working with numbers and design a timer.


We study how a programming language compiles source code.



We use Pascal to find a solution to the problem about schoolgirl Anna.


We program a real virtual music synthesizer.


We master complex mathematical functions and create a full-fledged engineering calculator.



We create the “correct” phone book based on the database.


Lesson 1 - First program
Lesson 2 - Prime numbers
Lesson 3 - Compilers (Part 1)
Lesson 3 - Compilers (Part 2)
Lesson 4 - Solving a school problem
Lesson 5 - Making a Piano
Lesson 6 - Advanced Calculator (Part 1)
Lesson 6 - Advanced Calculator (Part 2)
Lesson 7 - Convenient phone book (Part 1)
Lesson 7 - Convenient phone book (Part 2)
Lesson 7 - Convenient phone book (Part 3)
Lesson 7 - Convenient phone book (Part 4)
Lesson 8 - Working with graphics. Particle System (Part 1)
Lesson 8 - Working with graphics. Particle System (Part 2)
Lesson 8 - Working with graphics. Particle System (Part 3)
Lesson 8 - Working with graphics. Particle System (Part 4)

This book is not a textbook, but rather an assistant in mastering the Pascal programming language, which all schoolchildren are introduced to in computer science lessons. It consists of conversations devoted to practical issues of programming and problem solving. Numerous examples allow you to better understand how to develop an algorithm, write your own program, and format its text correctly. Tips and notes draw readers' attention to important details, help them avoid pitfalls, and write programs more efficiently.
The book was written by school computer science teachers with great experience many years of practical work.

What is a programming language? Any problem that a computer solves is written as a sequence of commands. This sequence is called a program. The commands, of course, must be presented in a language that the computer can understand. One such language is the Pascal programming language. It was developed by Swiss professor Nikolaus Wirth specifically for teaching students programming. The peculiarities of language also include its structure. That is, the program is easily divided into simpler, non-overlapping blocks, which, in turn, are divided into even simpler blocks. This also makes programming easier. In 1979, the language was approved as a standard language. Wirth named it after the French scientist Blaise Pascal, inventor of the calculating machine. The Pascal language is simple, logical and efficient. It has spread all over the world. Our conversations are based on specific examples of programs. There are no lengthy theoretical explanations, so it is imperative to carefully read the comments in the program texts!
So, we start the first conversation right away with the first program in Pascal;

Content
Introduction 7
Thanks 7
From the publisher 8
TOPIC 1. How to write a simple program on Pascal 9
Lesson 1.1. We display a message on the display screen 10
Lesson 1.2. How can I install this program on my computer? eleven
Stages of creating a computer program 12
1. Launching the Pascal 14 environment
2. Working in the Edit 16 editing window
3. Saving the program to a file on disk 19
4. Launching the compiler 20
5. Execution of program 21
6. Viewing the results of the program 21
7. Exit from Pascal 22 environment
Lesson 1.3. Formatting text on screen 22
Conclusions 28
Test questions 28
TOPIC 2. How to incorporate numerical data into your work 30
Lesson 2.1. Let's start with something simple: the integers 31
Concept of variable 32
Type Integer. Assignment operator. Display 32
Operations with type Integer 34
Standard functions of type Integer 36
How variables of integer type are represented in computer memory 38
Lesson 2.2. Let's put it to work real numbers 39
Description of the real data type (Real) 40
Formats for recording real variables 40
Material operations 41
Standard functions of type Real 41
Writing Math Expressions 43
How real type variables are represented in memory
computer 45
Lesson 2.3. How to combine integer and real type variables 46
Type Conversion 46
Priority rules in performed actions 47
Actions with data different types 47
Lesson 2.4. Data input and output 51
Entering variables from the keyboard 52
Beautiful display 52
Setting variable values ​​using a random number sensor 55
Lesson 2.5. Why are constants needed in a program? 57
Conclusions 59
Test questions 60
TOPIC 3. Learning to work with symbols 61
Lesson 3.1. How does a computer understand 62 characters?
ASCII 62 code table
Description of the Char type and standard functions 63
Lesson 3.2. The Char type is an ordinal type! 64
Conclusions 66
Test questions 67
TOPIC 4. George Boole and his logic 68
Lesson 4.1. One more type is needed - logical! 69
Boolean data type 70
Relation operations 70
Boolean I/O 71
Lesson 4.2. Logical (Boolean) operations 71
Logical multiplication (conjunction) 72
Logical addition (disjunction) 72
Exclusive OR (addition modulo 2) 73
Logical negation (inversion) 74
Application logical operations in program 74
Priority of logical operations 76
Conclusions 77
Test questions 78
TOPIC 5. Analysis of the situation and sequence of command execution 79
Lesson 5.1. Condition checking and branching in Algorithm 80
Full and incomplete form of the if statement 81
Design of programs 84
Lesson 5.2. Operator blocks 85
Lesson 5.3. Branching according to a number of conditions (case statement) 90
Conclusions 94
Test questions 95
TOPIC 6. Repeated actions 96
Lesson 6.1. Operator- for loop 97
For statement with incremental counter increment 97
For statement with sequential decrement of counter 99
Lesson 6.2. Using loops with a counter of 99
Cycle within a cycle 100
Tracing 101
Calculating the sum of series 103
Conclusions 107
Test questions 108
TOPIC 7. Loops with condition 109
Lesson 7.1. Loop with precondition 110
Description of the loop with precondition 110
Approximate calculation of the sum of an infinite series 111
Entering a number to the specified integer power 114
Lesson 7.2. Loop with postcondition 118
Description of a cycle with a postcondition 119
Using repeat and while loops 119
Relativity of the choice of operators while and repeat 123
Conclusions 129
Test questions 129
TOPIC 8. Arrays - structured data type 131
Lesson 8.1. Storing similar data in the form of a table 132
Basic steps for working with arrays 133
Description of an array in Pascal 133
Filling an array with random numbers and displaying the array on the screen 134
Creating a Custom Data Type 137
Finding the maximum array element 141
Calculating the sum and number of array elements with given properties 146
Lesson 8.2. Search in array 148
Determining if an Array Has a Negative Element Using a Flag 149
Determining the presence of negative elements in an array by calculating their number 150
Finding the number of the negative array element 152
Lesson 8.3. Two-dimensional arrays 156
Conclusions 158
Test questions 159
TOPIC 9. Auxiliary algorithms. Procedures and functions. Structured programming 160
Lesson 9.1. Designing a Top-Down Algorithm 161
Practical problem using auxiliary algorithms 162
Lesson 9.2. An example of working with a function: searching for the maximum element 169
Conclusions 171
Test questions 171
TOPIC 10. How to work with character strings 1 72
Lesson 10.1. Working with strings of characters: type String 1 73
Description of a string variable 173
Basic operations with 174 strings
Lesson 10.2. Some Pascal functions and procedures for working with strings 175
Using Library String Routines 175
Conclusions 177
Test questions 178
TOPIC 11. Procedures and functions with parameters 179
Lesson 11.1. Simple examples using subroutines with parameters 180
The simplest procedures with 180 parameters
Formal and actual parameters 182
The simplest functions with 183 parameters
Lesson 11.2. Methods for passing parameters 184
Conclusions 187
Test questions 187
TOPIC 12. Files: saving the results of the work until next time 189
Lesson 12.1. How to work with a text file 190
Opening a file for reading 190
Opening a file for writing 193
Lesson 12.2. Storing a two-dimensional array of numbers in text file 196
Saving Numeric Data to a Text File 196
Saving an array of numbers in a text file 197
Adding information to the end of the file 201
Conclusions 202
Test questions 203
TOPIC 13. Graphic mode of operation. Graph 204 module
Lesson 13.1. Enable graphic mode 205
Features of working with graphics 205
Switching to graphics mode of the video adapter 206
Lesson 13.2. We continue to explore the capabilities of the Graph 208 module
Drawing lines using the Graph module 209
Drawing circles using the Graph 210 module
Conclusions 212
Test questions 212
TOPIC 14. Operators that change the natural flow of the program 213
Lesson 14.1. Using the goto 215 unconditional jump operator
Lesson 14.2. Statements that change the flow of a loop 218
break statement 2.19
Operator continue 220
Conclusions 220
Test questions 221
Appendix 1. Block diagram elements 222
Appendix 2. Homework 224
Assignments for Chapter 2 224
Assignments for Chapter 4 227
Tasks for chapters 6-7 229
Chapter 8 assignments 236
Alphabetical index 254

There is probably not a single modern person who does not know the Pascal language (the basics of programming). And this is not surprising! The most basic concepts of this unique program are described in the computer science textbook for schoolchildren.

Now, in this century information technologies, everyone can conduct self-tutorial training online (by taking the courses “Learning programming languages ​​from scratch”; “Pascal for dummies” and others).

The history of the language being studied is not so simple: Pascal underwent many changes before schoolchildren saw it in the form in which it is taught in the classroom. It was the very first simple language (ord pascal) for programming, helping to solve many practical problems of the last century (1970). It was developed by a group of scientists.

As platforms expanded, new versions of this program were created, and Pascal became a classic programming language.

Below we will look at what Pascal is and what its main tools are. Let's consider the operations and functions of the program, its specific features. Let's use examples to understand how it works. Let's learn to write and work in Pascal.

What is the Pascal programming language

This is a basic high-level program. It ranks first in the curricula of many schools and universities in the Russian Federation.

Features of the PascalABC.NET system

Everything is learned by comparison, so let’s consider the advantages of this program in relation to another BASIC language.

So, what is typical for the Pascal language and what is not suitable for BASIC:

  1. Firstly, the presence of a compiler that allows you to download Pascal to any platform.
  2. Secondly, all versions of this program are compatible with each other.
  3. Thirdly, structured data types help the programmer to accurately compose the necessary algorithm for solving a practical problem, while protecting it.
  4. Fourthly, the clarity and logic of the program interface: all commands are simple and understandable.
  5. Fifthly, switching to another, higher-level programming language is quite simple.

Example programs on PascalABC.NET

Sum of entered integers

Product of integers

How many are odd among the n entered?

Invalid input protection

Conclusion of 10 first powers of two

Find the sum of the digits of a positive integer m

Factoring a number into prime factors

Pascal for Beginners - Basic Concepts

Let's look at the basic concepts that help to correctly write a program in this language.

Workspace

What does the workspace look like?

Now let's look at the basics: the alphabet and structure.

Alphabet Pascal

What do you need to know? An alphabet is a set of symbols needed when composing a program.

What they include:

  1. Latin uppercase, lowercase letters (A, B, C....a,b,c).
  2. Arithmetic symbols (0, 1, 2...).
  3. Special characters (punctuation, parentheses, quotation marks, arithmetic signs, etc.).
  4. Indivisible symbols (:=, ˃=…).
  5. Function words:
  • and – and;
  • array – array;
  • begin – beginning;
  • do – execute;
  • else - otherwise;
  • for – for;
  • if – if;
  • of – from;
  • or – or;
  • procedure – procedure;
  • program – program;
  • repeat – repeat;
  • then – that;
  • to – before;
  • until – until (= while);
  • var – variable;
  • while - for now.

Please note: constants and operations should not have the same names as function words (any length).

Program structure

So, what is included in the “hierarchy” of this program?

According to its structure, this language is divided into 3 sections:

  • Name;
  • data;
  • actions.

Note: Variables must be listed separated by commas, and then their type must be indicated through “:”. Complete the written word with “;”.

Actions begin with "begin" and end with "end" with a period.

The structure can be represented as follows:

By the way, operators are separated by semicolons.

Operators write, writeln, read, readln

Let's find out how the output and input of information occurs.

Conclusion

There are no output operators as such in this language, but there are special words that help launch the necessary functions. This write, writeln.

What is their main difference? When entering or outputting subsequent information after them: in the first case, subsequent information will be output on the same line where the statement is written. But in the second - to the next one.

Enter

There are also words for input: read, readln(=readkey).

They differ from each other in the same way as the previous statements (in output).

Integer data type

There are 3 main types:

  1. Integer.
  2. Byte.
  3. Longint.

They also carry out simple actions:

  • addition – “+”;
  • subtraction – “-”;
  • multiplication - "*";
  • division – “div”.

In addition, it is allowed to make relationships and comparisons (greater than or equal to - ˃ =).

Real data types

Such variables include fractional numbers (for example, pi). Here they are called real.

What to remember? To enter a formula fractional number, you need to use a period instead of a comma. To write powers (x * 10 y), 10 is replaced by E and the number has the notation:

With them you can perform both the simplest arithmetic operations and more complex ones:

  • square root – sqrt;
  • absolute value – abs;
  • quadratic function – sqr;
  • sine – sin;
  • cosine – cos;
  • arctangent – ​​arctan;
  • natural logarithm – ln;
  • exponent – ​​exp.

Data processing

In addition to the functions listed above (in the previous 2 paragraphs), there are others:

  • integer part of the number – int;
  • fractional part of the number – frac;
  • getting the integer part of a number – trunc;
  • rounding to the nearest whole number – round;
  • ordinal type conversion – ord;
  • converting code to character type – chr;
  • determination of the previous value of a quantity – pred;
  • determination of the subsequent value of a quantity – succ.

Mathematical operations

Mathematical functions and operations were covered when parsing integer and real data.

Let's focus on the types of constants and variables. What are they?

Simple ones include subtypes:

  • integers – integer;
  • logical – boolean;
  • character – char;
  • enumerable;
  • interval;
  • real

Strings are written with the string command. References are presented in the appropriate form.

Structured ones are divided into:

  • arrays – array;
  • records – record;
  • sets – set;
  • file – file.

Each type has its own set of operations.

Conditions

If there are alternative commands and functions, then using the if, then, else statements you can write down the necessary commands to solve a practical problem.

The diagram is shown in the figure below.

Logical operations

Operations are based on the truth of a fact or its lie.

There are 3 types of such functions:

  1. Odd - if the number is odd, then true (vice versa - false).
  2. Eoln – true at the end of the line (elsewhere – false).
  3. Eof – true at the end of the file (elsewhere – false).

Program control functions

What other procedures exist:

  • Inc – increase in number;
  • Clrscr – clearing previous results of the program;
  • Uses crt – launch clscr;
  • Length – return the length of the string;
  • Val – convert a string to a number;
  • Pos – find the first transformation in the string;
  • Assign – linking a variable to a file;
  • Upcase - converting lowercase letters to uppercase ones.

Conclusion

So, to become a good programmer, you first need to learn the basics. Pascal is the best choice for this.

2nd ed. - St. Petersburg: 2011. - 320With.

This book is not a textbook, but rather an assistant in mastering the Pascal programming language, which all schoolchildren are introduced to in computer science lessons. It consists of lessons devoted to practical programming and problem solving issues. Numerous examples allow you to better understand how to develop an algorithm, write your own program, and format its text correctly. Tips and notes help the reader pay attention to important details, allowing you to avoid pitfalls and write programs more efficiently. The book was prepared by computer science teachers at the school who have extensive experience of many years of practical work. The second edition adds several new chapters on records, dynamic variables, the stack, queues, and lists. One of the most difficult topics in programming is also covered - the construction of recursive algorithms.

Format: pdf(2011, 2nd ed., 320 pp.)

Size: 14.5 MB

Watch, download: docs.google.com

Content
Preface to the second edition 15
Introduction 16
From the publisher 16
TOPIC 1. How to write a simple program in Pascal 17
Lesson 1.1. We display a message on the display screen 18
Lesson 1.2. How to install this program on a computer 19
Stages of creating a computer program 20
Lesson 1.3. Formatting text on screen 28
Conclusions 34
Test questions 34
TOPIC 2. How to incorporate numerical data into your work 36
Lesson 2.1. Let's start with something simple: the integers 37
Concept of variable 38
Type Integer. Assignment operator. Display 38
Operations with type Integer 40
Standard functions of type Integer 42
How variables of integer type are represented
in computer memory 43
Lesson 2.2. We include real numbers 45 in the work
Description of the real data type (real) 45
Formats for recording real variables 46
Material operations 46
Standard functions of type real 47
Writing Math Expressions 48
How real type variables are represented in computer memory 50
Lesson 2.3. How to combine integer and real type variables 51
Type Conversion 51
Priority rules in performed actions 52
Actions on data of different types 53
Lesson 2.4. Data input and output 56
Entering variables from the keyboard 57
Beautiful display 57
Setting variable values ​​using a random number sensor 61
Lesson 2.5. Why are constants needed in a program? 62
Conclusions 64
Test questions 64
TOPIC 3. Learning to work with symbols 66
Lesson 3.1. How does a computer understand symbols 67
ASCII 67 code table
Description of the Char type and standard functions 68
Lesson 3.2. The Char type is an ordinal type! 70
Conclusions 71
Test questions 72
TOPIC 4. George Boole and his logic 73
Lesson 4.1. One more type is needed - logical! 74
Boolean data type 75
Relational operations 75
Boolean I/O 76
Lesson 4.2. Logical (Boolean) operations 76
Logical multiplication (conjunction) 76
Logical addition (disjunction) 77
Exclusive OR (addition modulo 2) 77
Logical negation (inversion) 78
Using logical operations in program 78
Logical operation priority 80
Conclusions 81
Test questions 81
TOPIC 5. Analysis of the situation and sequence of command execution 82
Lesson 5.1. Checking conditions and branching in Algorithm 83
Full and partial form of the if statement 84
Design of programs 86
Lesson 5.2. Operator blocks 88
Lesson 5.3. Branching according to a number of conditions (case statement) 92
Conclusions 96
Test questions 96
TOPIC 6. Repeated actions 98
Lesson 6.1. Loop statement for 99
Operator for with sequential increment of the counter 100 Operator for with sequential decrement of the counter 101
Lesson 6.2. Using loops with counter 101
Cycle within a cycle 102
Trace 103
Calculating the sum of series 105
Conclusions 108
Test questions 109
TOPIC 7. Loops with condition 110
Lesson 7.1. Loop with precondition 111
Description of the loop with precondition 111
Approximate calculation of the sum of an infinite series 112
Raising a number to the specified integer power 115
Lesson 7.2. Loop with postcondition 119
Description of a loop with postcondition 120
Using repeat and while loops 120
Relativity of the choice of operators while and repeat 123
Conclusions 129
Test questions 129
TOPIC 8. Arrays - structured data type 131
Lesson 8.1. Storing similar data in the form of a table 132
Basic steps for working with arrays 133
Description of an array in Pascal 133
Filling an array with random numbers and displaying the array on the screen 134
Creating a Custom Data Type 137
Finding the maximum array element 140
Calculating the sum and number of array elements with given properties 144
Lesson 8.2. Search in array 148
Determining the presence of a negative element in an array using a flag 148
Determining the presence of negative elements in an array by calculating their number 149
Finding the number of the negative element of the array 150
Lesson 8.3. Two-dimensional arrays 154
Conclusions 156
Test questions 157
TOPIC 9. Auxiliary algorithms. Procedures and functions. Structured programming 1 58
Lesson 9.1. Designing a top-down algorithm 159
Practical problem using auxiliary algorithms 160
Lesson 9.2. Example of working with the function: Finding the maximum element 167
Conclusions 168
Test questions 169
TOPIC 10. How to work with character strings 170
Lesson 10.1. Working with strings of characters: type String 171
Description of a string variable 171
Basic operations with 172 strings
Lesson 10.2. Some Pascal functions and procedures for working with strings 173
Using Library String Routines 173
Conclusions 175
Test questions 175
TOPIC 11. Procedures and functions with parameters 176
Lesson 11.1. Simple examples of using subroutines with parameters 177
The simplest procedures with parameters 177
Formal and actual parameters 179
The simplest functions with parameters 179
Lesson 11.2. Methods for passing parameters 181
Conclusions 183
Test questions 184
TOPIC 12. Files: saving the results of the work until next time 185
Lesson 12.1. How to work with a text file 186
Opening a file for reading 186
Opening a file for writing 188
Lesson 12.2. Saving a two-dimensional array of numbers in a text file 192
Saving Numeric Data to a Text File 192
Saving an array of numbers in a text file 192
Adding information to the end of the file 196
Conclusions 197
Test questions 197
Topic 13. Graphical mode of operation. Graph module 199
Lesson 13.1. Enable graphic mode 200
Features of working with graphics 200
Switching to graphics mode of the video adapter 201
Lesson 13.2. We continue to explore the capabilities of the Graph 203 module
Drawing lines using the Graph 203 module
Drawing circles using the Graph 205 module
Conclusions 206
Test questions 207
Topic 14. Operators that change the natural flow of the program 208
Lesson 14.1. Using the goto 210 unconditional jump operator
Lesson 14.2. Statements that change the flow of a loop 213
break statement 213
Continue operator 214
Conclusions 215
Test questions 215
Topic 15. Grouping data: records 216
Lesson 15.1. Description of data type record 218
Lesson 15.2. When and how to wisely use 220 records
Creating your own data type - entry 220
Array of records 220
Join operator with 221
Data structure selection example 223
Records of records 224
Conclusions 225
Test questions and assignments 225
Topic 16. Dynamic variables 226
Lesson 16.1. Memory allocation 227
Lesson 16.2. Addresses 229
Lesson 16.3. Signs 230
Pointers to individual variables 230
Pointers to variable blocks 232
Lesson 16.4. Dynamic memory allocation 232
New and Dispose 233
Dynamic memory allocation for arrays 235
GetMem and FreeMem 236
Accessing elements of an array created dynamically 237
Variable length array 238
Conclusions 241
Test questions 242
Topic 17. Dynamic data structures. Stack 244
Lesson 17.1. Let's describe data type 245
Lesson 17.2. Creating a stack and basic stack operations 247
Adding an element to the stack (Push) 248
Popping an element from the stack (Pop) 251
Checking the stack for emptiness (StacklsEmpty) 252
Lesson 17.3. Using the 253 stack
Programming a Stack Using a 255 Array
Conclusions 256
Test questions and assignments 256
Topic 18. Dynamic data structures. Queue 258
Lesson 18.1. Operating principle and description of the data type 259
Lesson 18.2. Basic queue operations 261
Adding an element to the queue (EnQueue) 261
Removing an element from a queue (DeQueue) 263
Checking the queue for emptiness (QueuelsEmpty) 264
Lesson 18.3. Using Queue 264
Programming a Queue Using an Array 267
Conclusions 269
Test questions 269
Topic 19. Dynamic data structures. One-way list 270
Lesson 19.1. Description of the data type and operating principle 271
Lesson 19.2. Basic operations with a one-way list 272
Sequential viewing of all list elements 272
Placing an element in a list 273
Removing an element from a list 275
Lesson 19.3. List processing 276
The feasibility of using a one-way list 278
Conclusions 280
Test questions 280
Topic 20. Recursion 281
Lesson 20.1. Description of principle 282
Lesson 20.2. Towers of Hanoi 285
Lesson 20.3. Structure of a recurrent subroutine 287
Lesson 20.4. An example of a recurrent solution to a non-recurrent problem 288
Lesson 20.5. An example of a recurrent solution to a recurrent problem 289
Conclusions 291
Test questions 291
Appendix 1. Block diagram elements 292
Appendix 2. Problems 295
Integer. Description. Enter. Conclusion. Operations 296
Real. Description. Enter. Conclusion. Operations and functions 296
Real. Writing and Evaluating Expressions 297
Char. Description. Enter. Conclusion. Functions 298
Boolean. Writing Expressions 298
Boolean. Evaluating Expressions 299
If. Simple comparisons. Min/max/average 300
If. Equations and inequalities with 300 parameters
For. Transfers 300
For. Calculations with Loop Counter 301
For. Overkill with comparisons 302
While-Repeat. Search 302
While-Repeat. Rows 303
Graphic arts. Straight 303
Graphic arts. Circles 304
Arrays. Filling, withdrawal, amount/quantity 305
Arrays. Permutations 305
Arrays. Search 306
Arrays. Checks 307
Arrays. Maximums 307
Subroutines without parameters 307
Lines. Part I 308
Lines. Part II 309
Subroutines with parameters. Part I 309
Subroutines with parameters. Part II 310
Subroutines with parameters. Part III 310
Files 311
Unidirectional list 312
Recursion 313

After the release of the first edition of the book, our colleagues and students began to increasingly contact us with a request to supplement the first edition with information about the most studied and in demand data structures. In this edition we have added several chapters on records, dynamic variables, stack, queue and lists. We also tried to cover one of the most difficult topics in programming - the construction of recursive algorithms.
In the application, we decided to abandon the homework collection with many options on several topics. Instead, we included a large number of thematic tasks in the application, organized in blocks of 5-8 tasks. The tasks in each block are arranged from simple to complex. We use them in our lessons to organize practical classes while reinforcing theoretical material (one lesson - one block).
The authors express their deepest gratitude to one of their best students, Associate Professor of the Department of Security information systems SPbSUAP, Ph.D. Evgeny Mikhailovich Linsky for support, many useful tips and great help during the work on the second edition of the book.



tell friends