Advanced Placement Computer Science: The C++ Subset

The subset of C++ used in Advanced Placement Computer Science courses is documented here. This document is only the C++ subset, it is neither a description of nor a curriculum for an APCS course. A detailed topic outline of the APCS courses is provided in the Advanced Placement Course Description for Computer Science, a publication of the College Board. A more detailed description and rationale for the subset is also accessible.

In the three-column format used in the subset description below, any feature or topic listed in the second (AB) column is specifically not part of the A course. The third (comment) column explains and elaborates on the topics listed in the first two columns.

Four levels of understanding are used in the topics outline: read, use, modify, and implement. For example, the outline says that APCS-A students should be able to "Read, use, and modify classes." This means that they should be able to read class declarations, use the classes in client programs they write, and modify a class implementation by adding a new member function or modifying an existing member function. APCS-A students are not expected to design and implement classes from scratch. When use modifies a language feature, as in "use const member functions," students are expected to be able to write programs that use the feature.

A special section, "Topics not Covered", includes features of C++ that are not part of the APCS C++ subset and therefore will not be tested on the C++ exam. This section is divided into three subsections. The first subsection lists language features that teachers may want to include in their courses, but that will not be tested on the APCS exams. The second subsection lists language features that we do not view as useful in the APCS courses. The third subsection lists language features that we view as dangerous; these features should be avoided.

Teachers and students are free to use language features in these "not covered" sections, but the features will not be tested using questions that are on the APCS examinations.

A and AB course AB course only Comment


Read, use, and modify classes Design and implement classes. APCS-A students read class declarations, write client programs, add/modify member functions.
Read and use constructors, including initializer lists. Implement constructors, copy constructors, destructor. Constructors should use initializer lists as opposed to assignments to data because sometimes initializers are required, so use them for uniformity.
Differentiate between public and private.
No public data are used in classes. Since inheritance is not part of APCS, there is no reason to use protected functions/data.
Read class definitions that include use of *this. Use, modify, and implement class member functions that include *this.
Implement overloaded functions, use overloaded operators. Implement overloaded operators, including operator = and operator << (but friend not used) Students will NOT be tested on recognizing that functions differing in return type only are overloaded incorrectly.
Use const member functions Recognize when to make a member function const and implement const member functions
Use AP string class
The AP string class is a limited, safe subset of the standard string class.
Use templated AP vector and matrix classes Use and re-implement templated AP stack and queue classes
Design and implement templated classes and functions
Differentiate interface and implementation of class (.h and .cpp file)
C++ permits the ideas to be treated separately.
Use and implement structs, use constructors in structs when appropriate Implement linked lists and trees using structs A struct is a class in which all data is public. Constructors facilitate dynamic creation of structs.

Properties of Language

Understand short circuit evaluation.
Boolean expressions such as (a && b) are evaluated left-to-right; expression evaluation stops when the value of the entire expression can be determined. This means that constructs such as
while (k < n && a[k] != key)
can be used safely.
Use built-in types: int, char, double, bool.
For compilers that do not use 32 bit integers, long int may be used, otherwise no modifiers short, long, signed, unsigned.
Use arithmetic operators +, -, *, /, % increment decrement operators ++,--, logical operators &&,||,!, relational operators ==,<, >, !=, <=, >=, assignment operators =, +=, -=, *=, %=, /=, indexing operator [], and insertion extraction for I/O <<, >>
Use ++ and -- only as shorthand for +=1 and -=1; do NOT use these operators in expressions like a[k++] = 0.
Use break.
Used in switch statements, can be used in loops. The continue statement will not be tested.
Use function syntax for typecasts, e.g., cout << double(x)/3
For some types, e.g., long int, another form of cast is necessary: (long int) x. When compilers support the static_cast< > operator it will be used.
Use pointers: operators *, ->, new, delete; NULL preferred to 0; use == and != with pointers The address of operator & is used to test for aliasing in operator =, but not used elsewhere.
Pointer arithmetic, pointers to functions, and pointer comparison using < and > will NOT be tested.
Use [][] in matrix class for indexing.
Reinforce vector of vectors and mimic notation for built-in arrays.
Use #include and #ifndef idiom in header files.
No other use of preprocessor; const variables used instead of #define
Use assert
An AP supplied function apassert() can be used in place of the standard function assert(). The AP function will take a string as a parameter in addition to a Boolean expression. It will come in two versions: one supporting exceptions and one calling the standard function abort().
Use escape sequences, \n, \t, \\, \',\"
Use value, reference, and const reference parameters.
Recognize that values returned by operator [] for string and vector can be assigned to, e.g., s[0] = 'a' is ok Read and use reference return types and understand the implications of returning reference to local variable No testing of reference return types for APCS-A students
Use the functions pow and sqrt from <math.h>.

