Download presentation
Presentation is loading. Please wait.
Published byClemence Andrews Modified over 8 years ago
1
Pascal Programming Today Chapter 2 1 Chapter 2
2
Pascal Programming Today Chapter 2 2 »Output statements write data to output devices (e.g. VDU). »Two output statements in Pascal: –writeln statements –write statements
3
Pascal Programming Today Chapter 2 3 » writeln statements move the cursor to the beginning of next line after printing but write statements do not.
4
Pascal Programming Today Chapter 2 4 Syntax of writeln statements writeln(,,..., ) Syntax of write statements write(,,..., )
5
Pascal Programming Today Chapter 2 5 »Differences between the output of writeln and write statements:
6
Pascal Programming Today Chapter 2 6 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output __
7
Pascal Programming Today Chapter 2 7 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output A_A_A_A_
8
Pascal Programming Today Chapter 2 8 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output AB_
9
Pascal Programming Today Chapter 2 9 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output ABC _ ABC_
10
Pascal Programming Today Chapter 2 10 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output __
11
Pascal Programming Today Chapter 2 11 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output A_A_ A_A_
12
Pascal Programming Today Chapter 2 12 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output AB_AB_ AB_
13
Pascal Programming Today Chapter 2 13 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output ABC_ABC_ ABC_
14
Pascal Programming Today Chapter 2 14 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output __
15
Pascal Programming Today Chapter 2 15 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output AB _ AB_
16
Pascal Programming Today Chapter 2 16 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output AB CD _ ABCD_
17
Pascal Programming Today Chapter 2 17 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output AB CD E _ ABCDE_
18
Pascal Programming Today Chapter 2 18 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output __
19
Pascal Programming Today Chapter 2 19 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB _ AB_
20
Pascal Programming Today Chapter 2 20 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB _ AB_
21
Pascal Programming Today Chapter 2 21 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB CD _ ABCD_
22
Pascal Programming Today Chapter 2 22 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB CD E _ ABCDE_
23
Pascal Programming Today Chapter 2 23 »All output items can be formatted to certain field widths by adding a colon ( : ) and a positive integer after them.
24
Pascal Programming Today Chapter 2 24 Syntax of formatting field widths writeln( :,..., : ) or write( :,..., : )
25
Pascal Programming Today Chapter 2 25 »If specified field widths are too large, leading blank(s) will be added and the output items will be right-justified. »If specified field widths are insufficient, the field widths will be increased automatically to accommodate the whole item.
26
Pascal Programming Today Chapter 2 26 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output __
27
Pascal Programming Today Chapter 2 27 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output 12 _ 12_
28
Pascal Programming Today Chapter 2 28 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output 12 35678 _ 12 35678_
29
Pascal Programming Today Chapter 2 29 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output 12 35678 1234 _ 12 356781234_
30
Pascal Programming Today Chapter 2 30 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output 12 35678 1234 98700 _ 12 3567812349 8700_
31
Pascal Programming Today Chapter 2 31 »Real values are normally printed in floating point notation. »Real values will be printed in decimal notation if number of decimal places is specified by adding a colon ( : ) and a positive integer after the field width.
32
Pascal Programming Today Chapter 2 32 Syntax of specifying number of decimal places of real values writeln( : :,..., : ): )
33
Pascal Programming Today Chapter 2 33 or write( : :,..., : ): )
34
Pascal Programming Today Chapter 2 34 writeln(-12.34); writeln(12.34:4); writeln(12.34:7); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:7); write(12.34:7:3); write(12.34:7:1); Output __
35
Pascal Programming Today Chapter 2 35 writeln(-12.34); writeln(12.34:4); writeln(12.34:7); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:7); write(12.34:7:3); write(12.34:7:1); Output -1.2340000000E+01 _ -1.2340000000E+01_
36
Pascal Programming Today Chapter 2 36 writeln(-12.34); writeln(12.34:4); writeln(12.34:7); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:7); write(12.34:7:3); write(12.34:7:1); Output -1.2340000000E+01 1.2E+01 _ -1.2340000000E+01 1.2E+01_
37
Pascal Programming Today Chapter 2 37 writeln(-12.34); writeln(12.34:4); writeln(12.34:10); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:10); write(12.34:7:3); write(12.34:7:1); Output -1.2340000000E+01 1.2E+01 1.234E+01 _ -1.2340000000E+01 1.2E+01 1.234E+01_
38
Pascal Programming Today Chapter 2 38 writeln(-12.34); writeln(12.34:4); writeln(12.34:10); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:10); write(12.34:7:3); write(12.34:7:1); Output -1.2340000000E+01 1.2E+01 1.234E+01 12.340 _ -1.2340000000E+01 1.2E+01 1.234E+01 12.340_
39
Pascal Programming Today Chapter 2 39 writeln(-12.34); writeln(12.34:4); writeln(12.34:10); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:10); write(12.34:7:3); write(12.34:7:1); Output -1.2340000000E+01 1.2E+01 1.234E+01 12.340 12.3 _ -1.2340000000E+01 1.2E+01 1.234E+01 12.340 12.3_
40
Pascal Programming Today Chapter 2 40 Syntax of readln statements readln(,,..., ) » readln statements receive data and store them into the variables listed in the parentheses relative to their position.
41
Pascal Programming Today Chapter 2 41 »Input statements receive data from input devices (e.g. keyboard).
42
Pascal Programming Today Chapter 2 42 Syntax of readln statements readln(,,..., ) » readln statements receive data and store them into the variables listed in the parentheses relative to their position.
43
Pascal Programming Today Chapter 2 43 »The program will pause and wait for input in the execution of readln statements. »If number of input data is more than the number of variables in readln statements, the exceeded input will be lost.
44
Pascal Programming Today Chapter 2 44 »If there are insufficient input, the program will pause to wait for the required input.
45
Pascal Programming Today Chapter 2 45 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output A=1 B=2 C=3 _ Input 1 2 3 _
46
Pascal Programming Today Chapter 2 46 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output A=1 B=2 C=3 _ Input 1 2 3 4 _ The fourth data will be lost.
47
Pascal Programming Today Chapter 2 47 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output 1 2 _ Input 1 2 _ Waiting for the third item.
48
Pascal Programming Today Chapter 2 48 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output Invalid numeric format _ Input F 1 2 _
49
Pascal Programming Today Chapter 2 49 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output A=1 B=2 C=3 _ Input 123_123_
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.