Inheritance (2).

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
For(int i = 1; i
CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.

Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Functions Prototypes, parameter passing, return values, activation frams.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++ Karoly Bosa RISC SS2000.
Inheritance - Case Study TCP1201: 2013/2014. Case Study – Guessing Game Listed below is the code to play a guessing game using procedural programming.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
EC-241 Object-Oriented Programming
Inheritance zThe mechanism by which one class can inherit the properties of another. zIt allows a hierarchy of classes to be built, moving from the most.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
C++ Classes & Data Abstraction
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
1 Data Structures CSCI 132, Spring 2014 Lecture 15 Recursion.
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Union, bitfield, typedef, enum union nama_u{ }; union nama_u{ struct nama_s byte; }; enum{ }; Tipedef var BYTE.
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Single Right rotation (compare to RotateWithLeftChild page 148 text) void rotateRight(AVLNode *& curr) { AVLNode * kid = curr->left; curr->left = kid->right;
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.
Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class.
Inheritance in C++ Multiple Base Classes Inheritance By Nouf Aljaffan Reference: Learn C++ from the master, Schildt, second Ed.
Inheritance in C++ Multiple Base Classes Inheritance By: Nouf Aljaffan Edited by : Nouf Almunyif.
Passing arguments by value void func (int x) { x = 4; }... int a = 10;... func(a); cout
1 Inheritance Inheritance is a natural way to model the world in object-oriented programming. It is used when you have two types of objects where one is.
Topic 1 11/18/2015. Submitted By: Arslan Ali : Roll No: 6703 Ali Ahmad : Roll No: 6710 Ameer Moavia : Roll No: 6734 Abdul Manam : Roll No: 6738 Agha Waqas.
Inheritance Examples. Example Of Multiple Inheritance class personnel { protected: char name[30]; char addr[30]; char [30]; char birth_date[30];
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
Constructor in Inheritance. 2 Constructors are used to initialized object. In inheritance the base class contains default constructor then, the base class.
Class 15 - Overhead 1Object Oriented Programming Using C #include class telephone { public: telephone(char *number, int volume); int dial(char *outgoing_number);
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
NESTED CLASS. Apa itu nested class ? Nested class is a class defined inside a class, that can be used within the scope of the class in which it is defined.
C++ : Operator overloading example
Control Statement tsenghy.
Inheritance Concept of Inheritance . Types of Inheritance .
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Revision.
Presented By: Nazia Hossain Lecturer, Stamford University
לולאות קרן כליף.
Object Oriented Programming Language (OOP)
Random Number Generation
HYBRID INHERITANCE : AMBIGUITY REMOVAL
Inheritance.
Creation and Use of Namespaces
הרצאה 03 אבני היסוד של תוכנית ב- C
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
Anatomy of a Function Part 1
Code::Block vs Visual C++
CS1201: Programming Language 2
CS150 Introduction to Computer Science 1
Virtual Functions Polymorphism is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions.
class PrintOnetoTen { public static void main(String args[]) {
Multiple Base Classes Inheritance
CS1201: Programming Language 2
Arrays of Two-Dimensions
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
Pointers & Functions.
Anatomy of a Function Part 1
Text Files.
Presentation transcript:

Inheritance (2)

Hybrid Inheritance Apply two or more types of inheritance. Mahasiswa Ujian Tulis Ujian OR Hasil

#include “iostream.h” // Hybrid Inheritance class student { protected : int roll_number; public : void get_number(int a) { roll_number = a; }; void put_number(void) { cout << “Roll Number = “ << roll_number << “\n”; }; }; class test : public student { protected : float sub1; float sub2; public : void get_marks(float x, float y) { sub1=x; sub2=y; }; void put_marks(void) { cout << “Sub1 = “ << sub1 << “\nSub2 = “ << sub2; class result : public test { public : void display(void) { put_number(); put_marks(); cout << “Total = “ << sub1 + sub2 << “\n”; } void main() { result student; student.get_number(123); student.get_marks(85.6, 77.9); student.display(); }

Constructors in Derived Classes As long as no base class constructor takes any arguments, the derived class need not have a constructor function. But, if any base class contains a constructor with one or more arguments, then it is mandatory for the derived class to have a constructor and pass the arguments to the base class constructors. When both the derived class and base classes contain constructors, the base constructor is executed first and then the constructor in the derived class is executed. The constructors will be executed in the order in which they appear in the declaration of the derived class or in the order of inheritance.

#include "iostream.h" class a { public: a() {cout<<"menjalankan constructor a default\n";}; a(int i) {cout<<"constructor a 1 parameter " <<i<<endl;}; }; class c c() {cout<<"menjalankan constructor c default \n";}; c(int i) {cout<<"constructor c 1 parameter " <<i<<endl;}; class b : public a, public c b(int j, int k) : a(j), c(k) {cout<<"constructor b\n\n";}; b() : a(100), c(200) {cout<<"constructor b default\n\n";}; ~b() {cout<<"desrtuctor b\n";} void main() { b bebek(10,20); b baba; }