PIC10B/1 Winter 2014 Exam I Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-8 inclusive) 2. Examples/Homework 3. Textbook The midterm will test 1. Your ability to read a program and understand what it does 2. Your ability to debug a program 3. Your ability to write C++ code snippets to accomplish small tasks 4. Your ability to write an entire C++ program from scratch 5. Your understanding of the lecture notes, homework, examples, and homework readings Terms to know: inheritance derived class (subclass) base class (superclass) is a relationship has a relationship base class component of an object constructor intializer list hidden members public members protected members private members accessor (get) methods mutator (set) methods public inheritance protected inheritance 1
private inheritance polymorphism virtual function polymorphic collection of objects dynamic method binding Overriding an inherited member function data slicing dynamically created variables on the heap statically bound function (at compile time) dynamically bound function (at run time) extensible abstract class concrete class pure virtual member function interface modular friend of a class stream byte bit istream (input stream) object ostream (output stream) object fstream (file stream) object sstream (string stream) object istringstream (input string stream) object ostringstream (string stream) object operator operands operation operator overloading prefix operator postfix operator clone of a variable default constructor, conversion constructor, copy constructor code memory 2
static data memory stack memory heap memory function pointers pointer pointee static variable global variable wild (dangling) pointer NULL pointer allocate a variable deallocate a variable pass/return by reference pass/return by value delete a pointer memory leak dereferencing a pointer memberwise copying shallow copy deep copy assignment operator= calling object (*this) this pointer to calling object destructor managing heap memory the Big 3 : copy constructor, assignment operator, destructor 3
C++ libraries and identifiers in those libraries we have used so far: iostream std::cin std::cout std::endl std::istream fail() clear() get() unget() peek() ignore() eof() std::ostream put() fstream std::ifstream std::ofstream sstream std::istringstream std::ostringstream str() iomanip std::left std::right std::defaultfloat std::fixed std::scientific std::showpoint 4
std::setprecision std::setw string std::string assert.h assert vector std::vector cstdlib NULL rand() srand(int seed) cmath sqrt pow fabs ceil floor exp log log10 sin cos tan Things to know: How to define a function. Know the difference between arguments passed by value and arguments that must be passed by reference. How to define a class and implement member functions, constructors and destructor. 5
How to define a derived class that inherits publicly from its base class. How to define a derived class constructor and use an initializer list to construct the base class component using an appropriate constructor of the base class. How to use an initializer list to initialize object members. How to declare an object and access its members. Know the difference between a public, a protected, and a private member function or variable. Know what happens when assigning a base class object a derived class object (data slicing). Know what happens when assigning a base class pointer a derived class pointee. How the access level of inherited members changes in the derived class for public inheritance, protected inheritance, and private inheritance. How to achieve polymorphism and recognize/enable dynamic method binding in C++. How to override inherited methods and access the inherited version using the base class name and ::. How to obtain a polymorphic collection of objects. How to define a virtual function and understand that all subsequent overridden versions in derived classes are automatically virtual. 6
Know the difference between calling a virtual overridden method and a non-virtual overridden method using a base class pointer. How to define/recognize a pure virtual function. How to define/recognize an abstract class. How to derive concrete classes from an abstract class. Remember how to use an abstract class (declaring pointers okay. Cannot construct object of that type directly (only base class components of concrete subclass objects in constructor initializer lists). How to declare and define friend functions and friend classes of a class and understand what it means to be a friend of a class. How to overload operators as member functions, friends, and nonmember nonfriend functions. Know when one way is allowed and when it is not. Eg. ones involving assignment such as =, +=, -=, ++, -- must be member functions. Input >> and output << operators must be nonmembers or friends. Other ones such as +, -, *, == can be defined either way. Know how to define them either way (and know their signatures (how many parameters? Should parameters be passed by value or reference or const reference? What should be the operator s return type? )). Know how the expressions involving operators translate to function calls. Eg a += b; means a.operator+=(b); 7
Know the different signatures for prefix and postfix ++ and and how to define them. Understand C++ will never try to implitly convert the left operand into an object of the appropriate type (using a conversion constructor) if the operator is overloaded as a member function, but it will convert the right operand into an object of the appropriate type (provided there is an appropriate conversion constructor) in either case. How to declare a pointer and assign it a pointee. How to declare a function pointer variable or array of function pointers. How to dereference/use function pointers. How to recognize accessing a wild pointer. How to recognize/prevent a memory leak. How to pass pointers into functions as arguments and return pointers. How to use an array name as a pointer to the element at index 0. How to declare and initialize arrays and 2D arrays and access their elements. How to create and use vectors to store, organize, shuffle, and manipulate collections of objects, pointers, or values of the same type. How to create and deallocate dynamically allocated arrays. 8
How to declare variables on the heap and deallocate those variables using pointers. How to use the this pointer to access the calling object inside its member function, constructor, or destructor definition. How to use/recognize a static or global variable. Understand that you must initialize all variables before they are used. Know when a destructor is automatically called or when C++ tries to call one. How to define a copy constructor, destructor and assignment operator when an object needs to manage dynamic memory. How to read a text file using an ifstream. How to write or append to a text file using an ofstream. How to read various types of data into memory from a string source using an istringstream. How to write various types of data to a string value target using an ostringstream. How to compare char or string values using operators. C++ fundamental types short int long 9
unsigned short unsigned int unsigned long float double bool char C++ classes string concatenation operator + string and char orderings comparing string values using <, >, <=, >=, ==,!= member functions length substr insert erase replace find c_str() cin >>, cout <<, getline(cin, ) vector element access bracket operator[] member functions size capacity resize empty clear front back push_back pop_back 10
operators parenthesis () arithmetic +, -, *, /, % relational <, <=, >, >= comparison ==,!= logical &&,,! increment (prefix and postfix) ++ decrement (prefix and postfix) -- assignment =, +=, -=, *=, /=, %= input >> output << ternary (? : ) sizeof address of & dereferencing * arrow -> aka (* ). new delete delete [] casting static_cast<int>('a') escape sequences (char values) \n newline \t tab \r carriage return \\ backslash \" quotation mark \a ring system bell \0 null character control structures 11
selection if if/else if/else/else switch repetition while do-while for Horstmann s graphics lecture will NOT be covered. 12