Contacts

Programming languageABC Pascal presentation for a lesson on computer science and ICT on the topic. Presentation on the topic "Pascal ABC programming environment" a). The value of x is known. Calculate y if

Programming in Pascal



In 1970, at least two great events occurred in the world of programming: operating system UNIX and a new programming language created by Professor Niklaus Wirth from the Swiss Federal Institute of Technology in Zurich. Wirth named it in honor of the great 17th century French mathematician and philosopher Blaise Pascal.

Niklaus Wirth

Blaise Pascal


Pascal language convenient for initial programming training, not only

because it teaches how to write a program correctly, but also how to correctly

develop methods for solving programming problems


  • uppercase and lowercase letters of the Latin alphabet from A to z, as well as the underscore (_), which also counts as a letter.
  • Uppercase and lowercase letters are interchangeable (equal meaning);
  • Arabic numerals 0 1 2 3 4 5 6 7 8 9 ;
  • special single characters: + – * / = . , : ; ^ $ # @ ;
  • special paired signs: () { } ;
  • compound signs: = .. (* *) (..) .

Program structure

The Pascal program consists of:

// Heading (optional part)


  • Description of marks;
  • Definition of constants;
  • Definition of types;
  • Description of variables;
  • Description of procedures and functions.

  • begin { start of the program }
  • { program body }
  • end. { end of program }

Program structure

Program program name; ( program title }

Uses …; (module connection section)

Label; { tag description section }

Const; { constant description section }

Toure; { type definition section }

Var; { variable description section }

Function; Procedure; { section describing functions and procedures }

... { operators section }


What does the program consist of?

Constant – a constant quantity that has a name.

Variable – a changing quantity that has a name (memory cell).

Procedure – an auxiliary algorithm that describes some actions (drawing a circle).

Function – an auxiliary algorithm for performing calculations (calculating the square root, sin) .


Constants

i2 = 45; { integer }

pi = 3.14; { real number }

q = " Vasya "; { character string }

L = True; { logical value }

the integer and fractional parts are separated by a dot

You can use Russian letters!

can take two meanings:

  • True (true, “yes”) False (false, “no”)
  • True (truth, “yes”)
  • False (false, “no”)

Variables

Variable types:

  • integer ( whole ) real ( real ) char ( one character ) string ( character string ) boolean ( logical }
  • integer ( whole }
  • real ( real }
  • char( one character }
  • string ( character string }
  • boolean ( logical }

Declaring Variables ( memory allocation ) :

variable– variable

type - integers

var a, b, c: integer ;

list of variable names


Example program

write(‘ This is my first program ! ’);

Run the program and view the result.


Inference operator

Write(‘ text ’); - operator for displaying text and variables on the screen (leaves the cursor on the current line);

Writeln(‘ text ’); - operator for displaying text and variables on the screen (moves the cursor to a new line);


Exercise

  • Display the following text on the screen:

Hi all!

I am the best programmer at SSH No. 3!

Please note that the text is displayed on two different lines.



Calculate mathematical expressions in ABC Pascal


  • Priority of operations in ABC Pascal the same as in mathematics.
  • You just need to learn how to correctly write mathematical expressions in the language Pascal

Arithmetic operations

Operation

Name

Addition

Subtraction

Multiplication

Division (real type only)

A div B

Calculation of the integer part (incomplete quotient)

Calculating the remainder

Calculate:

10 div 3 18 mod 4


Examples

Mathematical recording

Recording in language Pascal

37(25+87,5)-17(4,6+1,9)

37*(25+87.5)-17*(4.6+1.9)

(a +2* b-3*c)/(5*a+4)

(a+b)/(a-b)+a*b/3.14

Decimal point in Pascal denoted by a dot


Standard Features

Pascal's function

Mathematical notation

Name

Absolute value of the number X (modulus)

Squaring a number

Exhibitor

Calculating the square root

Calculates the fractional part of a number

Rounds to the nearest whole number

Cuts off the fractional part

Define result:

Frac(16.68); Round(16.68); Trunc(16.68);


Standard Features

Pascal's function

Mathematical notation

Name

Sine calculation

Cosine calculation

