Read Microsoft PowerPoint - lecture7.ppt text version

µ 2003

. ,

µµ µµµ µ µµ

µµ µµµ µ µ µµ. µµ µ . µ µµ µ µ . µ µµ :

µ µ µ µ µ µ µ µ

µµ µ µ µ µµ begin end. µµ µ µ µµ. Pascal µ 2 µµ, (procedure) (function).

. . , 2003

2

1

µµ

µµ

µ µ () µ µµ, () µ µ .

µµ

µ µ µµ, µ, µµ µµ µµ

µµ

µ µ µµ µ µµ ( µµ µµ µµ) µµ µ µµ µµ µ µµ (µ )

. . , 2003 3

µµ µµ Pascal µµ Pascal 3 µ:

Program Onoma (input, output); const var procedure function begin µµ end.

. . , 2003 4

µµ

2

µ µ µ µ µ µ µ. µ µ µµ begin end. µ, µ µ µµ. µ µ µ begin.

. . , 2003 5

µ

µ µ 5

procedure DISPLAY_MENU; begin writeln(output, 'Menu choices are'); writeln(output, ' 1: Edit text file'); writeln(output, ' 2: Load text file'); writeln(output, ' 3: Save text file'); writeln(output, ' 4: Copy text file'); writeln(output, ' 5: Print text file') end;

µ DISPLAY_MENU, µ writeln .

. . , 2003

6

3

µ

