INTERACTIVE TEST 6: Arrays, pred, succ, ord, chr | Notes | Tests | Home Page |
This browser does not support JavaScript. In order to use this test, please update your browser to a JavaScript compatible browser, or choose the CGI version of this test. Internet Explorer browsers are updated by http://www.microsoft.com/ie/, and Netscape browsers updated by accessing http://www.netscape.com/
1. Write a Pascal statement to define an array called numbers, which is an integer array with elements ranging from 1 to 20
type numbers = ARRAY[1..20] of int; type numbers = ARRAY[1..20] of integer; type numbers := ARRAY[1..20] of integer; var numbers = ARRAY[0..19] of int;
2. Write a Pascal statement to create an array called mynumbers, of type numbers, which was defined in 1. above
var mynumbers : numbers; type numbers : mynumbers; var mynumbers := numbers; type mynumbers of numbers;
3. Write a Pascal statement which assigns the integer value 20 to element 4 of the array mynumbers, which was declared in 2. above
mynumbers[3] = 20; mynumbers[20] := 4; mynumbers[4] = 20; mynumbers[4] := 20;
4. Write Pascal statements which define a packed array of characters (15 elements), called word, create a working variable of type word called myword, and then reads input from the keyboard into the array myword
type word = PACKED ARRAY[1..15] of char; var word : myword; begin readln( myword );
type word = PACKED ARRAY[1..15] of integer; var myword : word; begin readln( word );
type word = PACKED ARRAY[1..15] of char; var myword : word; begin readln( myword );
5. Write Pascal statements which will sum the contents of an integer array called mynumbers, which has 20 elements numbered 1 to 20
total := 0; for loop = 1 to 20 total := total + mynumbers[loop];
total := 0; for loop := 1 to 20 do total := total + mynumbers[loop];
total = 0; for loop = 1 to 20 total = total + mynumbers[loop];
6. Write a Pascal statement which will initialize a packed character array called message to the string 'Hello there!'. The array has thirteen elements
message := "Hello there! "; message = 'Hello there! '; message := 'Hello there! '; message := "Hello there!";
7. Write a Pascal statement to display the ASCII value of the letter 'A'
writeln( chr('A') ); writeln( pred('A') ); writeln( succ('A') ); writeln( ord('A') );
8. Write a Pascal statement to display the character represented by the ASCII value 52
writeln( ord(52) ); writeln( pred(52) ); writeln( chr(52) ); writeln( succ(52) );
9. Write a Pascal statement to display the character which follows 'F'
writeln( chr('F') ); writeln( ord('F') ); writeln( succ('F') ); writeln( pred('F') );
10. Write a Pascal statement to display the character which comes before 'Z'
writeln( ord('Z') ); writeln( chr('Z') ); writeln( succ('Z') ); writeln( pred('Z') );
br> Copyright B Brown/P Henry, 1988-1999. All rights reserved.