Stream properties

Assume input data is "type-safe", e.g., when int expected int is read
Use cin, cout, <<, >>,endl
cerr not tested, but can be useful
Use ifstream, ofstream
students will use open, but it will not be tested since parameters to open may be compiler specific.
Use getline
getline() is a free function in the AP string class, consistent with the standard string class function getline.
Use istream &, ostream & as formal parameters.
Students should realize that different types of streams can be passed as arguments when formal parameter is istream &, but inheritance hierarchy of streams will not be tested.

NOT part of APCS C++ subset
not tested, but potentially useful

Useful for symbolic values, but will not be tested (in C++ enums do not support iteration over all values).
iomanip (but endl used)
Students and teachers will find manipulators useful in formatting output, but iomanip will not be tested.
stream member functions eof(), good(), bad(), fail(), ignore(), etc.
Use while (cin >> x) idiom, or test return value of getline for end of input.
string streams
Input string streams are useful for parsing lines of data, output string streams facilitate conversion to string values.
get(char &)
Useful for reading stream input one character at a time.
default parameters
Function overloading can be used instead.
More useful in C than in C++ when classes are used.
functions in <math.h>, e.g., fabs, sin, cos, tan, floor, ceil
Many programs require these functions, but their use will not be tested.
functions in <ctype.h>, e.g., isalpha, isdigit, islower, ispunct, isspace, isupper, tolower, toupper
Facilitates system independent testing and conversion of characters, but not tested.
constants in <limits.h>: INT_MAX, INT_MIN; constants in <float.h>, DBL_MIN, DBL_MAX
Can be useful, but will not be tested.
command line arguments, argc, argv[]
Can be useful, but will not be tested.

not tested

operators: comma, ?:, bitwise, sizeof
These operators are not essential.
Although there are occasions when goto can be useful, indiscriminate use is dangerous; goto is NOT part of the AP C++ subset.
reference variables
Reference parameters and reference return types are part of the AP C++ subset, but reference variables are not.
inline functions
Concerns with efficiency at the level of use of inline functions are not part of the AP course. In general, code will not appear in class declarations (defaulting to inline).
friend classes and functions
Use public Display/Print member function instead of overloaded operator << when overloaded operator << would require use of "friend".
Implicit promotion or conversion, especially in parameter passing, will not be tested.
While inheritance is a central theme of object oriented programming, this topic and its implementation in C++ are not part of the current AP C++ subset.
Not necessary in programs studied and implemented in AP courses.

troublesome and warned against

built-in arrays
No need for this given use of templated vector class. The built-in array type is fraught with problems, e.g., range checking, pointer similarity. Recognition of limitations makes built-in arrays an interesting topic for study
new[]/delete[] and malloc/free
No need for [], (except with built-in arrays) and use new/delete rather than malloc/free
scanf/printf, etc. NEVER used.
&, the address of operator
Used only in test for aliasing in operator =.

A rationale describing some of the features of the APCS C++ subset in more detail is accessible.