The integer part of number

Calculating the natural logarithm

Raising a number to a power

Returns a random number in the range from 0 to X

Number π


Degrees in Pascal need to be converted to radians

Recording in language Pascal

Mathematical notation


PL Operators Pascal ABC


:= expression; An arithmetic expression can include constants variable names arithmetic operations signs: constants variable names arithmetic operations signs: + - * / div mod + - * / div mod function calls parentheses () function calls parentheses () division integer multiplication remainder of division division" width="640"

Assignment operator

variable name := expression ;

An arithmetic expression may include

  • constants names of variables signs of arithmetic operations:
  • constants
  • variable names
  • signs of arithmetic operations:

+ - * / div mod

  • + - * / div mod
  • function calls parentheses ()
  • function calls
  • round brackets ()

complete division

multiplication

remainder of the division


Which operators are incorrect?

program qq;

var a, b: integer;

x, y: real;

10 := x;

y:= 7 , 8;

b:= 2.5;

x:= 2*(a + y);

a:= b + x;

the variable name must be to the left of the sign :=

the integer and fractional parts are separated dot

You cannot write a real value to an integer variable


Input operator

read(a); { entering a variable value a)

read(a, b); { entering variable values a And b)

How to enter two numbers?

separated by space:

through Enter :


Inference operator

write(a); { output variable value a)

write ln (a); { output variable value a And move to new line }

writeln(" Hello! "); { text output }

writeln(" Answer: ", c); { output text and variable value c)

writeln(a, "+", b, "=", c);


Adding two numbers

Task. Enter two integers and display their sum.

The simplest solution:

program qq;

var a, b, c: integer;

read(a, b);

c:= a + b;

writeln(c);


Complete solution

program qq;

var a, b, c: integer;

writeln(" Enter two integers ");

read(a, b);

c:= a + b;

writeln(a, "+", b, "=", c);

computer

Protocol :

Enter two integers

25+30=55

user



CALCULATE:

12 div 4 =

1 9 div 5 =

12 mod 3 =

1 36 mod 10 =


On Pascal

In the language of mathematics

Modulus of number x

Squaring x

Trunc(x)

e X

Round(x)

Fractional part calculation

Square root of x

Rounds to the nearest whole number

Random(x)

Cuts off the fractional part

Sine x

Exp/y*ln(x))

Returns a random number from 0 to x

Cosine x

[ X ]

X at

Ln x


Homework

1. Calculate the circumference and area of ​​a circle at a given radius

2. Calculate the perimeter of a right triangle from its legs




Conditional operator ( full form )

full form of branching

condition

Action1

Action2

conclusion


then begin (what to do if the condition is true) end else begin (what to do if the condition is false) end; Features: a semicolon is NOT placed before else begin and end a semicolon is NOT placed before else if there is one statement in the block, you can remove the words begin and end" width="640"

Conditional operator (long form)

if condition then begin

{ }

else begin

{ what to do if the condition is false }

Peculiarities:

  • before else NOT put a semicolon if there is one statement in the block, you can remove the words begin And end
  • before else NOT a semicolon is added
  • if there is one statement in the block, you can remove the words begin And end

Conditional operator (not full form )

incomplete branching form

condition

Action

conclusion


then begin (what to do if the condition is true) end; Features: if there is one statement in the block, you can remove the words begin and end; if there is one statement in the block, you can remove the words begin and end" width="640"

Conditional operator (incomplete form)

if condition then begin

{ what to do if the condition is true }

Peculiarities:

  • if there is one statement in the block, you can remove the words begin And end
  • if there is one statement in the block, you can remove the words begin And end


Homework

  • Write a program that decreases the first number by a factor of five if it is greater than the second.

2. Write a program in which the value of the variable With calculated by the formula: a+b , If A odd And a*b , If A even .



b then c:= a + b else c:= b – a;" width="640"

Homework

1. Write a program to solve the problem:

A). The value of x is known. Calculate y if

b). The coordinates of the point are given. Find out whether this point lies in the 3rd coordinate quadrant?

2. Determine the value of the variable c after executing the following program fragment:

a:= 6 ;

b:= 15 ;