program PROC1 (output); procedure DISPLAY_MENU; begin writeln(output, 'Menu choices are'); writeln(output, ' 1: Edit text file'); writeln(output, ' 2: Load text file'); writeln(output, ' 3: Save text file'); writeln(output, ' 4: Copy text file`); writeln(output, ' 5: Print text file') end; begin writeln(output, 'About to call the procedure'); DISPLAY_MENU; writeln(output, 'Now back from the procedure') end.

. . , 2003

7

µ () µµ µ :

About to call the procedure Menu choices are 1: Edit text file 2: Load text file 3: Save text file 4: Copy text file 5: Print text file Now back from the procedure

. . , 2003

8

4

µ: µ

program Calculator1 (input, output); { 2 µ µ , µ µ} var x1, x2, apotelesma: real; praxh: char; adynato: boolean; procedure PROSTHESE; begin apotelesma := x1 + x2 end; procedure AFAIRESE; begin apotelesma := x1 - x2; end; procedure POLLAPLASIASE; begin apotelesma := x1 * x2 end; procedure DIAIRESE; begin { µ 0} if x2 <> 0 then apotelesma := x1 / x2 else adynato := true end;

. . , 2003

9

(...)

begin adynato:= false; { µ } writeln(output, 'EISAGETE: telesti x1 x2'); readln(input, praxh, x1, x2); case praxh of '+' : PROSTHESE; '-' : AFAIRESE; '*' : POLLAPLASIASE; '/' : DIAIRESE; else writeln(output, 'LA8OS EISAGVGH DEDOMENVN'); end {case}; if adynato = true then writeln(outpu, 'ADYNATH DIAIRESH') else writeln(output, x1:5:2, ' ', praxh, ' ', x2:5:2, ' = ', apotelesma) end. {Calculator1}

. . , 2003

10

5

µ µ µ µ µ µ µ , µ . µ µ µ begin end .

. . , 2003 11

µ: µ µ

µµ µ µ.

program TOPIKES_METABLHTES (input, output); var number1, number2 : integer; { µ} procedure add_numbers; var result : integer; { µ} begin result := number1 + number2; writeln(output,'TO APOTELESMA EINAI ',result) end; begin { µµ} writeln(output, 'DOSTE 2 PROS8ETEOYS '); readln(input, number1, number2 ); add_numbers end.

. . , 2003

12

6

µ µ

µ µ µ (. µ) µ

µ µ µ µ µ µ µ µ

µ µ ( µ)

µ µ µ µ ( µ) µ µ ( µ) µ

. . , 2003

13

µ: µ µ 2

program ATHROISMA (input, output); var number1, number2: integer;

procedure YPOLOGISMOS_ATHROISMATOS(first, second:integer); var result: integer; begin result := first + second; writeln(output, 'TO APOTELESMA EINAI ', result ) end; begin writeln(output, 'DOSTE 2 ARI8MOYS'); readln(input, number1, number2 ); YPOLOGISMOS_ATHROISMATOS(number1, number2) end.

. . , 2003

14

7

µ µ

µµ µ µ µ (µ) µ µ µ procedure athroisma (m: integer; var athr:integer); µ (formal) µ

µ µ athroisma (3, sum); µ µ (actual) µ µ µ µ µ µ µ!

. . , 2003 15

µ µ

µ (local) µ µ µ µ µ µ

µ µ

µ µ µ µ

µµ µ µ, µ

µ µ µ µ µ µ

. . , 2003 16

8

µ: µ µ µ µ

program Calculator2(input, output); var x1, x2: real; praxh: char; procedure PROSTHESE (x, y : real ); var z : real; begin z := x + y; writeln(output, x:4:2, ' + ', y:4:2, ' = ', z:5:2) end; . . . procedure DIAIRESE (x, y : real ); var z : real; begin if y <> 0 then begin z := x / y; writeln(output, x:4:2,' / ',y:4:2,' = ', z:5:2) end else writeln(output,'ADYNATH DIAIRESH') end; . . , 2003

17

...

begin writeln(output, 'EISAGETE: telesti x1 x2'); readln(input, praxh, x1, x2); case praxh of '+' : PROSTHESE (x1, x2); '-' : AFAIRESE (x1, x2); '*' : POLLAPLASIASE (x1, x2); '/' : DIAIRESE (x1, x2); else writeln(output, 'LA8OS EISAGVGH DEDOMENVN'); end {case}; end. {Calculator2}

. . , 2003 18

9

µ µ

µ µ µ µ µ µ µ

«µ» µ µ µ µ, µ µ µµ var. µ, µ µ µ µ ( ).

µ:

procedure synolikes_krathseis( var kratiseis, foros: real; akatharista:real); kratiseis, foros µ µ akatharista µ µ

µ µ µ µ µ µ

µ µµ µµ

µ µ µ

µ µ µ µ µ µ µ ' µ

. . , 2003

19

µ:

program PARAMETROI_METABLHTHS (output); var number1, number2 : integer; procedure ANTALLAXE ( var value1, value2 : integer ); var temp : integer; begin temp := value1; value1 := value2; value2 := temp end; begin number1 := 10; number2 := 33; writeln(output, 'Number1=', number1, ' Number2=', number2 ); ANTALLAXE( number1, number2 ); writeln( output, 'Number1=', number1, ' Number2=', number2 ) end.

µµ :

Number1 = 10 Number2 = 33 Number1 = 33 Number2 = 10

. . , 2003

20

10

µ µ µ µ µ µ µ µµ

: Number1 = 10 Number2 = 33 Number1 = 10 Number2 = 33

. µ µ number1 number2 !!!

. . , 2003

21

µ: µ µ µ µ

program Calculator3(input, output); var x1, x2, apotelesma: real; praxh: char; adynato: boolean; procedure PROSTHESE (x, y : real; var z: real ); begin z := x + y end; . . . procedure DIAIRESE (x, y : real; var z: real; var adyn_diair: boolean ); begin if y <> 0 then begin z := x / y; adyn_diair := false end else adyn_diair := true end;

. . , 2003

22

11

...

begin writeln(output, 'EISAGETE: telesti x1 x2'); readln(input, praxh, x1, x2); case praxh of '+' : PROSTHESE (x1, x2, apotelesma); '-' : AFAIRESE (x1, x2, apotelesma); '*' : POLLAPLASIASE (x1, x2, apotelesma); '/' : DIAIRESE (x1, x2, apotelesma, adynato); else writeln(output, 'LA8OS EISAGVGH DEDOMENVN'); end {case}; if adynato = true then writeln(output, 'ADYNATH DIAIARESH') else writeln(output, x1, ' ', praxh, ' ', x2, ' = ', apotelesma); end. {Calculator3}

. . , 2003 23

µ µ

(µ) µ µ µ µ µ µ µ µµ µ µ µ µµ µ µ µ, µ µ µµ µ µ . µµ, µ

. . , 2003

24

12

µ

µ µ µ µ

µ µ µ µ Pascal µ µ µ µµ µ , µ

function power(basi, ekthetis: integer): real;

µ µ µ µ µµ Pascal

Abs(x), Sin(x), Sqr(x), Sqrt(x), ...

. . , 2003 25

µ: µ

program test_function (input, output); var pl: integer; function tetragwno (plevra:integer): integer; begin tetragwno:=plevra*plevra; end; begin writeln(output, 'DOSE 0 GIA TELOS'); write(output, 'DOSE PLEYRA TETRAGWNOY = '); readln(pl); while pl > 0 do begin writeln(output, 'EMBADON = ', tetragwno(pl)); write(output, 'DOSE PLEYRA TETRAGWNOY = '); readln(pl); end; end.

. . , 2003 26

13

µ

function DISECTO (ETOS: integer):boolean; { ETOS } begin DISECTO:= (ETOS mod 4 = 0) and ( (ETOS mod 100 <> 0) or (ETOS mod 400 = 0) ); end; function PLITHOS_HMERWN_MHNOS(MHNAS, ETOS: integer): integer; { µ MHNAS ETOS} begin case MHNAS of 1, 3, 5, 7, 8, 10, 12: PLITHOS_HMERWN_MHNOS : = 31; 2: if DISECTO (ETOS) then PLITHOS_HMERWN_MHNOS : = 29; else PLITHOS_HMERWN_MHNOS : = 28; 4, 6, 9, 11: PLITHOS_HMERWN_MHNOS : = 30; end {case} end; function AR_HMERWN_ETOYS (ETOS: integer): integer; { µ ETOS} begin if DISECTO (ETOS) then AR_HMERWN_ETOYS := 366; else AR_HMERWN_ETOYS := 365; end; . . , 2003 27

µ: µ µ functions

program Calculator4(input, output); var x1, x2, apotelesma: real; praxh: char; function PROSTHESE (x, y : real ): real; begin PROSTHESE := x + y end; function AFAIRESE (x, y : real ): real; begin AFAIRESE := x - y end; function POLLAPLASIASE (x, y : real ): real; begin POLLAPLASIASE := x * y end; function DIAIRESE (x, y : real ): real; begin DIAIRESE := x / y end; . . , 2003

28

14

...

begin writeln(output, 'EISAGETE: telesti x1 x2'); readln(input, praxh, x1, x2); case praxh of '+' : apotelesma := PROSTHESE (x1, x2); '-' : apotelesma := AFAIRESE (x1, x2); '*' : apotelesma := POLLAPLASIASE (x1, x2); '/' : if x2 <> 0 then apotelesma := DIAIRESE (x1, x2) else writeln(output, 'ADYNATH DIAIRESH'); else writeln(output, 'LA8OS EISAGVGH DEDOMENVN'); end {case}; writeln(output, x1, ' ', praxh, ' ', x2, ' = ', apotelesma); end. {Calculator4}

. . , 2003

29

µ µµ

µ µµ µ µ «µµ»

: µµ µ , µ : µµ µ

µ µ µµ µ: µµ µ µ µ µµ : µµ µ µ «» µ µµ µµ /

. . , 2003

30

15

Information

Microsoft PowerPoint - lecture7.ppt

15 pages

Report File (DMCA)

Our content is added by our users. We aim to remove reported files within 1 working day. Please use this link to notify us:

Report this file as copyright or inappropriate

563829