Misc.
Questions from previous exams of CPSC 110, this may or may not help you.
These are mostly from the SECOND and THIRD exams (though subject material covered
varies slightly from semester to semester so some questions may not have yet
been covered in your class). Some questions may be repeated.
Few (if any) answers to these questions will be provided. The actual
gain in this is if you look the answers up or type the short programs
in and discover the answers yourself.
In no way are these questions guaranteed to help you (but it is extremely
unlikely they would hurt you).
If you print this it will use about 41 pages.
In Pascal, procedure declarations are placed:
Which of the following is an illegal assignment statement (assume all variables properly declared)?
Today in the U.S. the pseudocode of an algorithm is written in
The first general purpose, purely electronic digital computer was:
What generation of computer are we currently producing?
How many bits are in a byte?
Which of the following is NOT a key hardware component?
every time you compile your program (T/F).
· The following Pascal program section is valid
Program Interest;
Var
Principal, Rate, Time: Integer;
Sum, Principal: Real;
If a unit named Bob is in a file UNIT1.PAS and you compile it to disk, the compiled version
of the unit will be in a file named:
Given the below 4 types of declarations:
1) Constant Declarations
2) Variable Declarations
3) Type Declarations
4) Procedure and Function Declarations
What is the order the book says they should be done in a program?
The next 3 questions assume the following declarations:
Type
Aggie = array [1..100] of integer;
Var
A, B, C : Aggie;
i, j, sum : integer;
What does the following piece of code do given the above declarations and assuming it
is embedded in a working program ?
For i:= 1 to 100 do
A[i] := B[100 + i + 1];
Given the above declarations and assuming it is embedded in a working program, what does the following piece of code do ?
for i:=1 to 100 do
begin
sum := A[i];
A[i] := B[i];
B[i] := sum;
end;
If we want to add the arrays A and B componentwise and store the result in the array C
(i.e. C[i] := A[i] + B[i];) how many cells from A, B and C do we have to access?
In the book ADT stands for which of the following:
Which of the following is an illegal Pascal expression (assume all variables are declared correctly)
In the following program segment (assume no syntax errors and embedded in a working program)
VAR
x, y : integer;
BEGIN
x := 3;
y := 5;
if 2 > x then
y := 1
else
x := 5;
if 4 < x then
y := 2;
END.
What is the final value of y ?
What does the operator <> mean in Pascal ?
What does the operator != mean in Pascal ?
Which of the following is NOT a valid Pascal function ?
Which of the following is an illegal actual value parameter of type integer? (Assume the variable n is of type integer).
How many bytes is a Kilobyte ?
Which of the following is the correct declaration for an array?
What is the output of the below program ?
program OutPut;
type
ListArry = array[1..6] of char;
var
i : integer;
word : ListArry;
begin
word[1] := O;
word[3] := L;
word[6] := ?;
word[5] := H;
word[2] := L;
word[4] := E;
for i := 6 downto 1 do
write(word[i]);
end.
What is the output of the below program?
program AddStuff;
const
MAX_SIZE = 5;
type
score_array = array[1..MAX_SIZE] of integer;
var
i, j, x : integer;
scores : score_array;
begin
for i:= 1 to MAX_SIZE do
scores[i] := i;
x := 0;
for j := 1 to MAX_SIZE-2 do
x := x + scores[j];
writeln(x);
end.
Which of the following is NOT a built in string function/procedure in Turbo Pascal?
If the following statement is placed in a working program what is the value of p after the statement
is executed (assume p is type integer) ?
p := pos(be, dobedobedo);
How many elements are in the following multi-dimensional array?
Var
Test : array[A..D,a..d] of integer;
The next 3 questions refer to the below code:
program FoodBill;
type
DeptName = (Meat, Deli, Produce, Grocery);
AmountSpent = array[DeptName] of real;
ExpenseArray = array[50] of AmountSpent;
var
SpentOn : AmountSpent;
CustomerExpense : ExpenseArray;
function Total(var B: AmountSpent) : real
var
Dept: DeptName;
Sum : real;
begin { Total }
Sum := 0;
for Dept := Meat to Grocery do
Sum := Sum + B[Dept];
Total := Sum;
end; { Total }
begin { main }
SpentOn[Meat] := 40.0;
SpentOn[Deli] := 0.0;
SpentOn[Produce] := 10.00;
SpentOn[Grocery] := 45.00;
writeln(Total(SpentOn):0:2);
end. { main }
What is the output of the above code.
In the above code the variable SpentOn is:
In the above code the variable CustomerExpense is:
A logical error is:
Which of the following is not an input device?
In this class, a set of instructions that leads to a solution is called a(n) ?
Which of the following does NOT make source code easier to read?
The next 3 questions refer to the below code:
program MultiIndex;
type
GradeArray = array[1..10, 1..20] of integer;
var
MyArray : GradyArray;
index, j : integer;
q, r, s : integer;
begin { main }
for index := 1 to 10 do
begin
for j := 1 to 20 do
begin
if (index > j) then
MyArray[index, j] := index - j
else
MyArray[index, j] := j index;
end; { for j }
end; { for index }
q := MyArray[8, 8];
r := MyArray[4, 2];
s := MyArray[6, 9];
{ The questions will ask for the values of q, r, s at this point in the code }
writeln(q, ' ', r, ' ', s);
end.
What is the value of q that is output?
What is the value of r that is output?
What is the value of s that is output?
The next 3 questions refer to the below code:
program ArrayStuff;
type
array_type : array[1..10] of integer;
var
A, B : array_type;
index, x, y, z : integer;
begin
for index := 1 to 10 do
begin
A[index] := index + 1;
B[index] := index;
end; { for }
B := A;
B[3] := B[3] 2;
x := B[3];
y := A[3];
z := B[4];
{ The questions will ask what the value of x, y, z are at this point in the code }
writeln(x, y, z);
end.
What is the value of x that is output?
What is the value of y that is output?
What is the value of z that is output?
Assume the below code was embedded in a working program.
sum := 0;
for i:=1 to 5 do ; { notice the semi-colon after the do is intentional }
sum := sum + i;
writeln(sum);
What is the output of the above writeln?
Given the below declarations:
type
Sample = record
F1 : integer;
F2 : char;
end;
var
X1, X2 : Sample;
Assume the following code is embedded in a working Pascal program:
X1.F1 : = 5;
X1.F2 := A;
write(X1.F1, X1.F2, ---- );
X2 := X1;
X2.F1 := 6;
X1.F1 := 4;
writeln(X2.F1, X2.F2);
What is the output?
The next two questions refer to the below table:
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
This table defines the two dimensional array A. Assume row 1 starts at the value 1
and row 2 starts at the value 6 and row 3 starts at the value 11. Assume column 1 starts
at 1, column 2 at 2, column 3 at 3, column 4 at 4, and column 5 at 5.
If we use ROW major order to index into A, then the value of A[2, 3] is:
If we use COLUMN major order to index into A, then the value A[2, 3] is:
Which of the following cannot be part of a procedure in Turbo Pascal 7.0:
a) local variables
b) local functions
c) local named constants
d) constant parameters
e) they are all valid parts of a procedure
What is the output of the following code:
program Letter;
function NumToChar( N: integer): char;
begin
NumToChar := 'Z';
if (N = 1) then
NumToChar := 'A';
if (N = 3) then
NumToChar := 'B';
end; { NumToChar }
begin {main program Letter }
writeln(NumToChar(1), NumToChar(2), NumToChar(3));
end. { main program Letter }
a) ZAB
b) BAZ
c) ABZ
d) AZB
e) none of the above
Which of the following subtasks is BEST implemented as a single function?
a) Converting a given number of centimeters into feet and inches.
b) Converting a given number of miles to an equivalent number of kilometers.
c) Computing the net income and the tax due on an income tax return,
given the gross income and the adjustments to income.
d) Computing the gas mileage and cost of a trip, given the miles traveled,
the number of gallons of gas consumed and the cost of gas per gallon.
e) Displaying the output of a program to the screen
Which of the following expressions evaluates to false:
a) true OR true
b) not (true OR false)
c) not (true AND false)
d) true OR false
e) true AND true
global variables inside a procedure (T/F).
Next 2 Questions refer to the below program
program ShortCheck;
var
kids, pieces : integer;
begin
kids := 0;
pieces := 100;
if (kids <> 0) and (pieces div kids >= 2) then
writeln('Each child may have two pieces.')
else
writeln('There are no kids.');
end.
Assuming the compiler IS using short-circuit evaluation the output is:
a) Each child may have two pieces.
b) There are no kids.
c) The program does not run the compiler generates a syntax error.
d) The program runs but it generates a runtime error.
e) Both a) and b) are printed (on separate lines).
Assuming the compiler is NOT using short-circuit evaluation the output is:
a) Each child may have two pieces.
b) There are no kids.
c) The program does not run the compiler generates a syntax error.
d) The program runs but it generates a runtime error.
e) Both a) and b) are printed (on separate lines).
Which of the following is NOT a boolean operator in Pascal?
a) in
b) and
c) not
d) or
e) out
Next 2 questions refer to the below program:
program NoGoodCode;
var
x, y, z : real;
begin
x := 15.5;
y := 11.12;
z := 20.89;
if (x > y) then { this is line 8 }
if (x > z) then
writeln('x is the largest')
else if ( y > z) then
writeln('y is the largest') { this is line 12 }
else if (y < z) then
writeln('z is the largest')
else
writeln('y is biggest');
end.
What is the output of the program as it is written above?
a) x is the largest
b) y is the largest
c) z is the largest
d) y is the biggest
e) There is no output
Assume there is a "begin" after line 8 and an "end" after line 12.
What is the output of the code if it is so modified?
a) x is the largest
b) y is the largest
c) z is the largest
d) y is the biggest
e) There is no output
What is the output of the following code (when embedded in
correct programs with X declared to be of type integer)?
X := 10;
repeat
X := X 3;
until X <= 0;
writeln(X);
a) 0
b) 2
c) 1
d) 2
e) 3
Next 2 Questions are based on the following program:
program ForKingdom;
var
X, Y, Z : integer;
begin
X:= -2;
Z := 1;
Y := -3;
for X := Y downto 0 do
Z := X;
writeln(X);
end.
When the program completes what is the value of X ?
a) 1
b) 1
c) 2
d) 3
e) none of the above
When the program completes what is the value of Z ?
a) 0
b) 1
c) 1
d) 3
e) none of the above
Which of the following is NOT a good method for terminating a loop in Pascal?
a) Exit on sentinel value.
b) Running out of input.
c) Count controlled loops.
d) Using a goto statement.
e) Exit on flag condition.
What is the output of the below program?
program IfLoops;
var
m, n, o : integer;
begin
for m:=0 to 6 do
begin
if ( M < 4) then
n := m + 3
else
if ( m > 5) then
o := n + 2
else if ( m = 6) then
o := n + 1;
end;
writeln( o );
end.
a) 7
b) 8
c) 9
d) 10
e) none of the above
Given the below code, what is(are) the NAME(s) of the file(s)
opened for outputting to (i.e. opened for writing)?
assign(file1, 'data1.txt');
rewrite(file1);
assign(file2, 'data2.txt');
reset(file2);
assign(file3, 'data3.txt);
append(file3);
a) data1.txt
b) data2.txt
c) data3.txt
d) data1.txt and data3.txt
e) data1.txt and data2.txt
1. The term index and subscript are synonymous. |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
2. Indexed variable and array variable are synonymous |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
3. Functions cannot return arrays |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
4. A data structure is a way of organizing data values |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
5. A dynamic data structure can grow and shrink in size during the course of a programs execution |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
6. A linked list is a type of dynamic data structure |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
7. Pointers can be passed to functions |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
8. A Pascal compiler will always generate a syntax error if you reference an array out of its bounds/size |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
9. Records cannot contain pointers as components |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
10. String types may NOT be used as parameter types (e.g procedure dostuff(var first, last : string[10]); ) |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
11. Array elements may be accessed either sequentially, as with a for loop, or in a random order by computing the desired index |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
12. The interface section of a unit is the private section |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
13. The implementation section of a unit is the private section |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
14. When writing a program that uses unit, the programmer must know the details of the unit's IMPLEMENTATION section |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
15. Constants and Types CANNOT be placed in the interface section of a unit source file |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
16. Arrays illustrate the notion of a structured type |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
17. A unit may only contain functions no procedures |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
18. Type String is an ordinal type |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
19. Value parameters typically consume less storage than variable parameters |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
20. In Pascal the size of an array must be declared at the time the program is written |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
21. The size of an array cannot be changed dynamically (during run-time). |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
22. An entire array can be used as a parameter to a write or writeln statement |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
23. An array variable without subscripts may be used in an assignment statement of the type A:=B; where A and B are arrays of the same type |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
24. A record type can have fields holding different types of data |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
25. A record type is an example of a structured data type |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
26. Records and arrays provide a way of giving a single name to a collection of values |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
27. Pascal allows you to use arrays of arrays |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
28. Pascal only allows you to use one or two dimensional arrays |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
29. In Pascal, the expression A[6, 7] is the same as A[7][6] |
|||||||||||||||||||
a. True |
b.
False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
30. Pascal allows you to create arrays of records |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
31. Enumerated type and subranges of enumerated types may be used as the index types of arrays. |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
32. The following definition is valid. Type Index = -5 .. 5; Grades = array[index] of integer; |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
33. The following program segment is valid. Program check; Var A:
array[1..10] of integer; X:
integer; Begin X:=
0; A[X]:=
1; End. |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
34. If C is an array, the statement C:= 0; is illegal. |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
35. The with statement
is used for arrays as well as records. |
|||||||||||||||||||
a. True |
b. False |
|
|
|
|||||||||||||||
|
|||||||||||||||||||
36. Index types for arrays cannot be which of the following types. |
|||||||||||||||||||
a. integer |
b. chars |
c. boolean |
d.
reals |
e. enumerations |
|||||||||||||||
|
|||||||||||||||||||
37. The following code uses which type of array: Books[4][5]:= 38.4; |
|||||||||||||||||||
a. single-dimensional |
b. multi-dimensional |
c.
array of arrays |
d. both A and B |
e. both A and C |
|||||||||||||||
|
|||||||||||||||||||
38. The following code uses which type of array: Books[4, 5]:=
38.4; |
|||||||||||||||||||
a. single-dimensional |
b.
multi-dimensional |
c. array of arrays |
d. both A and B |
e. both A and C |
|||||||||||||||
|
|||||||||||||||||||
39. The individual components of a record are commonly referred to as |
|||||||||||||||||||
a. fields |
b. components |
c. component fields |
d. all
of the above |
e. none of the above |
|||||||||||||||
|
|||||||||||||||||||
40. Components of a record are accessed using which operator. |
|||||||||||||||||||
a.
period (.) |
b. hyphen (-) |
c. arrow (->) |
d. all of the above |
e. none of the above |
|||||||||||||||
|
|||||||||||||||||||
41. Which of the following symbols declares a pointer variable. |
|||||||||||||||||||
a. asterisk (*) |
b.
caret (^) |
c. arrow (->) |
d. all of the above |
e. none of the above |
|||||||||||||||
|
|||||||||||||||||||
42. Which of the following will create a new dynamic variable. |
|||||||||||||||||||
a. malloc |
b. alloc |
c. calloc |
d. new |
e. create |
|||||||||||||||
|
|||||||||||||||||||
43. Which operator is used to access a component through a pointer. |
|||||||||||||||||||
a. period (.) |
b. hyphen (-) |
c. arrow (->) |
d. caret (^) |
e.
caret-period (^.) |
|||||||||||||||
|
|||||||||||||||||||
44. Which reserved word represents a value of empty or pointing to nothing for a pointer |
|||||||||||||||||||
a. NULL |
b. NIL |
c. EMPTY |
d. ZERO |
e. VOID |
|||||||||||||||
|
|||||||||||||||||||
45. What is the output of the below program ? program OutPut; type List = array[1..6] of char; Var i : integer; word : List; begin word[1] := Y; word[3] := W; word[6] := ?; word[5] := H; word[2] := D; word[4] := O; for i := 1 to 6 do write(word[i]); end. |
|||||||||||||||||||
a. ?YDWOH |
b. YDWOH? |
c. HOWDY? |
d. ?HOWDY |
e. There is no output |
|||||||||||||||
|
|||||||||||||||||||
46. In the statement: Score[ K ] := 5; K is the: |
|||||||||||||||||||
a. Index Expression |
b. Value of the
array element |
c. Array Name |
d. All of the above |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
47. In the statement: Score[ K ] := 5; Score is the: |
|||||||||||||||||||
a. Index Expression |
b. Value of the array element |
c. Array Name |
d. All of the above |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
48. In the statement: Score[ K ] := 5; 5 is the: |
|||||||||||||||||||
a. Index Expression |
b. Value of the
array element |
c. Array Name |
d. All of the above |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
49. What is the output of the below program (assume no syntax errors)? program SumScores; const MAX_SIZE = 5; Type score_array =
array[1..MAX_SIZE] of integer; var i, j, x, num_studs :
integer; scores : score_array; begin for i:= 1 to MAX_SIZE do scores[i] := i * 10; x := 0; num_studs := 3; for j := 1 to num_studs do x := x - scores[j]; writeln(x); end. |
|||||||||||||||||||
a. none of the below |
b. 30 |
c. 60 |
d. 100 |
e. 150 |
|||||||||||||||
|
|||||||||||||||||||
50. Which of the following is NOT a built in string function/procedure in Turbo Pascal? |
|||||||||||||||||||
a. copy |
b. reverse |
c. pos |
d. length |
e. insert |
|||||||||||||||
|
|||||||||||||||||||
51. If the following statement is placed in a working program what is the value of p after the statement is executed (assume p is type integer) ? p: = pos(do,
dothedo); |
|||||||||||||||||||
a. 0 |
b. 1 |
c. 5 |
d. 6 |
e. 7 |
|||||||||||||||
|
|||||||||||||||||||
52. Given the below 4 types of declarations: 5) Constant Declarations 6) Variable Declarations 7) Type Declarations 8) Procedure and Function Declarations What is the order the book says they should be done in a program? |
|||||||||||||||||||
|
b. 1,3,2,4 |
c. 4,2,1,3 |
d. 4,3,2,1 |
e. 3,4,2,1 |
|||||||||||||||
|
|||||||||||||||||||
53. Which of the following is the correct declaration for an array? |
|||||||||||||||||||
a.
A= array
[1..10] of integer; |
b. A= array of [1..10] integer; |
c. A= integer[1..10] of array; |
d. A = integer array of [1..10]; |
e. none of these |
|||||||||||||||
|
|||||||||||||||||||
54. Given the following type declaration: type BigOnes = 9..15; The host type of BigOnes is: |
|||||||||||||||||||
a. char |
b. boolean |
c. integer |
d. real |
e. string |
|||||||||||||||
|
|||||||||||||||||||
55. Assume the following code is embedded in a working program. Also assume that the array A has been properly declared and Element is type integer. Sum := 0; For Element := A[1] to A[100] do Sum := Sum +
Element; { This
is the statement line referred to in the question } How many times does the statement in the for loop get executed? |
|||||||||||||||||||
a. 99 times |
b. 101 times |
c. Cant say, it
depends on the values of A[1] and A[100]. |
d. once |
e. 100 times |
|||||||||||||||
|
|||||||||||||||||||
56. Which of the following are true: I. Enumerated type variables can be used in assignment statements. II. All ordinal types can used in readln statements. III. A subrange type contains a subrange of values of any data type. |
|||||||||||||||||||
a. I |
b. II |
c. III |
d. II and III |
e. I , II and III |
|||||||||||||||
|
|||||||||||||||||||
The next 3 questions assume the following declarations: Type ArrayType = array [1..10]
of integer; Var A, B, C : ArrayType; i, j, sum : integer; |
|||||||||||||||||||
57. What does the following piece of code do given the above declarations and assuming it is embedded in a working program ? For i:= 1 to 10 do A[i] := B[10 - i + 1]; |
|||||||||||||||||||
a. Copies the array B to A |
b. Copies the array A to B |
c. Stores in B, the reverse array of B. |
d. Stores in A,
the reverse array of B. |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
58. Given the above declarations and assuming it is embedded in a working program, what does the following piece of code do ? for i:=1 to 10 do begin sum := A[i]; A[i] := B[i]; B[i] := sum; End; |
|||||||||||||||||||
a. Reverses the contents of both A and B. |
b. Swaps the contents of A and B (i.e. When
the loop completes, the content of A = what the content of B was before the
loop and the content of B is what the content of A was before the loop) |
c. Finds the sum of the contents of A and B. |
d. Copies the contents of A into B, leaving A unchanged. |
e. None of the above. |
|||||||||||||||
|
|||||||||||||||||||
59. If low and high are integers and low < high then the number of elements in array A[low..high] of integer is: |
|||||||||||||||||||
a. high low |
b. high + low |
c. high low 1 |
d. high low + 1 |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
60. How many elements are in the following multi-dimensional array? Var Test : array[B..E,a..d] of integer; |
|||||||||||||||||||
a. 2 |
b. 4 |
c. 8 |
d. 16 |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
61. How many elements are in the following multi-dimensional array? Var Test : array[20..25, 10..15] of integer; |
|||||||||||||||||||
a. 10 |
b. 25 |
c. 36 |
d. 40 |
e. 70 |
|||||||||||||||
|
|||||||||||||||||||
62. A program that uses a unit must have access to at least: |
|||||||||||||||||||
a. The unit's source file |
b. The compiled
unit |
c. The .pas file of the unit |
d. The units matriod |
e. All of the above |
|||||||||||||||
|
|||||||||||||||||||
63. A program that uses a unit may reference: I. declarations found in the interface section of the unit II. declarations found in the implementation section of the unit III. any procedure and function found in the unit |
|||||||||||||||||||
a. I |
b. II |
c. III |
d. All of the above |
e. None of the above. |
|||||||||||||||
|
|||||||||||||||||||
64. What will happen if you forget to close a file opened for writing? |
|||||||||||||||||||
a. The program will not compile |
b. The program will terminate immediately with a run-time error. |
c. It is possible
that not everything you wrote to that file is saved to disk. |
d. No file will be created (not even an empty one). |
e. There is no need to close a file opened for writing. |
|||||||||||||||
|
|||||||||||||||||||
program FoodBill; type DeptName = (Meat, Deli,
Produce, Grocery); AmountSpent = array[DeptName]
of real; ExpenseArray = array[50] of
AmountSpent; var SpentOn : AmountSpent; CustomerExpense :
ExpenseArray; function Total(var B: AmountSpent) : real var Dept: DeptName; Sum : real; begin { Total } Sum := 0; for Dept := Meat to Grocery
do Sum := Sum + B[Dept]; Total := Sum; end; { Total } begin { main } SpentOn[Meat] := 40.0; SpentOn[Deli] := 0.0; SpentOn[Produce] := 10.00; SpentOn[Grocery] := 45.00;
writeln(Total(SpentOn):0:2); end. { main } |
|||||||||||||||||||
|
|||||||||||||||||||
65. What is the output of the above code. |
|||||||||||||||||||
a. 95.00 |
b. 100.00 |
c. 40.00 |
d. 45.00 |
e. None of the above. |
|||||||||||||||
|
|||||||||||||||||||
66. In the above code the variable SpentOn is |
|||||||||||||||||||
a. An array of arrays |
b. A 1-dimensional
array |
c. A 3-dimensional array |
d. A 4-dimensional array |
e. Not an array |
|||||||||||||||
|
|||||||||||||||||||
67. In the above code the variable CustomerExpense is: |
|||||||||||||||||||
a. An array of arrays |
b. A 1-dimensional
array |
c. A 3-dimensional array |
d. A 4-dimensional array |
e. Not an array |
|||||||||||||||
|
|||||||||||||||||||
The next 3 questions refer to the below code: program ArrayStuff; type array_type : array[1..10]
of integer; var A, B : array_type; index, x, y, z : integer; begin for index := 1 to 10 do begin A[index] := index + 1; B[index] := index; end; { for } B := A; B[3] := B[3] 2; x := B[3]; y := A[3]; z := B[4]; { The questions will ask
what the value of x, y, z are at this point in the code } writeln(x, y, z); end. |
|||||||||||||||||||
|
|||||||||||||||||||
68. What is the value of x that is output? |
|||||||||||||||||||
a. 1 |
b. 2 |
c. 3 |
d. 4 |
e. 5 |
|||||||||||||||
|
|||||||||||||||||||
69. What is the value of y that is output? |
|||||||||||||||||||
a. 1 |
b. 2 |
c. 3 |
d. 4 |
e. 5 |
|||||||||||||||
|
|||||||||||||||||||
70. What is the value of z that is output? |
|||||||||||||||||||
a. 1 |
b. 2 |
c. 3 |
d. 4 |
e. 5 |
|||||||||||||||
|
|||||||||||||||||||
71. Given the below declarations: type Sample = record F1 :
integer; F2 :
char; end; var X1, X2 : Sample; Assume the following code is embedded in a working Pascal program: X1.F1 : = 5; X1.F2 := A; write(X1.F1, X1.F2, ---- ); X2 := X1; X2.F1 := 6; X1.F1 := 4; writeln(X2.F1, X2.F2); What is the output? |
|||||||||||||||||||
a. 6A ---- 5A |
b. 5A ---- 5A |
c. 5A ---- 6A |
d. 6A ---- 6A |
e. 5A ---- 4A |
|||||||||||||||
|
|||||||||||||||||||
72. Given the below declarations Type OneToFifty = 1..50; IloveTests =
array[1..50] of integer; Var A.B: IloveTests; X,Y: OneToFifty; Which of the following statements is not allowed? |
|||||||||||||||||||
a. A[X][Y] :=B[X][Y] |
b. A[B[X*Y]] :=X; |
c. A := B |
d. B:= A |
e. None of the
above |
|||||||||||||||
|
|||||||||||||||||||
73. If you have a two-dimensional array in ROW-MAJOR order, the inner loop should control which subscript? |
|||||||||||||||||||
a. Column
subscript |
b. Row subscript |
c. It can control either subscript |
d. It can control both subscripts |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
74. Which of the following words is NOT associated with pointers in Turbo Pascal? |
|||||||||||||||||||
a. Delete |
b. New |
c. Dispose |
d. Nil |
e. None of the above are associated with pointers |
|||||||||||||||
|
|||||||||||||||||||
75. Given the below declarations, which of the following Pascal Statements is valid? Type Date = Record Month:
1..12; Day:
1..31; Year:
integer; End; Info = Record Name:
array[1..20] of char; Birthday:
Date; End; Var D: Date; I: Info; |
|||||||||||||||||||
a.I.Birthday.Day:=40; |
b. D.Name:= 'Jim'; |
c.I.Birthday.Year.Month := 10; |
d. D.Date := 23; |
e. None of the
above |
|||||||||||||||
|
|||||||||||||||||||
The following code segment is for the next two questions. Type Ptr = ^node; Node = Record Name:
string[20]; Height:
integer; Next:
Ptr; End; Var MyNodePtr, p1, p2: ptr; MyNode: Node; |
|||||||||||||||||||
76. Which of the following statements would create a new dynamic variable of type Node? |
|||||||||||||||||||
a. New(Node); |
b. New(MyNode); |
c. New(MyNodePtr); |
d. New(^Node); |
e. New(Record); |
|||||||||||||||
|
|||||||||||||||||||
77. Assume that all pointers have been allocated and initialized correctly (point to something valid). Assume all other necessary initialization steps have been performed. Given the above code, which of the following statements would cause an error? |
|||||||||||||||||||
a. P1 := P2; |
b. MyNode.Height := 110; |
c. P1^.Height := 100; |
d. MyNode.Next := P1; |
e. None of the
above |
|||||||||||||||
|
|||||||||||||||||||
78. Which of the following compiler directives force the compiler to always give an error message for Array Index out of Range Error |
|||||||||||||||||||
a. {$R+} |
b. {$B+} |
c. {$R-} |
d. {$B-} |
e. None of the above |
|||||||||||||||
|
|||||||||||||||||||
79. When you type in a unit file (say temp) and save it to the disk, what would you save the file as before compiling it? |
|||||||||||||||||||
a. temp.pas |
b. temp.tpu |
c. temp.exe |
d. temp.bak |
e. temp.txt |
|||||||||||||||
|
|||||||||||||||||||
80. Which of the following is/are NOT valid array declarations? |
|||||||||||||||||||
a. x: array[2..11, 'r'..'w'] of char; |
b. x: array[5..22, boolean] of char; |
c. x:array[72..78,2.0..4.0] of char; |
d. Only b and c are
NOT valid. |
e. Statements a, b and c are all NOT valid. |
|||||||||||||||
|
|||||||||||||||||||
For next 3 assume the following definitions and declarations:
Type NodePointer=^Node;
Node=Record
Data:integer;
Next:NodePointer;
END;
Var
Ptr:NodePointer;
Cell:Node;
Which of the following are legal in Pascal?
(a).new(cell);
(b).new(node);
(c) .new(nodepointr);
(d).new(ptr);
(e).none of the above
(a).new(node.next);
(b).new(ptr^);
(c )..new(cell.data);
(d).new(ptr);
(e).both © and (d).
(a).cell.next=NIL;
(b).ptr:=nil;
(c ).writeln(ptr^.data);
(d).readln(cell.data);
(e).all of the above
next 4 Questions are based on the following piece of code:
Type Data=record
Value:integer;
End;
Var p1,p2:^data;
New(p1);
New(p2);
P1^.value:=10;
P2^.value:=20;
Writeln(p1^.value,p2^.value);
P1:=p2;
Writeln(p1^.value,p2^.value);
P1^.value:=30;
Writeln(p1^.value,p2^.value);
P2^.value:=40;
Writeln(p1^.value,p2^.value);
What is the first line of output?
(a).1010
(b).1020
(c ).2020
(d).2010
(e).1030
What is the second line of output?
(a).1010
(b).1020
(c )..2020
(d).2010
(e).1030
What is the third line of output?
(a).3010
(b).3020
(c ).3030
(d).2030
(e).1030
What is the fourth line of output?
(a).3040
(b).4030
(c ).3030
(d).4040
(e).4020
Which of the following are ordinal types?
1.Boolean
2.String
3.Real
(a). 1
(b). 2
(c ). 3
(d). 1 & 2
(e). 1,2&3
What is the output of the following code fragment?( I is of type integer and ord(A) is 65)
for I:=1 to 5 do
write(chr(ord(A) + I));
(a). ABCDEF
(b). BCDEFG
(c ).656676869
(d).66677983
(e).none of the above
Which of the following are true?
1.Enumerated type variables can be used in assignment statements
2.All ordinal types can be used in readln statements
3.A subrange type contains a subrange of values of any data type
(a). 1
(b). 2
(c ). 3
(d).2 & 3
(e).All of the above
If low and high are integers and low<high then the number of elements in array A[low..high] of integer is
(a).high-low
(b).high+low
(c ).high-low-1
(d).high-low+1
(e).none of the above
Which of the following is true?
(a).The size of an array may be dynamically changed
(b).A function may return an array value
(c ).We should always pass an array as a formal value parameter
(d).We may pass an array to a procedure using the array name only
(e).An array may be declared to a maximum of three dimensions
Use the following piece of code for next 3 questions
{$R+}
program exam3;
const
MAX:=6;
Type
Indextype:=1..5;
Arraytype=array[indextype] of char;
Var
Count:integer;
Message:arraytype;
Begin
Message[1]:=h;
Message[2]:=e;
Message[3]:=l;
Message[4]:=l;
Message[5]:=o;
Message[6]:=!;
For count:=1 to MAX do
Write(message[count]);
End.
What is the output of the program?
(a).hello
(b).hello!
(c ). Hell!
(d).subscript range error
(e).none of the above
message can be best described as:
(a).an array of arrayType elements
(b).an array of char elements
(c ).an array of indextype elements
(d).an array of integer elements
(e).none of the above
The type indextype can be best described as:
(a).an array of integers
(b).a subrange type
(c ).a subtype of the type integer
(d).an array of type arraytype
(e).none of the above
· Which of the following is NOT a legal Pascal variable
1. _ABC123
2. A_BC123
3. A_1BC23
4. 1_ABC23
5. A_B_C123
· Consider the following program segment
Read(N1, N2)
Read(N3)
If these two lines use the input
1 5 7
9 11
1. 1
2. 5
3. 7
4. 9
5. 11
· In which of the cases will the following statements produce an error if x:=y
1. Var x: integer;
Var y: real;
2. Var x: real;
Var y: integer;
3. Var x: real;
Var y: real
4. Var x: integer;
Var y: integer;
5. None of the above
· Which of the following is the output for the code below
Count:=0;
A=0;
B=1;
While (Count <=7) do
Begin
Count:=Count+1;
A:=A+B;
B:=A-B;
A:=A-B;
Write(A);
End.
· If you were asked to give someone a hardcopy of your source code, what would you give?
Program confuse;
Var
X,Y: integer;
{Procedure Swap places the value of U in Z and the value of Z in U}
Procedure Swap(Var U,V: Integer);
Var
Temp: Integer;
Begin
Temp:=U;
U:=Z;
Z=Temp;
End;
Begin {program}
X:=10;
Y:=20;
Confuse(X,Y);
Confuse(Y,X);
Confuse(X,Y);
Writeln(X = ,X);
Confuse(Y,X);
Writeln(Y = ,Y);
· The formal parameters of Procedure Swap are
· The output of the Program is
· What is the output of the following program segment?
Var X: Integer;
Begin
X:= 5 + 2 * 4;
Writeln(X);
End.
· What is the output of the following program segment?
X:= 10;
While (X>0) do
X:= X 4;
Writeln(X);
· A logical error is
Which of the following is NOT a legal Pascal Variable?
Which of the below declarations will cause the statement:
x := y;
to be in error?
x: char;
y: char;
x: real;
y: integer
x: real;
y: real;
x: integer;
y: integer;
x: integer;
y: real;
What is the output of the below code (assume it is embedded in a working program)
count := 0;
A := 1;
B := 1;
while (count <= 4) do
BEGIN
count := count + 1;
B := B + 1;
A := A + B - count;
write(A, ' '); { there is a space between those single quotes }
END;
If you were to give someone a hardcopy of your program, you would give them what?
The next 2 questions pertain to the following code (assume the code has NO syntax errors and compiles)
Program confuse;
VAR
x, y : integer;
{ Procedure swap places the value of U in Z and the value of Z in U }
Procedure Swap( Var U, Z : Integer);
VAR
Temp : Integer;
BEGIN
Temp := U;
U : = Z;
Z := Temp;
END;
BEGIN { Program }
x := 1;
y := 2;
swap( x, y);
swap( y, x);
swap( x, y);
write(' x = ', x);
swap( y, x);
writeln(' y = ', y);
END.
The FORMAL parameters of Procedure Swap are:
The output of the program is:
What is the output of the following program segment (assume embedded in working code)
VAR n : integer;
BEGIN
n := (7 DIV 3);
writeln(n);
END;
by computing the desired index (T / F).
What is the output of the following program segment? (assume embedded in working code)
x := 10;
while ( x > 0 ) do
x := x 4;
writeln(x, ' '); { There are several spaces between the single quotes }
Which of the following is NOT part of a procedure?
Which of the following identifiers represents a loop structure?
The rules of grammar for a programming language are called the
Which of the following is the assignment operator in Pascal?
In the following statement, which mathematical operation will be performed first (aka has the higher precedence) ?
X + Y * Z W / A;
Which identifier BEGINS a comment in Pascal?
<, =, >, <> are all examples of what in Pascal
Which following structures assists the programmer in top-down design?
What type of variable would the following value be assigned to: 'Why, hello there'
What would be the output of the following expression?
2 * 4 sqrt(abs(-16)) / 2
Given the following piece of code (embedded in a working program, assume no syntax errors):
VAR
score : integer;
grade : char;
BEGIN
grade := 60;
if (score >= 60) then
grade := 'p'
else
if (score <= 60) then
grade := 'f';
END.
What is the final value of grade (when the program ends)?
How many times is "Howdy" printed by the below code (assume embedded in working program with no syntax errors):
VAR
count : integer;
BEGIN
count := 5;
while (count > 1) do
begin
writeln('Howdy');
count := count 1;
end;
END.
Which of the following is NOT a reserved word in Pascal?
Which of the following statements is FALSE about comments in a program?
If the below statement was placed in a working a program (assume ch is type char):
ch := succ(G);
What is the value of ch after the above statement is executed?
If the below statement was placed in a working program (assume val is type integer):
val := ord( M ) ( ord( L ) );
What is the value of val after the above statement is executed?
Given the following type declaration:
type
BigOnes = 9..15;
The host type of BigOnes is:
In the statement: Score[ I + 3 ] := 5;
I + 3 is the:
In the statement: Score[ I + 3] := 5;
Score is the:
In the statement: Score[ I + 3] := 5;
5 is the:
Assume the following code is embedded in a working program.
Also assume that the array A has been properly declared and Element is type integer.
Sum := 0;
For Element := A[1] to A[100] do
Sum := Sum + Element; { This is the statement line referred to in the question }
How many times does the statement in the for loop get executed?
What is the output of the following program segment (as always, embedded in working program and no syntax errors):
writeln('Howdy, '); { there is a space before each ending single quote }
write('Good ');
writeln('Luck ');
Good
Luck
Luck
Good Luck
What is the output of the following program (assume no syntax errors)?
program SeeIt;
VAR
x, y : integer;
procedure Bob(x, y : integer);
BEGIN
writeln(x, , y, ); { There is a space between the single quotes }
END;
BEGIN { program }
x:= 1; y := 2;
Bob(x, y);
Bob(y, x);
END.
1 2
1 2
2 1
Which of the following is NOT a type of parameter (discussed in the book)?
What is the decimal (base ten) representation of the binary number: 00101 ?
What is the output of the following program? ( Assume no syntax errors )
program Just;
VAR
i : integer;
BEGIN
i := 0;
while (i < 5) do
writeln(i, ); { There is a space between the single quotes }
END.
What is the output of the following program? (Assume no syntax errors)
program YetAgain;
VAR
i, k : integer;
BEGIN
i := 1;
k := i + 1;
while (i <= k) do
begin
if (i MOD k = 0) then
i := k + 1
else
i := i + 1;
end; { of while }
writeln( i );
END.
The next TWO questions refer to the below code (assume no syntax errors):
program YetAgainAndAgain;
VAR
i, k : integer;
Procedure AddAndIncrement( var u : integer, z : integer );
begin
u := u + z;
z := z + 1;
end;
BEGIN
i := 3;
k := 2;
AddAndIncrement (i, k);
writeln( i, , k); { there is a space between the single quotes }
end; { of while }
What is the value of i that is output ?
What is the value of k that is output ?
What is the output of the following piece of code (assume embedded in working program and no syntax errors):
dollars := 9876.54321;
writeln( $, dollars:0:1);
Which of the following is NOT a correctly formed constant of type REAL (according to Pascal)?
Which of the following can never be used as a variable name in Pascal?