Pascal Output Answer
Pascal Output Answer
2. For each of the following program segments, write down its screen output.
a) writeln(‘****’); ****
writeln(‘* *’); * *
writeln(‘****’); ****
b) write(‘****’);
write(‘* *’);
write(‘****’); ***** *****
c) Subject := ‘Pascal programming’; I like
Writeln(‘I like ‘); Pascal Programming
Writeln(Subject); very much
Writeln(‘very much’);
3. Assuming that I and J are integer variables with i=5, j=8 and that K is a real variable with
K=345.678, write down the output for each of the following program segments:
□□□□□□Name□□□□□□□contactNo□□□□□□□□□□□□□Salary
----------------------------------------------------------------------------
□□□□ JohnWu□□□□□□□□24332343□□□□□□□□□□□ 16432.23
□□□□□Ti mLi□□□□□□□□25433443□□□□□8.98243000E+03
begin
Writeln(‘Name’ :10, ‘contactNo’:19, ‘Salary’:19);
Writeln(‘------------------------------------------------------------------’);
Writeln(‘JohnWu’ :10, ‘24332343’:19, 16432.226:19:2);
Writeln(‘TimLai’ :10, ‘25433443’:19, 8982.3:19)
end.
5.With the given variables and their initial values, write a set of output statements that will produce
the following output.
Program OutputTest;
Var A: integer;
B: real;
C: char;
D: string;
Begin
A:=100;
B:= 999.0;
C:=’Z’;
D:=’Dummy’
end.
a) bb100bb999bbZbbDummy
write(A:5);
write(B:5:0);
write(C:3);
writeln(D:7);
b) 100bZb9.99E+02bDummy
write(A);
write(C:2);
write(B:9);
writeln(D:6);
c) DummyZ
999.000100
write(D);
writeln(C);
write(B:7:3);
writeln(A);
d) 1099.00ZZZZ
write(A +B :7:2);
writeln(C,C,C,C);
4. Refer to the following program declaration.
var
S1, S2, S3 : String;
C1, C2, C3 : char;
N1, N2 : integer;
R1, R2 : real;
Write down the output of each of the following program segments with the given input values
(a) readln (N1, N2) ;
readln (N3) ;
writeln (N1) ;
writeln (N2) ;
writeln (N3) ;
12 23 34
98 87 76
12
23
98
X Y Z
X
b
Y
34.567 21
3
4
.
567
567 1 2 234
567
2
1
John Lee M
123 1 2 3 4 5
123.45 789
John Lee M
123
1
1.2345000000E+02
7.8900000000E+02
5. The following table shows the types and the values of the variables M,N,R,C,D,E,S,T and U.
Variable Type Value
M integer 25
N integer 99
R real 234.5678
C char ‘X’
D char ‘+’
E char ‘=’
S string ‘Joey’
T string ‘apple’
U string ‘eats’
Use these variables to write output statements to produce the following output.
(Note: Any other strings and blanks are not allowed. The symbol ‘ ’ represents a space.)
(a) 25
write(M)
(b) 9925
Write(N,M)
(c) 99 + 25 = 124
Write(N,D,M,E,M+N)
(d) 99 x 25
Write(N, C, M)
(f) apple
Write(T:15) OR write(‘ ’,T)
(h) 2.345678E + 02
Write(R:13)
(i) 235
Write(R:3:0) OR write(round(R) )
(j) 234.57
Write(R:6:2)
(k) 2345.568
Write(R:10:3)
(l) 235234.57
Write(R:3:0, R:6:2)
6. A program MarkList reads the names of three students and their marks in the Chinese, English
and Mathematics tests and displays them in the format of a table.
Sample output
Enter name: Amy
Enter Chinese, English and Mathematics marks : 88 56 65
Enter name : Billy
Enter Chinese, English and Mathematics marks : 100 82 90
Enter name : Carol
Enter Chinese, English and Mathematics marks : 45 37 50
Name Chinese English Mathematics
Amy 88 56 65
Billy 100 82 90
Carol 45 37 50
7. A program ClassClub reads the names of the class committee and displays them in the format
shown.
Sample output
who is the Chairman? Amy
who are the two Vice Chairmen? Peter
Grace
who is the Treasurer? Sandy
who is the Secretary? Christopher
1 program ClassClub ;
2 var
3 Chairman, Vicel, Vice2, Treasurer, Secretary : string _______________________ ;
4 begin
5 write (‘who is the Chairman? ’) ;
6 readln ( _Chairman__________________) ;
7 write (__’Who are the two Vice Chairmen?’)
8 _readln(Vice1);
9 write(‘ ‘:31);
10 readln(Vice2);
11 write(‘Who is the Treasurer?’);
12 readln( Treasurer);_______________________________
13 write(‘Who is the Secreatary?’);_____________________________________
14 readln(Secreatary);_____________________________________________
15 writeln;_________________________________________________________
16 writeln (‘**** 4A Class Committee ****’) ;
17 writeln (‘Chairman : ‘ : 17, Chairman);______________________________
18 _writeln(‘Vice Chairman : ‘:17, Vice1);_______________________________
19 _writeln(‘ ‘:17, Vice2);____________________________________________
20 writeln(‘Treasurer: ‘:17, Treasurer);__________________________________
21 writeln(‘Secreatary: ‘:17, Secreastary)________________________________
22 end._______________________________________________________________
8. For each of the following Boolean expressions, add parentheses ( ) to show the order of
evaluation and construct the truth table.
(a) not p and not q
(not p) and (not q)
(b) p and q or r
(p and q) or r
p q r (p and q) or r
TRUE TRUE TRUE TRUE
TRUE TRUE FALSE TRUE
TRUE FALSE TRUE TRUE
TRUE FALSE FALSE FALSE
FALSE TRUE TRUE TRUE
FALSE TRUE FALSE FALSE
FALSE FALSE TRUE TRUE
FALSE FALSE FALSE FALSE
(c) p and not q or not r
(p and (not q)) or (not r)
x <> 0
c >= ‘A’
y>5
r = 10
s < 15
10<t<100
(g) (z > 1) and (z = 1)
FALSE
10. Decimal Notation Scientific Notation Floating Point Notation
23.78 2.378X10 2.3780000000E+01
0.0 0.0X10^0 0.0000000000E+00
-0.0008934 -8.934X10^-4 -8.9340000000E-04
-50000.0005 -5.0000005X10^3 -5.00000005E+03
9900000000 9.9X10^9 9.9000000000E+09
-100010000 -1.0001X10^8 -1.0001000000E+08
-0.00000788 -7.88X10^-5 -7.8800000000E-05
0.00123456 1.23456X10^-3 1.23456E-03
11. Write down the result of the following expressions.
a) 12*-3+ -5
b) –5*6-18+7.0
c) 43/5
d) –22 div 6
e) –22 div –6
f) 22 mod 6
g) –22 mod –6
h) 43 div 5 mod 4
1a)-41 b)-4.1 000 000 000E+01
c)8.6 000 000 000E+00
d)-3 e)3 f)4
g)-4 h)0
2. Assume the variables X, Y, Z hold 1,2,3 respectively. Draw a dry run table for the following
program statements.
A) Z:=X;
X:=Y;
Y:=Z;
B) X:=X+2;
Y:=Y*3;
Z:=X+Y;
C) X:= X+Y;
Y:=Y+Z;
Z:=Z+X;
D)X:=3;
1. Assume the variables X, Y, Z hold 1,2,3 respectively. Draw a dry run table for the following
program statements.
A) Z:=X;
X:=Y;
Y:=Z;
B) X:=X+2;
Y:=Y*3;
Z:=X+Y;
C) X:= X+Y;
Y:=Y+Z;
Z:=Z+X;
D)X:=3;
Y:=2;
Z:=1;