1988 APCS A Multiple Choice

This page contains the 35 A multiple choice questions from the 1998 Advanced Placement Exam in Computer Science. Not all formatting has been reproduced (particularly in code fragments). If you believe there is an error in the text, please report it to Stuart Reges. See the copyright notice at the end of this document.

  1. A program is being designed to enable users who are not computer experts to solve problems using a large file of geographic data: for example, to list the three longest rivers in Africa or to list the provinces of France. Of the following, which would be the most reasonable design for the user interface for such a program?
    1. Printing out a copy of the file
    2. Displaying the first screenful of the file, and then displaying the next screenful each time the user types a space
    3. Displaying a menu of general topics on the screen and having the user proceed to lower-level menus by typing a single character
    4. Prompting the user to type an integer code for the data wanted
    5. Offering the user an optional tutorial that is designed to increase the user's expertise with computers in general

  2. Which of the following is NOT likely to be done by a Pascal compiler?
    1. Checking that parameters passed to procedures are of the correct type
    2. Generating machine-code or some other low-level code
    3. Providing a program listing
    4. Finding all syntax errors
    5. Finding all infinite loops

  3. Which of the following statements about using a high-level language instead of a machine language is NOT true?
    1. As a general rule, programs written in a high-level language are m ore likely to be executable on machines produced by different manufacturers.
    2. Programs written in a high-level language are generally easier to read and understand than are programs written in machine language.
    3. Programs written in a high-level language generally run faster than do programs written in machine language.
    4. Programs written in a high-level language are generally shorter than are programs written in machine language.
    5. Programs written in a high-level language are generally easier to debug than are programs written in machine language.

  4. A procedure is to be written that will check arithmetic expressions to make sure that the number of left parentheses, NumLeft, equals the number of right parentheses, NumRight, in such an expression. Consider the additional variables Sum, Diff, and Prod used in the statements below.
      Sum := NumRight + NumLeft;
      Diff := NumRight - NumLeft;
      Prod := NumRight * NumLeft;
    
    Knowledge of the value of which variable defined above is sufficient to be able to decide whether an expression has the same number of right parentheses as left parentheses?
    1. NumLeft
    2. NumRight
    3. Sum
    4. Diff
    5. Prod

  5. If evaluating BBB has no side effects, under what condition(s) can the program segment
      while BBB do
        Block1
    
    be rewritten as
      repeat
        Block1
      until not BBB
    
    without changing the effect of the code?
    1. Under no conditions
    2. If executing Block1 does not affect the value of BBB
    3. If the value of BBB is true just before the segment is executed
    4. If the value of BBB is false just before the segment is executed
    5. Under all conditions

  6. Consider the following declarations.
      type
        IntArrayType = array[1..Many] of integer;
        StructureType = record
                          IntArray : IntArrayType;
                          Length : integer
                        end;
    
      function Search(Structure : StructureType; Key : integer) : integer;
      { Precondition: 0 < Structure.Length < Many                                           }
      {                                                                                     }
      { Postcondition: (1) Returns i such that 0 <= i <= Structure.Length.                  }
      {                (2) If positive i is returned, then Structure.IntArray[i] = Key.     }
      {                (3) If 0 is returned, then Key is not equal to Structure.IntArray[i] }
      {                    for all i <= Structure.Length.                                   }
        var
          Index : integer;
      begin
        Index := 1;
        with Structure do
          begin
            while (IntArray[Index] < Key) and (Index < Length) do
              Index := Index + 1;
            if IntArray[Index] = Key then
              Search := Index
            else
              Search := 0
          end
      end;
    
    Which of the following should be added to the precondition of Search?
    1. The value of Key appears at least once in Structure.IntArray.
    2. The value of Key does not appear twice in Structure.IntArray.
    3. Structure.IntArray is sorted smallest to largest.
    4. Structure.IntArray is sorted largest to smallest.
    5. Structure.IntArray is unsorted.

  7. A good reason for not using any var parameters in a function declaration is that
    1. var parameters are not permitted in a function
    2. var parameters take more space than value parameters
    3. array entries cannot be passed as var parameters
    4. var parameters in a function allow changes to variables within the scope of the function call
    5. var parameters cannot be passed to a local procedure within a function unless a forward declaration has been made

  8. Top-down programming is illustrated by which of the following?
    1. Writing a program in the top-down dialect of Pascal
    2. Writing a program without using goto's
    3. Writing the first lines of a program before writing the last lines
    4. Writing the program in terms of abstract operations and then refining those abstract operations
    5. Writing and testing the lowest-level routines first and then combining these routines to form appropriate abstract operations

  9. A list of integers can be stored sequentially in an array. The list can be maintained in sorted order. Maintaining the list in sorted order in an array leads to inefficient execution for which of the following operations?
    1. Inserting and deleting elements
    2. Printing the list
    3. Computing the average of the elements

    1. I only
    2. II only
    3. III only
    4. I and III only
    5. I, II, and III

  10. A used-car dealer wants to keep an inventory of the cars on a lot that can hold at most LotSize cars. The model, year, and color need to be recorded for each car. Assume that the following declarations are part of the program.
      type
        Model = (Sedan, Coupe, Liftback, StationWagon);
        Year  = 1960..1990;
        Color = (Red, Blue, Green, White, Brown, Black);
    
    Of the following, which indicates the best data structure for storing the inventory information?
    1.   CarRange = 1..LotSize;
        Inventory = record
                      m : Model;
      	        y : Year;
      	        c : Color;
      	        n : CarRange
      	      end;
      
    2.   Inventory = array[Model, Year, Color] of Boolean;
      
    3.   Inventory = array[Model, Year] of Color;
      
    4.   CarRange = 1..LotSize;
        Inventory = record
                      m : array[Model] of CarRange;
      	        y : array[Year] of CarRange;
      	        c : array[Color] of CarRange
      	      end;
      
    5.   CarRange = 1..LotSize;
        Inventory = array[CarRange] of record
                                         m : Model;
      	                           y : Year;
      	                           c : Color
                      	         end;
      

  11. An algorithm for searching a large sorted array for a specific entry x compares every fourth item in the array to x until it finds one that is larger than or equal to x. Whenever a larger item is found, the algorithm examines the preceding three entries. If the array is sorted smallest to largest, which of the following describes all cases when this algorithm might use fewer comparisons to find x than would a binary search?
    1. It will never use fewer comparisons.
    2. When x is very close to the beginning of the array
    3. When x is in the middle position of the array
    4. When x is very close to the end of the array
    5. It will always use fewer comparisons.

  12. If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates?
      while f(x, y, z) <> 0 do
        <some computation>
    
    1. x, y, and z are each increased during each iteration.
    2. x, y, and z are each decreased during each iteration.
    3. The sum of x, y, and z is decreased during each iteration.
    4. The value of f(x, y, z) is decreased during each iteration.
    5. The value of sqr(f(x, y, z)) is decreased during each iteration.

  13. The following program segment is intended to sum A[1] through A[N].
      Sum := 0;
      i := 0;
      while i <> N do
        begin
          Sum := Sum + A[i];
          i := i + 1
        end
    
    In order for this segment to perform as intended, which of the following modifications, if any, should be made?
    1. No modification is necessary.
    2. The segment Sum := 0; i := 0; should be changed to Sum := A[1]; i := 1;
    3. The segment while i <> N do should be changed to while i <= N do
    4. The segment Sum := Sum + A[i]; should be changed to Sum := Sum + A[i - 1];
    5. The segment i := i + 1 should be changed interchanged with Sum := Sum + A[i]

    Questions 14-15 refer to the following program segment.

      const
        Size = 10;
      type
        GridType = array[1..Size, 1..Size] of char;
    
      function YesOrNo(Grid : GridType;
                       Row,
                       Colm : integer;
                       Mark : char) : Boolean;
        var
          i, Count : integer;
          OK : Boolean;
      begin {YesOrNo }
        Count := 0;
        for i := 1 to Size do
          if Grid[i, Colm] = Mark then
            Count := Count + 1;
        OK := (Count = Size);
        Count := 0;
        for i := 1 to Size do
          if Grid[Row, i] = Mark then
            Count := Count + 1;
        YesOrNo := (OK or (Count = Size))
      end; {YesOrNo }
    
  14. Which of the following conditions on an array g of type GridType will by itself guarantee that
      YesOrNo(g, 1, 1, '*')
    
    will have the value true when evaluated?
    1. The element in the first row and first column is '*'.
    2. All elements in both diagonals are '*'.
    3. All elements in the first column are '*'.
    1. II only
    2. III only
    3. I and II only
    4. II and III only
    5. I, II, and III

  15. Which of the following best describes what the function YesOrNo does?
    1. Counts the occurrences of Mark in Grid and returns true when the count is less than Size.
    2. Determines whether there are exactly Size occurrences of Mark in Grid.
    3. Determines whether it is true that all entries in row Row are equal to Mark or all entries in column Colm are equal to Mark.
    4. Determines whether it is true that all entries in row Row and all entries in column Colm are equal to Mark.
    5. Counts the occurrences of Mark on the main diagonal of Grid and returns true when Count equals Size.

  16. Consider the following two program segments.
      {repeat loop}                          {for loop}
      i := First                             for i := First to Last do
      repeat                                   for j := 1 to i do
        writeln('repeat loop output');          writeln('for loop output')
        i := i + 1
      until i > Last
    
    If First = -1 and Last = 1, how many times will the output lines "repeat loop output" and "for loop output", respectively, be written?
    1. 2, 1
    2. 2, 6
    3. 3, 1
    4. 3, 3
    5. 3, 6

    Questions 17-18 refer to the following function.

      function WhatIsIt(x, n : integer) : integer;
      begin
        if n = 1 then
          WhatIsIt := x
        else
          WhatIsIt := x * WhatIsIt(x, n - 1)
      end;
    
  17. What value is returned by WhatIsIt(4, 4)?
    1. 8
    2. 16
    3. 24
    4. 64
    5. 256

  18. Which of the following is a necessary and sufficient condition for the function WhatIsIt to return a value if it is assumed that the values of n and x are small in magnitude?
    1. n > 0
    2. n ≥ 0
    3. n > 0 and x > 0
    4. xn and n > 0
    5. nx and n > 0

  19. All of the entries in the array a with position indices Spot to Last, inclusive, (SpotLast) are to be shifted one position so that a new entry can be inserted at a[Spot]. Which of the following statements correctly shifts the entries? (Assume that Last is less than the maximum index for a.)
    1.   for i := Spot to Last do
          a[i + 1] := a[i]	    
      
    2.   for i := Last downto Spot do
          a[i + 1] := a[i]	    
      
    3.   for i := Spot + 1 to Last do
          a[i + 1] := a[i]	    
      
    4.   for i := Last - 1 downto Spot do
          a[i + 1] := a[i]	    
      
    5.   for i := Spot to Last - 1 do
          a[i + 1] := a[i]	    
      

  20. procedure Wow(n : integer);
    begin
      if n > 1 then Wow(n div 2);
      write(n, ' ')
    end;
    
    The procedure call Wow(16) will yield as output which of the following sequences of numbers?
    1. 10 8 6 4 2
    2. 16 8 4 2 1
    3. 1 2 4 8 16
    4. 32 16 8 4 2
    5. 2 4 8 16 32

  21. Merging two sorted lists to yield a single sorted list requires which of the following?
    1. That the two lists be external files
    2. That recursive techniques be used
    3. That at least one list be stored in memory
    4. That nonrecursive techniques be used
    5. None of the above

  22. Consider the following declarations.
      const
        MaxNum = 5;
      type
        String = array[1..MaxNum] of char;
    
      procedure GetLine(var Line : String);
        var
          i : integer;
          ch : char;
      begin
        for i := 1 to MaxNum do
          Line[i] := '+';
        i := 0;
        while not eoln and (i < MaxNum) do
          begin
            read(ch);
            if ch in ['?', '#'] then
              case ch of
                '?' : i := 0;
                '#' : if i > 0 then
                        i := i - 1
              end
            else
              begin
                i := i + 1;
                Line[i] := ch
              end
          end { while }
      end;
    
    Assume an input line of
      A?B#C?DEF#GH##I
    
    Upon completion of procedure GetLine, Line is returned to the calling routine as
    1. EFGHI
    2. DEI++
    3. DEGH+
    4. DIGH+
    5. DEIH+

  23. If b is a Boolean variable, then the statement b := (b = false) has what effect?
    1. It causes a compile-time error message.
    2. It causes a run-time error message.
    3. It causes b to have value false regardless of its value just before the statement was executed.
    4. It always changes the value of b.
    5. It changes the value of b if and only if b had value true just before the statement was executed.

  24. Graphics commands, such as a command to position the cursor at an arbitrary position, are not part of standard Pascal. One good reason for this exclusion is that
    1. Pascal was designed for an educational environment in which drawing pictures is to be discouraged
    2. Pascal programs execute too slowly to produce worthwhile graphics output
    3. The data structures needed to support good graphics cannot be implemented in Pascal
    4. The graphics capabilities of output devices vary widely
    5. such commands can easily be defined in terms of the output procedures of standard Pascal

  25. During one iteration of the outer for loop of the program segment below, how many times is the body of the inner for loop executed?
      for i := 1 to n - 1 do
        for j := n downto i + 1 do
          if A]j - 1] > A[j] then
            begin
              Temp := A[j - 1];
              A[j - 1] := A[j];
              A[j] := Temp
            end;
    
    1. i + 1
    2. n - i + 1
    3. i - n + 1
    4. n(i - 1)
    5. n - i

  26. A questionnaire with 20 questions was given to 1,000 people between the ages of 20 and 49. The answer choices for each question were: agree, no opinion, and disagree. The designers of the questionnaire want to store in a computer the number of people who gave each answer to each question, broken down by the age group of the respondent. The age groups are 20-29, 30-39, and 40-49. The declarations below have been made.
      const
        NumQues = 20;
        NumPeople = 1000;
      type
        AnsType = (Agree, NoOpinion, Disagree, NoReply);
        AgeGroup = (Twenties, Thirties, Forties);
    
    Which of the following is an appropriate type declaration for storing the information?
    1.   SurveyType = array[1..NumQues, AnsType, AgeGroup] of integer;
      
    2.   SurveyType = array[1..NumPeople, AnsType, 20..49] of Boolean;
      
    3.   SurveyType = array[1..NumPeople, 1..NumQues] of AnsType;
      
    4.   SurveyType = array[1..NumQues] of AnsType;
        AgeType = array[AgeGroup] of integer;
      
    5.   TotalType = array[1..NumPeople, AgeGroup] of integer;
        AnswerType = array[1..NumQues] of AnsType;
      

    Questions 27-28 are based on the following block structure. (Assume there are no variable declarations other than the ones explicitly shown.)

      procedure p1;
      var
        a, b : real;
    
        procedure p2;
        var
          b : integer;
          c : char;
    
          procedure p3;
          var
            a : real;
            c : integer;
          begin { p3 };
            ...
          end { p3 };
        begin {p2}
          ...
        end {p2};
    
        procedure p4;
        var
          b : real;
        begin { p4 }
          ...
        end {p4 };
      begin { p1 }
        ...
      end { p1 };
    
  27. The variable a declared in procedure p1 can be used in the statement part of
    1. p1 only
    2. p1 and p2 only
    3. p1 and p4 only
    4. p1, p2, and p4 only
    5. p1, p2, p3, and p4

  28. Which of the following is true of the variable b if it is used in the body of p3?
    1. It is a variable of type real.
    2. It is a variable of type integer.
    3. It is an illegal reference because b is not declared in p3.
    4. Its value would depend on whether or not p4 has been called.
    5. None of the above

  29. Suppose Pascal did not support sets. Given a base set (universe) consisting of 8 known elements, subsets of that universe could be represented using all of the following EXCEPT
    1. An integer variable ranging between 0 and 28 - 1, inclusive
    2. A variable of an enumerated type with 8 elements
    3. an array of 8 elements
    4. 8 Boolean variables
    5. 8 integer variables

    Questions 30-31 are based on the following program.

      program Sample(output);
        var
          a, b : integer;
    
        procedure Proc(x, y, z : integer);
        begin
          y := y + 1;
          z := z + x
        end;
    
      begin
        a := 2;
        b := 3;
        Proc(a + b, a, a);
        write(a)
      end.
    
  30. What is printed by the program above?
    1. 2
    2. 3
    3. 5
    4. 7
    5. 8

  31. If the procedure heading
      procedure Proc(x, y, z : integer);
    
    were changed to
      procedure Proc(x : integer; var y, z : integer);
    
    what would be printed by the program?
    1. 2
    2. 3
    3. 5
    4. 7
    5. 8

  32. Consider the following function.
      function Mult(x, y : integer) : integer;
      { Precondition : x > 0          }
      {                               }
      { Postcondition : Returns x * y }
      begin
        if x = 1 then
          <statement 1>
        else
          <statement 2>
      end;
    
    Which of the following statement pairs properly completes the function?
          <Statement 1>               <Statement 2>
    
    1.   Mult := x * y	        <none>
      
    2.   Mult := y             Mult := Mult(x - 1, y + 1)
      
    3.   Mult := y             Mult := Mult(x - 1, y + y)
      
    4.   Mult := y             Mult := Mult(x - 1, y) + y
      
    5.   Mult := y             Mult := Mult(x - 1, y) * y
      

  33. Suppose that Grid is an n-by-n array of integers, and a procedure is to be used to reflect the entries across the main diagonal. (The main diagonal goes from the upper left corner to the lower right corner.) For example, if n = 3 and the array contained
        1  2  3
        4  5  6
        7  8  9
    
    the procedure would change it to
        1  4  7
        2  5  8
        3  6  9
    
    If Swap interchanges the values of its parameters, which of the following w9ill NOT have the desired effect?
    1.   for Row := 1 to n do
          for Colm := 1 to n do
            Swap(Grid[Row, Colm], Grid[Colm, Row])
      
    2.   for Row := 1 to n do
          for Colm := 1 to Row do
            Swap(Grid[Row, Colm], Grid[Colm, Row])
      
    3.   for Row := 2 to n do
          for Colm := 1 to Row - 1 do
            Swap(Grid[Row, Colm], Grid[Colm, Row])
      
    4.   for Row := 1 to n - 1 do
          for Colm := Row + 1 to n do
            Swap(Grid[Row, Colm], Grid[Colm, Row])
      
    5.   for Row := 1 to n - 1 do
          for Colm := Row to n do
            Swap(Grid[Row, Colm], Grid[Colm, Row])
      

  34. Consider two ways to code a procedure that repeatedly prints a character.
    1.   procedure PrintChars(ch : char; HowManyTimes : integer);
          var i : integer;
        begin
          for i := 1 to HowManyTimes do
            write(ch)
        end;
      
    2.   procedure PrintChars(ch : char; var HowManyTimes : integer);
          var i : integer;
        begin
          for i := 1 to HowManyTimes do
            write(ch)
        end;
      
    Which of the following is true concerning the choice of headers?
    1. Header I is preferable because it uses less memory space.
    2. Header I is preferable because it permits a call with an expression as an actual parameter.
    3. Header II is preferable because it avoids copying the value of HowManyTimes.
    4. Both headers are equally appropriate since the procedure bodies are the same.
    5. Both headers are equally appropriate since HowManyTimes is not changed in either procedure body.

  35. In a certain programming language, the syntax of the "multiple-assignment statement" is
      x1, x2 := Expr1, Expr2
    
    where x1 and x2 are integer variables and Expr1 and Expr2 are integer expressions whose evaluations have no side effect. This statement is executed as follows.
    1. The values of Expr1 and Expr2 are computed first.
    2. Then the value of Expr1 is assigned to x1 and the value of Expr2 is assigned to x2.
    The new statement is correctly implemented in Pascal by which of the following?
    1.   x1 := Expr1;
        x2 := Expr2
      
    2. MultiAssig1(x1, x2, Expr1, Expr2) where MultAssig1 is declared as:
        procedure MultAssig1(v1, v2, e1, e2 : integer);
        begin
          v1 := e1;
          v2 := e2
        end;
      
    3. MultiAssig2(x1, x2, Expr1, Expr2) where MultAssig2 is declared as:
        procedure MultAssig2(var v1, v2 : integer; e1, e2 : integer);
        begin
          v1 := e1;
          v2 := e2
        end;
      

    1. I only
    2. II only
    3. III only
    4. I and III
    5. II and III

The contents of this web page come from The 1988 Advanced Placement Examinations in Computer Science and Their Grading. The following copyright notice appears in that booklet and applies to the content of this page:

Copyright ©1989 by College Entrance Examination Board. All rights reserved.

College Board, Advanced Placement Program, and the acorn logo are registered trademarks of the College Entrance Examination Board.

Permission is hereby granted to any nonprofit organization or institution to reproduce this booklet in limited quantities for its own use, but not for sale, provided that the copyright notices be retained in all reproduced copies exactly as they appear in this booklet. This permission does not apply to any third-party copyrighted material that may be in this booklet.


Stuart Reges
Last modified: Thu Mar 13 01:41:13 PDT 2008