a:= b – a*2;

if a b then

c:= a + b

else c:= b – a;




Cycle - This is the repeated execution of the same sequence of actions.

  • cycle with famous number of steps ( loop with parameter ) cycle with unknown number of steps ( loop with condition )
  • cycle with famous number of steps ( loop with parameter )
  • cycle with unknown number of steps ( loop with condition )



:= start value to end value do begin (loop body) end; Decreasing a variable by 1 (step -1): for variable:= initial value downto final value do begin (loop body) end;" width="640"

Increment a variable by 1 (step 1):

for variable := initial value to

final value do begin

{ loop body }

Decreasing a variable by 1 (step 1) :

for variable := initial value downto

final value do begin

{ loop body }


Peculiarities:

  • integer ) to ) or -1 ( downto ) begin And end you don't have to write: to ) is never executed (
  • loop variable can only be whole ( integer )
  • the loop variable change step is always 1 ( to ) or -1 ( downto )
  • if there is only one statement in the body of the loop, the words begin And end you don't have to write:
  • if the final value is less than the initial value, loop ( to ) is never executed ( checking the condition at the beginning of the loop, loop with precondition)

for i:= 1 to 8 do

writeln( " Hello " );


  • It is not allowed to change a loop variable in the body of a loop
  • when changing the start and end values ​​inside the loop, the number of steps will not change:

for i:= 1 to n do begin

writeln( " Hello " );

n:= n + 1;

no looping




