Final Exam Review Inheritance Template Functions and Classes

Slides:



Advertisements
Similar presentations
Brown Bag #3 Return of the C++. Topics  Common C++ “Gotchas”  Polymorphism  Best Practices  Useful Titbits.
Advertisements

C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
Stacks and Queues & Inheritance 2014 Spring CS32 Discussion Jungseock Joo.
Classes: A Deeper Look Systems Programming.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Programming Languages and Paradigms Object-Oriented Programming.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Course Review Midterm Exam #
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Midterm Review CS1220 Spring Disclaimer The following questions are representative of those that will appear on the midterm exam. They do not represent.
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Inheritance, Polymorphism, And Virtual Functions Chapter 15.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.
Chapter -6 Polymorphism
Inheritance Initialization & Destruction of Derived Objects Protected Members Non-public Inheritance Virtual Function Implementation Virtual Destructors.
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
1 CS Programming Languages Class 22 November 14, 2000.
Overview of C++ Polymorphism
Classes - Part II (revisited) n Constant objects and member functions n Definition Form of Member Functions n friend functions and friend classes n Constructors.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Class Inheritance Inheritance as an is-a relationship Public derive one class from another Protected access Initializer lists in constructor Upcasting.
Chapter 16 Templates Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Design issues for Object-Oriented Languages
Chapter 2 Objects and Classes
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
C ++ MULTIPLE CHOICE QUESTION
Pointers and Dynamic Arrays
Introduction to Computers Computer Generations
CS 215 Final Review Ismail abumuhfouz Fall 2014.
7. Inheritance and Polymorphism
Andy Wang Object Oriented Programming in C++ COP 3330
Object-Oriented Programming (OOP) Lecture No. 45
Object-Orientated Programming
CS212: Object Oriented Analysis and Design
Chapter 2 Objects and Classes
Lecture 9 Concepts of Programming Languages
Java Programming Language
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Lists - I The List ADT.
Overview of C++ Polymorphism
CIS 199 Final Review.
A Deeper Look at Classes
Lecture 10 Concepts of Programming Languages
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
CECS 130 Final Exam Review Session
SPL – PS3 C++ Classes.
Lecture 9 Concepts of Programming Languages
Introduction to Classes and Objects
Presentation transcript:

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)

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

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

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

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

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

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

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;

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);

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; };

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;

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