Pascal - the basics of programming for beginners. Introduction to the Pascal programming language

Pascal - the basics of programming for beginners.  Introduction to the Pascal programming language
Pascal - the basics of programming for beginners. Introduction to the Pascal programming language

We create the first program in PascalABC.NET. Let's analyze the main points.

PascalABC.NET - SCHOOL - Prime numbers. Sieve of Eratosthenes

We analyze the fastest algorithm for finding prime numbers. Sieve of Eratosthenes. An experiment comparing algorithms. We analyze a few more functions and features of the Pascal language ...

PascalABC.NET - SCHOOL - Compilers (1.Introduction) - Number extraction

Let's get started with compilers. We are looking for integer and fractional numbers in the text. Stay tuned for this line!

PascalABC.NET - SCHOOL - Compilers (2. Finish highlighting) - Words and lines

We continue to develop the compiler. Learning to highlight words and lines.

PascalABC.NET - SCHOOL - Solving a problem for grade 7

PascalABC.NET - SCHOOL - ♫ Piano + OOP + Klitschko

We figure out how to make a simple piano using OOP (object-oriented programming).

PascalABC.NET - SCHOOL - 1. Cool calculator with brackets. Expression parsing

We are writing a powerful calculator that parses brackets and functions like sin or trunc. OOP (object-oriented programming).

PascalABC.NET - SCHOOL - 2. Cool calculator with brackets. Expression parsing

CONTINUATION!!! We bring to mind a powerful calculator that parses brackets and functions, such as sin or trunc. OOP (object-oriented programming).

PascalABC.NET - SCHOOL - 1. Advanced phone book! Quick search. Indexing

How to implement quick search V large volume data. Graph theory. We create on the example of a phone book.

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

