Pascal Programming Today Chapter 2 1 Chapter 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
Pascal Programming Today Chapter 2 3 » writeln statements move the cursor to the beginning of next line after printing but write statements do not.
Pascal Programming Today Chapter 2 4 Syntax of writeln statements writeln(,,..., ) Syntax of write statements write(,,..., )
Pascal Programming Today Chapter 2 5 »Differences between the output of writeln and write statements:
Pascal Programming Today Chapter 2 6 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output __
Pascal Programming Today Chapter 2 7 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output A_A_A_A_
Pascal Programming Today Chapter 2 8 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output AB_
Pascal Programming Today Chapter 2 9 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output ABC _ ABC_
Pascal Programming Today Chapter 2 10 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output __
Pascal Programming Today Chapter 2 11 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output A_A_ A_A_
Pascal Programming Today Chapter 2 12 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output AB_AB_ AB_
Pascal Programming Today Chapter 2 13 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output ABC_ABC_ ABC_
Pascal Programming Today Chapter 2 14 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output __
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_
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_
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_
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 __
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_
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_
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_
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_
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.
Pascal Programming Today Chapter 2 24 Syntax of formatting field widths writeln( :,..., : ) or write( :,..., : )
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.
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 __
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_
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 _ _
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 _ _
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 _ _
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.
Pascal Programming Today Chapter 2 32 Syntax of specifying number of decimal places of real values writeln( : :,..., : ): )
Pascal Programming Today Chapter 2 33 or write( : :,..., : ): )
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 __
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 E+01 _ E+01_
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 E E+01 _ E E+01_
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 E E E+01 _ E E E+01_
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 E E E _ E E E _
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 E E E _ E E E _
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.
Pascal Programming Today Chapter 2 41 »Input statements receive data from input devices (e.g. keyboard).
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.
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.
Pascal Programming Today Chapter 2 44 »If there are insufficient input, the program will pause to wait for the required input.
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 _
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 _ The fourth data will be lost.
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.
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 _
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_