1.What are the differences between composition(“has a” relationship) and inheritance(“is a” relationship)? 2.What is a base class? 3.How to declare a derived.

Slides:



Advertisements
Similar presentations
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Advertisements

Chapter 14 Inheritance Pages ( ) 1. Inheritance: ☼ Inheritance and composition are meaningful ways to relate two or more classes. ☼ Inheritance.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
STL. What is STL? Standard Templates Library Templates are best used for –Defining containers for storing data –Some kinds of algorithms that work the.
Chapter 16 Templates. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Function Templates  Syntax, defining 
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Virtual Functions Fall 2008 Dr. David A. Gaitros
CSE 332: C++ Classes From Procedural to Object-oriented Programming Procedural programming –Functions have been the main focus so far Function parameters.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
Introduction to C++. Overview C++? What are references Object orientation Classes Access specifiers Constructor/destructor Interface-implementation separation.
Object Oriented Programming using C++. Overview Problem Solving Features of an OOL Basic Syntax Programming Paradigms.
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Polymorphism &Virtual Functions 1. Polymorphism in C++ 2 types ▫Compile time polymorphism  Uses static or early binding  Example: Function and operator.
Inheritance CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CE Further Programming Concepts in C++ Lecture 5 Inheritance & Polymorphism.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Inheritance. Lecture contents Inheritance Class hierarchy Types of Inheritance Derived and Base classes derived class constructors protected access identifier.
Computing IV Singleton Pattern Xinwen Fu.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Object Oriented Programming in C++ Chapter 6 Inheritance.
Object-Oriented Programming in C++ More examples of Association.
C++ Review Part 1: Mechanics Part 2: Basics Part 3: References Part 4: Const Part 5: Inheritance Part 6: Libraries Acknowledgement: Adapted from: Brown.
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Inheritance  Virtual Function.
Advanced C++ Topics Chapter 8. CS 308 2Chapter 8 -- Advanced C++ Topics This chapter describes techniques that make collections of reusable software components.
Understanding Polymorphism tMyn1 Understanding Polymorphism Polymorphism requires the use of derived classes. It always involves the use of a pointer to.
Inheritance Initialization & Destruction of Derived Objects Protected Members Non-public Inheritance Virtual Function Implementation Virtual Destructors.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
Classes Sujana Jyothi C++ Workshop Day 2. A class in C++ is an encapsulation of data members and functions that manipulate the data. A class is a mechanism.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Chapter 16 Templates Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Polymorphism & Virtual Functions 1. Objectives 2  Polymorphism in C++  Pointers to derived classes  Important point on inheritance  Introduction to.
MAITRAYEE MUKERJI Object Oriented Programming in C++: Hierarchy / Inheritance.
CSC 143 O 1 CSC 143 Inheritance and Object Oriented Design.
1 CSE 2341 Object Oriented Programming with C++ Note Set #12.
MAITRAYEE MUKERJI Object Oriented Programming in C++
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.
Motivation for Generic Programming in C++
C ++ MULTIPLE CHOICE QUESTION
CS 3370 – C++ Object-oriented Programming
Advanced Program Design with C++
CS3340 – OOP and C++ L. Grewe.
Polymorphism &Virtual Functions
Polymorphism.
Polymorphism & Virtual Functions
Advanced C++ Topics Chapter 8.
Starting Out with C++ Early Objects Eighth Edition
C++ Classes C++ Interlude 1.
PRG 218 Week 5 Individual Assignment Coding: Derived Classes Please click here to buy ( (
group work #hifiTeam
Polymorphism Lec
C++ Functions, Classes, and Templates
Learning Objectives Inheritance Virtual Function.
Virtual Functions Department of CSE, BUET Chapter 10.
Inheritance: Polymorphism and Virtual Functions
Chapter 8: Class Relationships
Standard Template Library
Final Exam Review Inheritance Template Functions and Classes
Computer Science II for Majors
Presentation transcript:

1.What are the differences between composition(“has a” relationship) and inheritance(“is a” relationship)? 2.What is a base class? 3.How to declare a derived class? 4.What are the differences of the qualifiers (public, protected, private) when derive from a base class? class Person //base class { protected: string name; }; class Imployee1: public Person { string getName(){return name;} … }; class Imployee2: protected Person { string getName(){return name;} … }; class Imployee3: private Person { string getName(){return name;} … };

5. How does a derived class’s constructor call base class’s constructor? 6. How about destructors? 7. In what order are the constructor called? 8. In what order are the destructors called? 9. What is member function redefinition in class inheritance? 10. What is “name hiding” in function redefinition? 11. What are the differences between the redefined functions and virtual functions? class Shape //base class { public: virtual void setPosition(int x, int y) { position = Point(x, y); } }; class Rectangle: public Shape { public: virtual void setPosition(int x, int y) { position = Point(x*2, y*2); } }; int main() { Rectangle r; Shape &s = r; s.setPosition(2, 4); cout << r.getArea() << endl; //output? cout << s.getArea() << endl; //output? return 0; }

12. Late binding and early binding 13. Virtual Destructor. 14. What is the output of the following program? class A { ~A() { count << "A destructor\n" } }; class B: public A { virtual ~B() { count << “B destructor\n" } }; class C: public B { ~C() { count << “C destructor\n" } }; class D: public C { virtual ~D() { count << “D destructor\n" } }; int main() { C cClass; A * rBase = &cClass; delete rBase; return 0; }

15. How to declare a pure virtual function? 16. How to create an object of a class that include a pure virtual function? 17. What are the potential problems of multiple inheritance? 18. How to declare a template function? 19. How to declare a template class? 20. How to define the member functions of a template class? 21. Write a template function based on the swap function below. void swap(char& var1, char& var2) { char temp; temp = var1; var1 = var2; }

22. STL Vector. What are size and capacity of a vector class? 23. How to set capacity of a vector? 24. What happens if the size reaches the capacity of the vector? 25. What does the following code do? … vector v; vector ::iterator it; for (it = v.begin(); it != v.end(); v++) { *it = 0; } …

#include using namespace std; // function name: findName // find the target string in the input list // and returns the iterator of the list element list ::iterator& findName(list input, string target); int main() { list nameList; nameList.push_back("John"); nameList.push_back("Jack"); list ::iterator& it = findName(nameList, "John"); } //define findName function here 26. Implement a function described in the following code 27. Open a file-stream. Read a file, “readme.txt” from the directory “textfiles” under current directory. Finally, close the filestream.