Now, in the century information technologies, everyone can conduct self-study training online for themselves (having completed 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.

With the expansion of platforms, new versions of this program were created, and Pascal became a classic programming language.

Below we will understand: what is Pascal, what are its main tools. Consider the operations and functions of the program, its specific features. Let's see how it works with examples. 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 known in comparison, so we will 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 visibility and logic of the program interface: all commands are simple and clear.
  5. Fifthly, the transition to another, higher level programming language is quite simple.

Example programs in PascalABC.NET

Sum of input integers

Product of integers

How many odd ones among n entered

Invalid input protection

Conclusion of the first 10 powers of two

Find the sum of digits of a positive integer m

Decomposing a number into prime factors

Pascal for beginners - basic concepts

Let us analyze the basic concepts that help to correctly write a program in this language.

Workspace

What does the workspace look like?

Now consider the basics: alphabet and structure.

Pascal alphabet

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

What applies to them:

  1. Latin uppercase, lowercase letters (A, B, C .... a, b, c).
  2. Arithmetic symbols (0, 1, 2…).
  3. Special characters (punctuation, brackets, quotation marks, arithmetic marks, etc.).
  4. Indivisible characters (:=, ˃=…).
  5. Service words:
  • and - and;
  • array - an array;
  • begin - the 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 is a variable;
  • while - while.

Take into account: constants, operations should not have the same names as service 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 after that, through ":" indicate their type. Complete the written ";".

Actions start with "begin" and end with "end" with a dot.

The structure can be represented as follows:

By the way, operators are separated by semicolons.

Write, writeln, read, readln statements

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

Conclusion

As such, there are no output operators in this language, but there are special words that help run 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 displayed on the same line where the operator is written. But in the second - on the next.

Input

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

They differ from each other in exactly 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 conduct relations and comparisons (greater than or equal to - ˃ =).

Real data types

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

What should be remembered? To enter a fractional number formula, you must use a dot 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:

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

Mathematical operations

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

Let's dwell 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 represented by the corresponding form.

Structured 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 the necessary commands to solve a practical problem.

The scheme is shown in the figure below.

Boolean operations

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

There are 3 types of such functions:

  1. Odd - if an odd number, then true (on the contrary - false).
  2. Eoln - true at the end of the string (false elsewhere).
  3. Eof is true at the end of the file (false elsewhere).

Program management functions

What other procedures exist?

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

Conclusion

Thus, 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 get acquainted with in computer science lessons. It consists of lessons 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 correctly format its text. Hints and notes help the reader pay attention to important details, avoiding pitfalls and writing programs more efficiently. The book was prepared by computer science teachers at the school, who have many years of experience practical work. The second edition adds several new chapters on records, dynamic variables, stack, queue, and lists. One of the most difficult topics in programming is also covered - the construction of recursive algorithms.

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

Size: 14.5 MB

Watch, download: docs.google.com

Content
Preface to the second edition 15
Introduction 16
From publisher 16
TOPIC 1. How to write a simple program on Pascal 17
Lesson 1.1. Displaying a message on the display screen 18
Lesson 1.2. How to put this program in the computer 19
Stages of creation computer program 20
Lesson 1.3. Formatting text on the screen 28
Findings 34
Security questions 34
TOPIC 2: How to put numbers into action 36
Lesson 2.1. Let's start simple: integers 37
The concept of a variable 38
Integer type. assignment operator. Screen output 38
Operations with type Integer 40
Standard functions of type Integer 42
How Integer Variables Are Represented
in computer memory 43
Lesson 2.2. We put into work real numbers 45
Description of the real data type (real) 45
Recording Formats for Real Variables 46
Real operations 46
Standard functions like real 47
Writing Math Expressions 48
How variables of real type are represented in computer memory 50
Lesson 2.3. How to combine integer and real type variables 51
Type conversion 51
Rules of Priority in Performed Actions 52
Actions on data different types 53
Lesson 2.4. Data input and output 56
Entering variables from the keyboard 57
Beautiful screen output 57
Setting Variable Values ​​with a Random Number Generator 61
Lesson 2.5. Why are constants needed in a program? 62
Findings 64
Security questions 64
TOPIC 3. Learning to work with symbols 66
Lesson 3.1. How a computer understands symbols 67
ASCII code table 67
Char Type Description and Standard Functions 68
Lesson 3.2. The Char type is an ordinal type! 70
Findings 71
Security questions 72
TOPIC 4. George Boole and his logic 73
Lesson 4.1. We need one more type - boolean! 74
Boolean data type (Boolean) 75
Relational Operations 75
Boolean I/O 76
Lesson 4.2. Logical (boolean) operations 76
Logical multiplication (conjunction) 76
Logical addition (disjunction) 77
XOR (modulo 2 addition) 77
Logical negation (inversion) 78
Application logical operations in program 78
Logic Priority 80
Conclusions 81
Security questions 81
TOPIC 5. Analysis of the situation and the sequence of execution of commands 82
Lesson 5.1. Condition Checking and Branching in the Algorithm 83
Complete and incomplete form of the if statement 84
Designing programs 86
Lesson 5.2. Statement blocks 88
Lesson 5.3. Branching on a number of conditions (case statement) 92
Findings 96
Security questions 96
TOPIC 6. Repeated actions 98
Lesson 6.1. Operator for loop 99
for statement with counter incrementing 100 for statement with counter incrementing 101
Lesson 6.2. Using cycles with a counter 101
Cycle within a cycle 102
Trace 103
Calculating the sum of a series 105
Findings 108
Security questions 109
TOPIC 7. Loops with a condition 110
Lesson 7.1. Loop with precondition 111
Loop description 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
Loop description with postcondition 120
Using repeat and while loops 120
Relativity of the choice of while and repeat statements 123
Findings 129
Security questions 129
TOPIC 8. Arrays - structured data type 131
Lesson 8.1. Storing data of the same type 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 element of an array 140
Calculating the sum and number of elements of an array with given properties 144
Lesson 8.2. Array search 148
Determining if an Array Has a Negative Element Using a Flag 148
Determining if an Array Has Negative Elements by Calculating Their Number 149
Finding the number of negative array element 150
Lesson 8.3. 2D arrays 154
Findings 156
Security questions 157
TOPIC 9. Auxiliary algorithms. procedures and functions. Structured programming 1 58
Lesson 9.1. Designing a top-down algorithm 159
Practical task using auxiliary algorithms 160
Lesson 9.2. Example of working with the function: Finding the maximum element 167
Findings 168
Security questions 169
TOPIC 10. How to work with character strings 170
Lesson 10.1. Working with character strings: type String 171
String variable description 171
Basic String Actions 172
Lesson 10.2. Some Pascal functions and procedures for working with strings 173
Using Library String Routines 173
Conclusions 175
Security questions 175
TOPIC 11. Procedures and functions with parameters 176
Lesson 11.1. Simple examples 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. Ways to pass parameters 181
Conclusions 183
Security questions 184
TOPIC 12. Files: saving your work until the next time 185
Lesson 12.1. How to work with text file 186
Opening a file for reading 186
Opening a file for writing 188
Lesson 12.2. Preservation two-dimensional array numbers in text file 192
Saving Numeric Data in a Text File 192
Saving an array of numbers in a text file 192
Appending information to the end of a file 196
Conclusions 197
Security questions 197
Topic 13. Graphic mode of operation. Graph 199 module
Lesson 13.1. Turn on graphical mode 200
Features of working with graphics 200
Switching to the graphics mode of the video adapter 201
Lesson 13.2. We continue to explore the possibilities of the Graph 203 module
Drawing lines using the Graph 203 module
Drawing circles using the Graph 205 module
Conclusions 206
Security questions 207
Topic 14. Operators that change the natural course of the program 208
Lesson 14.1. Using the unconditional jump operator goto 210
Lesson 14.2. Statements that change the flow of a loop 213
break statement 213
continue statement 214
Conclusions 215
Security questions 215
Topic 15. Grouping Data: Records 216
Lesson 15.1. Description of data type record 218
Lesson 15.2. When and how to use records 220 wisely
Creating Your Own Data Type - Entry 220
Record array 220
with 221 append operator
Data Structure Selection Example 223
Entries records 224
Conclusions 225
Control questions and tasks 225
Topic 16. Dynamic variables 226
Lesson 16.1. Memory allocation 227
Lesson 16.2. Addresses 229
Lesson 16.3. Pointers 230
Pointers to individual variables 230
Pointers to blocks of variables 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
Findings 241
Security questions 242
Topic 17. Dynamic data structures. Stack 244
Lesson 17.1. Let's describe the data type 245
Lesson 17.2. Stack creation and basic stack operations 247
Adding an Item to the Stack (Push) 248
Popping an element from the stack (Pop) 251
Checking the stack for emptiness (StacklsEmpty) 252
Lesson 17.3. Stack usage 253
Stack Programming with an Array 255
Conclusions 256
Control questions and tasks 256
Topic 18. Dynamic data structures. Queue 258
Lesson 18.1. Principle of operation and description of the data type 259
Lesson 18.2. Basic Queue Operations 261
Adding an item to the queue (EnQueue) 261
Retrieving an Item from a Queue (DeQueue) 263
Queue check for emptiness (QueuelsEmpty) 264
Lesson 18.3. Using Queue 264
Programming a Queue with an Array 267
Conclusions 269
Security questions 269
Topic 19. Dynamic data structures. Unidirectional list 270
Lesson 19.1. Description of the data type and how it works 271
Lesson 19.2. Basic Operations with a Singly Linked List 272
Sequentially viewing all elements of a list 272
Putting an element into a list 273
Removing an item from a list 275
Lesson 19.3. List Processing 276
Why use a singly-linked list 278
Conclusions 280
Security 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 of a non-recurrent problem 288
Lesson 20.5. An example of a recurrent solution of a recurrent problem 289
Conclusions 291
Security questions 291
Appendix 1 Flowchart Elements 292
Annex 2 Tasks 295
Integer. Description. Input. Conclusion. Operations 296
Real. Description. Input. Conclusion. Operations and functions 296
Real. Writing and evaluating expressions 297
Char. Description. Input. Conclusion. Functions 298
Boolean. Writing expressions 298
Boolean. Expression evaluation 299
if. Simple comparisons. Min/max/average 300
if. Equations and inequalities with 300 parameters
for. Transfers 300
for. Loop Counter Calculations 301
for. Brute force 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. Highs 307
Subroutines without parameters 307
Strings. Part I 308
Strings. 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 contact us more and more often with a request to supplement the first edition with information about the most studied and demanded 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 - building recursive algorithms.
In the application, we decided to abandon the collection of homework with many options for several topics. Instead, we placed 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 exercises when consolidating 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 SPbGUAP, Ph.D. Evgeny Mikhailovich Linsky for support, many useful tips and great help in the work on the second edition of the book.

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 a language for students in grades 7-8. There will be no in-depth consideration (there is relevant literature for this).

Program Structure

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

To write the first program in Pascal, it is enough to know two sections (in fact, there are more of them):

  • variable declaration section - var- this section lists the variable names used in the program separated by commas. The following is their type.
  • program body - starts with a word begin and ends with the word end.(with a dot). This section contains the text of the program itself.
var variables : data type ; begin program body end.

Variables

What is a variable.

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

Memory cells named a, b, c

The variable name must meet the following requirements:

  • consist of letters of the Latin alphabet (a-z, A-Z), numbers and underscore "_";
  • The variable name must not start with a number (but may start with the character "_" ( 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 contain only integers.

There are many other data types, but the first three programs will suffice.

If you want some of the variables to be of the same type and some of the other:

var a, b : integer ; with :real;

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

assignment operator

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

:= assignment operator

Recording a:=23; reads "Variable A assigned a value 23 ". Now in a memory cell named A stored number 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 brackets. In our case, in a variable a.

Mathematical operations

+ - addition operation

- subtraction operation

* - multiplication operation

/ - division operation

mod- remainder of the division

div- integer part of division

Example:

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

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

Output operator

To display the value of a variable on the screen, use the command write(a) or writeln(a). After executing the command writeln there is a transition to newline, after executing the write command - does not happen.

If you want 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(' The value of the variable a = ‘, a);

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

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; //declaring 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.

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

What is a programming language? Any problem that a computer solves is written as a sequence of commands. Such a sequence is called a program. Commands, of course, must be presented in a language understandable to the computer. One such language is the Pascal programming language. It was developed by the Swiss professor Nikolaus Wirth specifically for teaching students how to program. The peculiarities of the language also include its structure. That is, the program is easily divided into simpler, non-intersecting blocks, which, in turn, into even more simple blocks. It also makes programming easier. In 1979, the language was approved as the standard. Wirth named it after the French scientist Blaise Pascal, the 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 concrete examples programs. There are no lengthy theoretical explanations, so it is extremely necessary to carefully read the comments in the texts of the programs!
So, we start the first conversation right away with the first program in Pascal;

Content
Intro 7
Thanks 7
From publisher 8
TOPIC 1. How to write a simple program in Pascal 9
Lesson 1.1. Display message on screen 10
Lesson 1.2. How to put this program in the computer? eleven
Stages of creating a computer program 12
1. Launch Pascal 14 environment
2. Working in the Edit 16 Window
3. Saving the program in a file on disk 19
4. Running the compiler 20
5. Running program 21
6. Viewing the results of the program 21
7. Exit Pascal 22 environment
Lesson 1.3. Formatting text on the screen 22
Findings 28
Security questions 28
TOPIC 2. How to put numerical data to work 30
Lesson 2.1. Let's start simple: integers 31
The concept of a variable 32
Integer type. assignment operator. Screen output 32
Operations with type Integer 34
Standard functions of type Integer 36
How integer type variables are represented in computer memory 38
Lesson 2.2. Putting real numbers into action 39
Description of the real data type (Real) 40
Recording Formats for Real Variables 40
Real operations 41
Standard functions of type Real 41
Writing Math Expressions 43
How real variables are represented in memory
computer 45
Lesson 2.3. How to Combine Integer and Real Type Variables 46
Type conversion 46
Rules of Priority in Performed Actions 47
Actions on different types of data 47
Lesson 2.4. Data input and output 51
Entering variables from the keyboard 52
Beautiful screen output 52
Setting Variable Values ​​with a Random Number Generator 55
Lesson 2.5. Why are constants needed in a program? 57
Findings 59
Security questions 60
TOPIC 3. Learning to work with symbols 61
Lesson 3.1. How a computer understands symbols 62
ASCII code table 62
Char Type Description and Standard Functions 63
Lesson 3.2. The Char type is an ordinal type! 64
Findings 66
Security questions 67
TOPIC 4. George Boole and his logic 68
Lesson 4.1. We need one more type - boolean! 69
Boolean data type (Boolean) 70
Relationship Operations 70
Boolean I/O 71
Lesson 4.2. Logical (boolean) operations 71
Logical multiplication (conjunction) 72
Logical addition (disjunction) 72
XOR (modulo 2 addition) 73
Logical negation (inversion) 74
Application of logical operations in the program 74
Logic Priority 76
Findings 77
Security questions 78
TOPIC 5. Analysis of the situation and the sequence of execution of commands 79
Lesson 5.1. Condition Checking and Branching in Algorithm 80
Complete and incomplete form of the if statement 81
Designing programs 84
Lesson 5.2. Statement blocks 85
Lesson 5.3. Branching on a number of conditions (case statement) 90
Findings 94
Security questions 95
TOPIC 6. Repeated actions 96
Lesson 6.1. loop-statement for 97
for statement with incremental counter 97
for statement with sequential decrement of counter 99
Lesson 6.2. Using cycles with counter 99
Cycle in cycle 100
Trace 101
Calculating the sum of a series 103
Findings 107
Security questions 108
TOPIC 7. Loops with a condition 109
Lesson 7.1. Loop with precondition 110
Loop description with precondition 110
Approximate calculation of the sum of an infinite series 111
Entering a Number to a Specified Integer Power 114
Lesson 7.2. Loop with postcondition 118
Loop description with postcondition 119
Using repeat and while loops 119
Relativity of the choice of while and repeat statements 123
Findings 129
Security questions 129
TOPIC 8. Arrays - structured data type 131
Lesson 8.1. Storing data of the same type 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 element of an array 141
Calculating the sum and number of array elements with given properties 146
Lesson 8.2. Array search 148
Determining if an Array Has a Negative Element Using a Flag 149
Determining if an array contains negative elements by calculating their number 150
Finding the Number of the Negative Element in an Array 152
Lesson 8.3. 2D arrays 156
Findings 158
Security 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. Example of working with a function: finding the maximum element 169
Findings 171
Security 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 string variable 173
Basic String Actions 174
Lesson 10.2. Some Pascal functions and procedures for working with strings 175
Using Library String Routines 175
Findings 177
Security questions 178
TOPIC 11. Procedures and functions with parameters 179
Lesson 11.1. Simple Examples of Using Subroutines with Parameters 180
The simplest procedures with parameters 180
Formal and actual parameters 182
The simplest functions with parameters 183
Lesson 11.2. Ways to pass parameters 184
Conclusions 187
Security questions 187
TOPIC 12. Files: saving your work until the 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. Saving a two-dimensional array of numbers in a text file 196
Saving Numeric Data in 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
Security questions 203
TOPIC 13. Graphic mode of operation. Graph 204 module
Lesson 13.1. Turn on graphical mode 205
Features of working with graphics 205
Switching to the graphics mode of the video adapter 206
Lesson 13.2. We continue to explore the possibilities of the Graph 208 module
Drawing lines using the Graph 209 module
Drawing circles using the Graph 210 module
Conclusions 212
Security questions 212
TOPIC 14. Operators that change the natural course of the program 213
Lesson 14.1. Using the unconditional jump operator goto 215
Lesson 14.2. Statements that change the flow of a loop 218
break statement 2.19
continue statement 220
Conclusions 220
Security questions 221
Appendix 1 Flowchart Elements 222
Annex 2. Homework 224
Tasks for chapter 2 224
Tasks for chapter 4 227
Assignments for chapters 6-7 229
Tasks for chapter 8 236
Alphabetical index 254