do begin (loop body) end; Features: you can use complex conditions: if there is only one operator in the body of the loop, the words begin and end need not be written: you can use complex conditions: if there is only one operator in the body of the loop, the words begin and end need not be written: while (a d o begin ( body loop ) end; while a d o a:= a + 1;" width="640"

while condition do begin

{ loop body }

Peculiarities:

  • you can use complex conditions: if there is only one operator in the loop body, the words begin And end you don't have to write:
  • You can use complex conditions:
  • if there is only one statement in the body of the loop, the words begin And end you don't have to write:

while (a d o begin

{ loop body }

while a d o

a:= a + 1;


b d o a:= a – b; a:= 4; b:= 6; while a d o d:= a + b;" width="640"
  • the condition is recalculated each time the loop is entered
  • if the condition at the entrance to the loop is false, the loop is never executed
  • if the condition never becomes false, the program loops

a:= 4; b:= 6;

while a b d o

a:= a – b;

a:= 4; b:= 6;

while a d o

d:= a + b;




until condition " width="640"

Loop with postcondition is a loop in which a condition test is performed at the end of the loop.

loop body

until condition


TASK

Find the sum of the squares of all natural numbers from 1 to 100. Let's solve this problem using all three types of loops.


"Bye" .

Program qq;

var a, s: integer;

s:=s+a*a;

writeln(s);


100 ; writeln(s); end." width="640"

"Before"

Program qq;

var a, s: integer;

s:=s+a*a;

until a 100 ;

writeln(s);


"With parameter"

Program qq;

var a, s: integer;

for a:=1 to 100 do

s:=s+a*a;

writeln(s);


Task.

Display squares and cubes of integers from 1 to 8.

Peculiarity:

The same actions are performed 8 times.


"cycle" block

i 1 := i * i;

i 2 := i 1 * i;

loop body

i, i 1 , i 2


Program

program qq;

var i, i1, i2: integer;

for i:=1 to 8 do begin

i1:= i*i;

i2:= i1*i;

writeln(i, i1, i2);

initial value

variable

final value


Loop with decreasing variable

Task. Display squares and cubes of integers from 8 to 1 (in reverse order).

Peculiarity: the loop variable should decrease.

Solution:

for i:=8 1 do begin

i1:= i*i;

i2:= i1*i;

writeln(i, i1, i2);

down to




Array – this is a group of elements of the same type that have a common name and are located nearby in memory.

Peculiarities:

  • all elements are of the same type the entire array has the same name
  • all elements are of the same type
  • the entire array has the same name
  • all elements are located nearby in memory

Examples:

  • list of students in class apartments in a house schools in the city
  • list of students in class
  • apartments in a house
  • schools in the city
  • annual air temperature data

NUMBER array element

(INDEX)

array

MEANING array element

NUMBER (INDEX) array elements: 2

MEANING array elements: 10


Declaring Arrays

Why announce?

  • define Name array define type array define number of elements highlight place in memory
  • define Name array
  • define type array
  • define number of elements
  • highlight place in memory

Array of integers:

Size via constant:

elements

ending index

starting index

var A : array[ 1 .. 5 ] of integer ;

var A: array of integer ;

const N=5;


What is wrong?

var a: array of integer;

A := 4.5;

var a: array ["z".."a"] of integer;

A["B"] := 15;

["a".."z"]

var a: array of integer;

A := "X";


Announcement:

Keyboard input:

Element-wise operations:

Output on display:

const N = 5;

var a: array of integer;

i: integer;

a =

a =

a =

a =

a =

for i:=1 to N do begin

write("a[", i, "]=");

read(a[i]);

Why write ?

for i:=1 to N do a[i]:=a[i]*2;

writeln(" Array A:");

for i:=1 to N do write(a[i]:4);

Array A:

1 0 24 68 112 26


Task:

1. Enter c keyboard array of 5 elements, find the arithmetic mean of all elements of the array.

Example:

Enter five numbers:

4 15 3 10 14

arithmetic average 9.200

SOLUTION:


Program qq;

var N: array of integer;

for i:=1 to 5 do begin

write("N[",i,"]");

for i:=1 to 5 do begin

write(" average", k:6:2);


Niklaus Wirth In the early 70s of the 20th century, the Swiss scientist Niklaus Wirth developed a programming language and gave it the name Pascal, in honor of the famous French mathematician of the 17th century, inventor of the first calculating machine, Blaise Pascal. Using Pascal, you can develop programs for a wide variety of purposes. The syntax of this language is intuitive even for those who are just starting to learn the basics of programming.




The alphabet of the language is the uppercase and lowercase letters of the Latin alphabet from A to z, as well as the underscore character (_), which is also considered a letter. Uppercase and lowercase letters are interchangeable (equal meaning); Arabic numerals; special single characters: + – * / =., : ; ^ $ special paired characters: () ( ) ; compound signs: =.. (* *) (..).








Program structure Program NameProgram; (program title) Uses ...; (module connection section) Label ...; (label description section) Const ...; (constant description section) Ture...; (type definition section) Var ...; (variable description section) Function...; Procedure...; (section of descriptions of functions and procedures) BEGIN... (section of statements) END.











Arithmetic operations If you write in the program: Writeln(3+8); Then after executing the program, the message 3+8 will appear in the execution screen. If you write: Writeln(3+8); //without apostrophes Then after executing the program, the inscription 11 will appear in the execution screen, i.e. Pascal will do the calculation itself. Try to calculate the expression: 185(14+16)

To use presentation previews, create an account for yourself ( account) Google and log in: https://accounts.google.com


Slide captions:

ABC Pascal programming language grade 9

Programming language This is a formal sign system (set of commands) that a computer understands. The alphabet of a language is the set of symbols used in this language.

In the early 70s of the 20th century, the Swiss scientist Niklaus Wirth developed a programming language and gave it the name Pascal, in honor of the famous French mathematician of the 17th century, inventor of the first calculating machine, Blaise Pascal. Using Pascal, you can develop programs for a wide variety of purposes. The syntax of this language is intuitive even for those who are just starting to learn the basics of programming.

The Pascal language is convenient for initial learning of programming, not only because it teaches you how to write a program correctly, but also how to correctly develop methods for solving programming problems

The alphabet of the language is the uppercase and lowercase letters of the Latin alphabet from A to z, as well as the underscore character (_), which is also considered a letter. Uppercase and lowercase letters are interchangeable (equal meaning); Arabic numerals 0 1 2 3 4 5 6 7 8 9 ; special single characters: + – * / = . , : ; ^$#@; special paired characters: () ( ) ; compound signs: = .. (* *) (..) .

Program structure A Pascal program consists of: // Heading (optional part) // Description block // Program body

Description block Description of tags; Definition of constants; Definition of types; Description of variables; Description of procedures and functions.

Program body Begin………… (program body, list of commands) End.

Program structure Program NameProgram ; (program title) Uses...; (module connection section) Label... ; (label description section) Const...; (constant description section) Type...; (type definition section) Var...; (variable description section) Function...; Procedure... ; (section of descriptions of functions and procedures) BEGIN... (section of operators) END.

Explanations In explanations you can use Russian letters (may be in curly braces) // can be written after two slashes

Output statement Write(‘ text ’); - operator for displaying text and variables on the screen (leaves the cursor on the current line); Writeln(‘text’); - operator for displaying text and variables on the screen (moves the cursor to a new line);

Compilation (F9) Eliminate errors in the program.

Example program Begin write(‘ This is my first program! ’); End. Compile and run the program and view the result.

Program Result of execution Stopping program execution

Task 001 Display the following text on the screen: Hello everyone! I am the best programmer at SSH No. 3! Please note that the text is displayed on two different lines.

Arithmetic operations If you write in the program: Writeln(‘3+8’); Then after executing the program, the message 3+8 will appear in the execution screen. If you write: Writeln(3+8); // without apostrophes Then after executing the program, the inscription 11 will appear in the execution screen, i.e. Pascal will do the calculation itself. Try to calculate the expression: 185(14+16)


Slide 1

Slide 2

Lesson 1. My first program Our first program will be a greeting program. It will simply display the text on the computer screen and complete its work. We will also look at the basic rules for designing a program. program First; begin write("Hello,"); writeln("friends!"); writeln("This is the second line") end. The first line is the program title. Program is a service word; First is the name of our program, you can come up with it yourself. At the end of the line there is ";" When listing Pascal instructions, you need to put “;” between them. . Next comes the body of the program. It always begins with the word begin. There is no ";" at the end of the line. The following command or statement displays the word HELLO on the screen; The output text is always enclosed in apostrophes. (" "). This operator displays the word FRIENDS on the screen! and moves the cursor to the next line. Because The "ln" characters in the writeln statement mean "line" - a line. Here at the end of the line ";" is not required, because This is the last operator (you don’t have to put “;” before end). End – ends the body of the program and there must be a period at the end. As a result of executing the program we get

Slide 3

How to install a program on a computer? First, let's look at the stages that the user (programmer) must go through in order to see the correct results of the program on the screen.

Slide 4

Scheme of the stages of creating a program on a computer. start Edit Error? Compile Error? Build Error? Run Error? End Yes Yes Yes Yes No No No No

Slide 5

Run the Pascal ABC program from the icon on the desktop Main menu Go to - F10 Edit window Go from the main menu - Alt Output window Start to execute the program - F9

Slide 6

Type your first program in the editing window and launch it with the F9 button. program First; begin write("Hello, "); writeln("friends!"); writeln("This is the second line") end. The processes of compiling and launching a program for execution can be combined by calling the Run (F9) command immediately after typing the program text. Exiting the program is done using the Exit command in the File menu. Task 1. Write a program that displays the text on the screen: Important Do not confuse Write and Writeln! Let's check.

Slide 7

Task 2. Write a program that displays the phrase “Hello everyone!” 20 times - in a table of 5 rows by 4 columns. Clue. Use multiple spaces to set space between columns. Write only one write statement first? Which will display one phrase (don't forget about spaces). Then copy it 4 more times to get the whole line. At the end, don't forget to add a break to the next line (writeln). No need to copy begin and end! Let's check.

1 slide

PASKAL Belyakova Natalya Aleksandrovna Teacher of computer science, technology and fine arts, MBOU secondary school No. 6, Kholmsk, Sakhalin region Pascal ABC

2 slide

3 slide

Data Type REAL If a number has a comma and is a fraction, then it is called REAL. To store real numbers, Pascal uses a special data type – REAL. To enter them into the program, use the VAR (variable) operator EXAMPLE: program p15 ; VAR a, b, c: REAL ; Begin and stuff……….

4 slide

REAL variables: program summa ; VAR A, B, C: REAL ; Begin A:= 3.5; B:= 7.6; C:=A + B; writeln("sum = ", c) ; End. _______________________________________ All real numbers are written not with a comma, but with a dot!!!

5 slide

Formats for writing real variables: Normal form: 0.7 can be written as 0.7 or .7 -2.1 can be written as -2.1 Notation with exponent: A number is represented as the mantissa (the fractional part of the number) multiplied by 10 to some power 2700 = 2.7*10 The number 10 is written as the letter E, followed by the power: 2.7E3 0.002 = 2*10 The number 10 is written as the letter E, followed by the power: 2E-3 3 - 3

6 slide

REAL variables: program z16 ; var a, b, c: real; begin a:= 17.3; b:= 3.4; c:=a+b; writeln("addition A+B = ", c); c:=a-b; writeln("subtract A-B = ", c); c:=a*b; writeln("multiply A*B = ", c); c:=a/b; writeln("division A/B = ", c); End.

7 slide

REAL type functions: PROGRAM Z18 ; VAR A, B: REAL; BEGIN A:= 2.0 ; (square root calculation) B:= SQRT(A); WRITELN (Square root (Sqrt (A)) = ", B) ; (sine calculation) B:= SIN (A); WRITELN ('sine of number (SIN (A) = ", B) ; (cosine calculation) B: = COS(A); WRITELN('cosine number(COS(A) = ", B) ;

8 slide

(calculate arctangent) B:= ARCTAN (A); WRITELN (arctangent of the number (Arctan (A)) = ", B) ; (calculation of the logarithm) B:= LN (A); WRITELN ('logarithm of the number (LN (A) = ", B) ; (raising the number E to the power A) B:= EXP (A); WRITELN ('exponent to the power of A (EXP (A) = ", B) ; (calculation of Pi) B:= PI; WRITELN ('Pi number (Pi) = ", B ) ; End.

Slide 9

(calculate arctangent) B:= ARCTAN (A); WRITELN ('arctangent of the number (Arctan (A)) = ", B); _______________________________ The output of a real number can be specified. For the value of the variable “B” we set 6 digits, of which 4 are after the decimal point: (calculation of the arctangent) B:= ARCTAN (A ); WRITELN ('arc tangent of number (Arctan (A)) = ", B: 6: 4) ; _______________________________

10 slide

The main operators of the system: Program name program Beginning and End Begin and End. Variables VAR Integer integer Real number real Output to the screen Write(‘x= ‘, x) Output to the screen with new line Writeln('x= ', x) Modulus of the number Abs (x) Squaring Sqr(x) Square root of the number Sqrt(x) Sine of the number Sin (x) Cosine of the number Cos (x) Arctangent of the number Arctan(x) Logarithm of the number Ln (x) Raising a number to the power of X Exp (x) Calculating the number Pi Pi

11 slide

TASK: z15) Assuming that the operation of multiplication and the operation of squaring have the same complexity, write the optimal expression: Z15a) Z15b) Z15c) Z15d) Z15e) Z16) Type a problem on basic arithmetic operations (sample in notebook) Z17) Calculate the expression : Z18) Write a problem for calculating standard functions of the number d:=8 (modulus, square root, square of a number, sine, cosine, tangent, arctangent, cotangent, logarithm of a number) Z19) Write a program to calculate the discriminant of a quadratic equation. Set the coefficients in the program using the assignment operator Z20) Calculate the expression:

12 slide

Z21) Given the diameter of the circle d. Find its length () Z22) Given the length of the edges of the cube, a, b, c of the rectangular parallelepiped. Find its volume and surface area Z23) Find the circumference L and area of ​​a circle S of a given radius R: L=2πR, S = πR Z24) Given 2 numbers a and b. Find their arithmetic mean Z25) Given 2 non-negative numbers a and b. Find their geometric mean (square root of their product) Z26) Find the distance between two points with given coordinates x1 and x2 on the number axis: |x2 - x1|. 2

Slide 13

Literature: M. E. Abrahamyan. Programming Taskbook. Electronic problem book on programming. Version 4.6./ Rostov-on-Don - 2007 2. Ushakov D.M., Yurkova T.A. Pascal for schoolchildren. St. Petersburg: Peter, 2010. - 256 p.

Did you like the article? Share it