IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
 
 
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help
 
 

eXercise #2

Scalar Data in Delphi


BYTE

1. What are the values of each of the following operations? Write the resultant output in your exercise books:
  1. +37
  2. 17 shl 2
  3. sqr(7)
  4. 71 div 3
  5. succ (73)
  6. 71 mod 3
  7. ord(19)
  8. 21 *3
  9. abs(-123)
  10. 16/4
  11. sqrt(4)
  1. pred(1)
  2. not 56
  3. 16 and 32
  4. 11 xor 3)
  5. 23 shr 2

2. Given the following declararions:

Var a, b, c : byte;

Determine the values that will be output for each of the variables and then explain it.

  1. begin
    a:=3 ;
    b:=17;
    c:=b-a;
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
    end
  2. begin
    a:=8 ;
    b:=13;
    b:=9;
    c:=b+a;
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
    end
  3. begin
    a:=17;
    b:=1;
    c:=16 shr 1;
    b:=3;
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
    end
  4. begin
    a:=6 ;
    b:=sqr(a);
    c:=b mod a;
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
    end
  5. begin
    a:=3 ;
    b:= 9;
    c:=5;
    c:= c+sqr(a);
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
    end

CHAR

1. Determine the value of each of the following expressions. You may need to have a copy of the ASCII collating sequence handy.
  1. chr(77)
  2. upcase('*')
  3. ^j
  4. integer('E')
  5. ord('S')
  6. succ('Z')
  7. byte('A')
  8. pred('A')
  1. upcase('m')
  2. boolean(^A)
  3. 'x'<>'X'
  4. ord(#32)
  5. 'd'=#100
  6. ord(^L)
  7. #25<=^Y

2. Given the declarations


	var
		a,b:	byte;
		c:	char;

determine the values outputted for each of these variables after the following sequences of assignments.

  1. begin
    a:= 70;
    b:= 9;
    c:= chr(a+b);
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
    end.
  2. begin
    b:= 3;
    a:= 69;
    c:='M';
    c:= chr(a-b);
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
    end.
  3. begin
    c:= 'h';
    b:= 15;
    a:= ord(c);
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
    end.
  4. begin
    c:= '1';
    a:= ord(c);
    c:= succ(c);
    b:= ord(c);
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
    end.
  5. begin c:= '3';
    b:= ord(c);
    c:= chr(b);
    a:= 7+b;
    showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
    end.

BOOLEAN

1. What is the value of each of the following operations?

  1. true and true
  2. pred (true)
  3. true or false
  4. ord (true)
  5. false xor false
  6. false < = true
  7. false and true
  8. true > = false
  1. true xor false
  2. false <= false
  3. false or false
  4. true <> false
  5. ord (false)
  6. false < true
  7. succ (false)
  8. false = false

INTEGER

1. What is the value of

  1. $ABAB shr 3
  2. ord (9155)
  3. lo ($FACE)
  4. $60FF xor $7905
  5. 385 div 71
  6. swap ($ABCD)
  7. 193 and 2076
  8. 385 mod 71
  1. lo (300)
  2. maxint or 5000
  3. not maxint
  4. hi (745)
  5. abs (-42 1)
  6. hi ($3000)
  7. swap (1 2 3)

2. Despite the fact that, i has been properly declared as an integer variable, each of the following statements will cause problems. Describe what type of error has been made in each, decide whether the compiler will spot it or whether it will be an error at runtime.

  1. sqr(i)
  2. i := sqrt(3)
  3. i : = 3.5
  4. i := 250*300
  5. i := 307 div 0
  6. i+l := 41*3
  7. sqr(i) := 16

REAL

1. Determine the values of each of the following:

  1. abs (-1.93)
  2. In (42.8)
  3. int (32.84)
  4. arctan (1.0)
  5. sqr (-1.4)
  6. exp (1.0)
  7. sqrt (36.0)
  8. sin (1.0)
  9. frac (18.83)
  1. 7.8*-6.1
  2. trunc (231.4)
  3. 3.7-5.2
  4. round (-82.7)
  5. 6.4/8.0
  6. trunc (-5.5)
  7. 3.1 > 9.2
  8. cos (1.22)
  9. 21.5 <= -21.5

2. Assuming that both r and s are legally declared real variables, that i is of type integer and that p is a boolean variable, what is wrong with each of the following assignment sequences?

  1. begin
    r:= 3.0;
    s:=r-r;
    r:= r/s
    end.
  2. begin
    r :=-3.1;
    i:= int(r);
    s:= -r
    end.
  3. begin
    s:= 12.0;
    r:= frac(s);
    s:= s/r
    end.
  4. begin r:= 3.0; s:= sqrt(9.0); p:= r=s end.

TYPE CONVERSION

1. Express the following using conversions.

  1. the character with ASCII number 98.
  2. the ASCII number of the character 'k', as a byte.
  3. the real number which corresponds to 71.
  4. the byte corresponding to the Integer 23.
  5. the integer which corresponds to the ASCII number of -L.
  6. the integer which is as close as possible to 123.98.
  7. the character which corresponds to the integer 50.
  8. the integer which is equivalent to the byte value 18.

2. Assuming b is byte, c is char, p is boolean, i is integer and r is real, what is wrong with each of the following assignment statements?

  1. i:= sqrt(3)
  2. 9:= b
  3. p:= odd(true)
  4. i:= frac(9.0)
  5. b:= trunc(maxint)
  6. i:= odd(97)
  7. 72:= trunc(72.9)
  8. 7<3:= true
  9. p:= not 21
  10. r:= real(10)
  11. p:= sqr(2)=sqrt(16)

EVALUATING EXPRESSIONS

1. What is the value of each of the following expressions?

  1. 10-5+3
  2. 10-5*3
  3. 10-5-3
  4. 29 div 5 mod 3
  5. 29 mod 5 div 3
  6. 25 div 9 mod 3 * 2
  7. abs (17 mod 13)
  8. sqr (17 div 3)
  9. abs (sqr(l1 mod 3) - sqr(l1 div 3))
  10. pred (ord (succ (7))
  11. pred (pred (pred ('M'))
  12. ord (succ (chr (pred(86))))
  13. abs(43) abs(27.4)
  14. sqr(7.0) sqrt(81.0)
  15. succ (sqr (8))
  16. pred (trunc (int (-11.83)))
  17. sqr (ord (pred ('B'))
  18. odd (succ (ord ('R'))
  19. trunc (abs (-1.0*13.7))
  20. 6+3=2+7
  21. (6>5) and (4>3)
  22. (6>5) or (3>4)
  23. (6>5) and (3>4)
  24. '6' < 'D'
  25. not (6 > 3)
  26. (2=1) or not (3=4)
  27. not (8<9) and ('v'<'V')
  28. not ((8<9) and ('v'<'V'))
  29. (7 < 6) and true
  30. false or not false
  31. false and not false
  32. not (not (2 > 3) and not false)

2. Given the declared store

	Var	i	:	integer;
		c	:	char;
		p,q	:	boolean;
		r	:	real;
	Begin
			i:= 10; 
			c := 'S';
			p := true;
			q := false;
			r := 4.5;

determine the value of the following boolean expressions:

  1. i >= 10
  2. p and not q
  3. i > trunc(r)
  4. not p and q
  5. ord(c) < ord('T')
  6. not p and not q
  7. i*r > 100.0
  8. not (p and q)
  9. p and q
  10. not p or not q
  11. not (p or q)
  12. not (i>5) and not (p and (c='S'))

3. Find an expression which will convert:

  1. any uppercase letter into the corresponding lowercase letter.
  2. any lowerease letter into the corresponding uppercase letter.
  3. any uppercase letter into the corresponding control character.

4. The printing characters (commencing with the space) start at character number 32 and end with character number 126. The center letter in this sequence of characters has number 79. To save you looking this up, it is the capital letter '0'. To encode a message, you take each letter or character of the message and replace it with the character which is as far from 'O' as the character but on the other side. In other words, you draw a line through 'O' and mirror each character in this line.

  1. Create an expression which converts any printing character into its coded character.
  2. To complete this secret message business, you will also need a decoder. Write the decoding expression.

Solutions

wonko@wonko.info
©Copyright t 1992..2018+. Edition 26.150117
wonkosite
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License
.