
AP Computer Science
Exam Quick Reference
(Please Note: The A exam will not include apstack and apqueue)
Quick Reference for apstring
extern const int npos; // used to indicate not a position in the string // public member functions // constructors/destructor apstring(); // construct empty string "" apstring(const char * s); // construct from string literal apstring(const apstring & str); // copy constructor ~apstring(); // destructor // assignment const apstring & operator= (const apstring & str); // assign str const apstring & operator= (const char * s); // assign s const apstring & operator= (char ch); // assign ch // accessors int length() const; // number of chars int find(const apstring & str) const; // index of first occurrence of str int find(char ch) const; // index of first occurrence of ch apstring substr(int pos, int len) const; // substring of len chars, starting at pos const char * c_str() const; // explicit conversion to char * // indexing char operator[ ](int k) const; // range-checked indexing char & operator[ ](int k); // range-checked indexing // modifiers const apstring & operator+= (const apstring & str); // append str const apstring & operator+= (char ch); // append char // The following free (non-member) functions operate on strings // I/O functions ostream & operator<< ( ostream & os, const apstring & str ); istream & operator>> ( istream & is, apstring & str ); istream & getline( istream & is, apstring & str ); // comparison operators bool operator== ( const apstring & lhs, const apstring & rhs ); bool operator!= ( const apstring & lhs, const apstring & rhs ); bool operator< ( const apstring & lhs, const apstring & rhs ); bool operator<= ( const apstring & lhs, const apstring & rhs ); bool operator> ( const apstring & lhs, const apstring & rhs ); bool operator>= ( const apstring & lhs, const apstring & rhs ); // concatenation operator + apstring operator+ ( const apstring & lhs, const apstring & rhs ); apstring operator+ ( char ch, const apstring & str ); apstring operator+ ( const apstring & str, char ch );Quick Reference for apvector and apmatrix
template <class itemType> class apvector // public member functions // constructors/destructor apvector(); // default constructor (size==0) apvector(int size); // initial size of vector is size apvector(int size, const itemType & fillValue); // all entries == fillValue apvector(const apvector & vec); // copy constructor ~apvector(); // destructor // assignment const apvector & operator= (const apvector & vec); // accessors int length() const; // capacity of vector // indexing itemType & operator[ ](int index); // indexing with range checking const itemType & operator[ ](int index) const; // indexing with range checking // modifiers void resize(int newSize); // change size dynamically; can result in losing values template <class itemType> class apmatrix // public member functions // constructors/destructor apmatrix(); // default size is 0 x 0 apmatrix(int rows, int cols); // size is rows x cols apmatrix(int rows, int cols, const itemType & fillValue); // all entries == fillValue apmatrix(const apmatrix & mat); // copy constructor ~apmatrix( ); // destructor // assignment const apmatrix & operator = (const apmatrix & rhs); // accessors int numrows() const; // number of rows int numcols() const; // number of columns // indexing const apvector<itemType> & operator[ ](int k) const; // range-checked indexing apvector<itemType> & operator[ ](int k); // range-checked indexing // modifiers void resize(int newRows, int newCols); // resizes matrix to newRows x newCols // (can result in losing values)Quick Reference for apstack and apqueue
template <class itemType> class apstack // public member functions // constructors/destructor apstack(); // construct empty stack apstack(const apstack & s); // copy constructor ~apstack(); // destructor // assignment const apstack & operator = (const apstack & rhs); // accessors const itemType & top() const; // return top element (NO pop) bool isEmpty() const; // return true if empty, else false int length() const; // return number of elements in stack // modifiers void push(const itemType & item); // push item onto top of stack void pop(); // pop top element void pop(itemType & item); // combines pop and top void makeEmpty(); // make stack empty (no elements) template <class itemType> class apqueue // public member functions // constructors/destructor apqueue(); // construct empty queue apqueue(const apqueue & q); // copy constructor ~apqueue(); // destructor // assignment const apqueue & operator= (const apqueue & rhs); // accessors const itemType & front() const; // return front (no dequeue) bool isEmpty() const; // return true if empty else false int length() const; // return number of elements in queue // modifiers void enqueue(const itemType & item); // insert item (at rear) void dequeue(); // remove first element void dequeue(itemType & item); // combine front and dequeue void makeEmpty(); // make queue empty| C++ Information | AP Computer Science Main Menu |
This entire site protected by copyright. All rights reserved. By accessing and using this site, you agree to be subject to the "Terms and Conditions Governing Use and Access to College Board Online."