MCQ On Computer Science
MCQ On Computer Science
Copyright © 2001 by College Entrance Examination Board. All rights reserved. College Board,
Advanced Placement Program, AP, and the acorn logo are registered trademarks of the College
Entrance Examination Board.
Computer Science A: Sample Multiple-Choice Questions
Following is a representative set of questions. Questions marked with an
asterisk are also representative of AB examination questions.
void Test()
{
int u = 2;
int v = 3;
Myst(u, v);
cout << u << " " << v << endl;
}
1 AP Computer Science A
What is printed as a result of the call Test() ?
(A) 2 3
(B) 2 8
(C) 6 3
(D) 6 8
(E) 8 3
AP Computer Science A 2
3. Consider the following functions.
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III
3 AP Computer Science A
4. Consider the following function.
void Mystery(int n)
{
if (n >= 2)
{
Mystery(n / 3);
}
cout << n << " ";
}
(A) 0 27
(B) 1 3 9 27
(C) 3 9 27
(D) 27 0
(E) 27 9 3
AP Computer Science A 4
5. Consider the following function.
5 AP Computer Science A
6. Consider the following functions.
void Test()
{
apstring str("ha");
cout << Laugh(Laugh(str, 2), 3) << endl;
}
(A) ha
(B) ha ha
(C) ha ha ha
(D) ha ha ha ha ha ha
(E) Nothing will be output because a runtime error will occur.
AP Computer Science A 6
*7. Consider the following class declaration.
class TheaterTicket
{
public:
TheaterTicket();
void SetInfo(const apstring & date,
const apstring & location,
int seat);
// other public member functions not shown
private:
// not shown
};
TheaterTicket t1;
t1.SetInfo("May 5, 1999", "AA", 22);
7 AP Computer Science A
Questions 8-9 refer to the following class declaration.
class SalesPerson
{
public:
SalesPerson(); // constructor
private:
apvector<double> mySales;
double ComputeAnnualSales();
// Totals the sales for the last 12 months
};
AP Computer Science A 8
*10. A sequential search algorithm is used to determine whether a given
integer is stored in an array of 1,000 integers. In each of the following
cases, what is the maximum number of array items that might be
examined during a sequential search?
*11. The expression !((x > y) && (y <= 3)) is equivalent to which
of the following?
9 AP Computer Science A
*12. Consider designing a data structure to record information about post
office boxes using the following structure.
struct BoxInfo
{
int BoxNum;
int NumLetters; // number of letters currently
// in this box
};
AP Computer Science A 10
13. The following incomplete function is intended to return the index of
the first occurrence of the minimum value in the array A.
<condition> <statement>
11 AP Computer Science A
*Questions 14-15 rely on the following information.
class Person
{
public:
Person(); // constructor
private:
// not shown
};
Person P;
int k;
bool oddNum;
AP Computer Science A 12
*14. Which of the following code segments correctly sets oddNum
to true if person P has an odd number of children, and to
false otherwise?
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III
Which of the following best describes what happens when the loop
is executed?
AP Computer Science A 14
*17. Consider the following definitions.
(A) 0
(B) 1
(C) MAXITEMS - 1
(D) MAXITEMS
(E) MAXITEMS * 2
{
int j, k;
<body of Unique>
}
15 AP Computer Science A
Which of the following code segments can be used to replace
<body of Unique> so that function Unique satisfies its
postcondition?
(A) I only
(B) II only
(C) I and II only
(D) I and III only
(E) I, II, and III
AP Computer Science A 16