Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Exam Review Inheritance Template Functions and Classes

Similar presentations


Presentation on theme: "Final Exam Review Inheritance Template Functions and Classes"— Presentation transcript:

1 Final Exam Review Inheritance Template Functions and Classes
Exception Handling Namespaces Pointers and Dynamic Memory Management GUI Programming Style STL Containers (queue, pqueue, stack, vector, list)

2 Inheritance class DerivedClass : public BaseClass {
// inherits functions and data of BaseClass // accessibility of inherited characteristics influenced by // keywords: public, protected, and private } Be familiar with the concepts Terms associated with inheritance: base class, derived class, ISA, HASA, polymorphism, slicing, etc. Usage of BaseClass constructor in base initialization section Order of construction and destruction Overidding versus overloading and access to BaseClass functions with :: ISA relationships, especially in context with pointers to BaseClass Implications of static versus dynamic (i.e., virtual keyword) binding Relationship between pure virtual function and abstract base class

3 Template Classes and Functions
Be familiar with stylistic programming changes Inclusion of .cpp at tail of .h Elimination of .h inclusion in .cpp Templated Functions: be able to … Create template functions with single or multiple type parameters Recognize the implicit requirements of templated code i.e., determine what operations are required for types which instantiate the function Convert a non-templated function to a corresponding templated version Templated Classes: be able to … Created template class with single or multiple type parameters Accurately specify <T> syntax in .h and .cpp files Accurately instantiate templated classes in client code

4 Exception Handling Have familiarity with try … throw … catch structure and associated rules try { …. if (…) { throw object_or_literal_of_type; } } catch(type optionalParameter) { // this is the handler for this type // other handlers as required in order of specificity Understand control flow associated with exception handling Understand relationships with inherited types and exception handling Know what are trivial classes and how they are useful with exceptions Know how to pass information up the call stack via an exception type

5 Namespaces Create a namespace Use a namespace
With using directive: using namespace namesaceIdentifier; With using declaration: using namespaceIdentifier::thingInNamespace; Be familiar with use of :: and namespaces and relationship with using clauses Understand how using clauses are modified by scope rules

6 Pointers and Dynamic Memory
Be comfortable declaring and using pointers to any type, including user-defined types Be able to allocate heap memory for dynamic objects and arrays of objects Understand how to free dynamically allocated memory in program code, including destructors Understand the difference between deep and shallow copy semantics Be able to use pointers to navigate linked structures. Know how to write deep copy versions of the copy constructor and assignment operator

7 GUI-Style Programming
Be familiar with typical control flow (event handling) in GUI programs Understand terms typically associated with GUI programming, e.g., Top-level window, event handler, event, widget, etc. Most GUI libraries depend upon inheritance, so be familiar with concepts of GUI objects inheriting data members and overriding member functions

8 Consider the function findMax(), which operates on an int array.
You decide that you need to have the function operate on several other data types, including string, Apple, and Orange, so you want to convert findMax() into a template function. 1. Modify the code below for findMax()to make it into a template function. template<class T> int T findMax(int T myArray[ ], int size) { int T maxSoFar; maxSoFar = myArray[0]; for (int i=1; i < size; i++) { if (myArray[i] > maxSoFar) { maxSoFar = myArray[i]; } return maxSoFar;

9 What function(s) must you ensure exist(s) for every type instantiated
with the function findMax()on the previous slide? > and = Now, assume you have an array of Apples, called theApples, which has numApples elements. Show how to use findMax() to find theBiggestApple in Apples. theBiggestApple = findmax(theApples, numApples);

10 4. Given the (unbolded) class definition for Pair below, modify the class (bolded) to make Pair a template class pairing two separate types. template <class T1, class T2> class Pair { public: Pair(int T1 first, int T2 second); int T1 getFirst ( ) const; int T2 getSecond( ) const; void setFirst (int T1 val); void setSecond(int T2 val); private: int T1 f; int T2 s; };

11 5. Write an implementation for the two-parameter constructor in its template form as it would appear in the .cpp file. template<class T1, class T2> Pair<T1, T2>::Pair(T1 ff, T2 ss) : f(ff), s(ss) {} 6. Write an implementation for the accessor function getFirst() in its template form as it would appear in the .cpp file. T1 Pair<T1, T2>::getFirst() const { return f; } 7. Write an implementation for the mutator function setSecond() in its template form it would appear in the .cpp file. void Pair<T1, T2>::setSecond(T2 ss){ s = ss; } 8. Declare a Pair object called p combining integers and strings. Pair<int, string> p;

12 For a code example of using namespaces, see the following link.


Download ppt "Final Exam Review Inheritance Template Functions and Classes"

Similar presentations


Ads by Google