Inheritance Math 130 B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours B Smith: Consider using the example in SAMS Teach Yourself.

Slides:



Advertisements
Similar presentations
Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Advertisements

Introduction to Java 2 Programming
Math in Our Environment Created by:. List your location here Discuss the location and what math concepts are going to be in the problem.
CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
Class 15 - Overhead 11Object Oriented Programming Using C #define t_circle 1 #define t_rectangle 2 struct circle_shape {short type; double x,y; double.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
C++ Classes & Data Abstraction
Reusable Classes.  Motivation: Write less code!
Chapter 19 - Inheritance Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Inheritance Inheritance-2. Inheritance Rewriting point and circle classes class Point { protected: int x,y; public: Point(int,int); void display(void);
Esempi Ereditarietà1 // Definition of class Point #ifndef POINT_H #define POINT_H #include using std::ostream; class Point { friend ostream &operator
Copyright © 2002 W. A. Tucker1 Chapter 3 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Cover Sheet Cut and discard this bottom portion. Click Here to Replace and add your title To insert a picture: Click on Insert – Clip Art.
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.
EEM 480 Algorithms and Complexity by Assist. Prof. Dr. Emin Germen.
1 Inheritance Concepts n Derive a new class (subclass) from an existing class (base class or superclass). n Inheritance creates a hierarchy of related.
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.
CIS Mar-06. Quiz Write a class declaration (what would go in our Coord.h file…) for the class Coord that contains: –T private floating-point data.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 28P. 1Winter Quarter Inheritance and Overloading.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
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.
How to start Visual Studio 2008 or 2010 (command-line program)
Inheritance Building one object from another. Background Object-oriented programming is normally described has offering three capabilities Encapsulation:
Box 1Box 4Box 3Box 2 Box 5Box 8Box 7Box 6 My Shadow Box.
Inheritance One of the most powerful features of C++
Section 4 - Functions. All of the programs that we have studied so far have consisted of a single function, main(). However, having more than one function.
Chapter 10 Inheritance and Polymorphism
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
Computer Programming & Applications Mohamed Iqbal Pallipurath Lecture 02P. 1 Inheritance and Overloading Lecture 28.
Circumference Review. Review What is the relationship between a radius and a diameter? What does a circumference measure? What formulas do we use to calculate.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Lecture Notes – Inheritance and Polymorphism (Ch 9-10) Yonglei Tao.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
Double click here to add event title Double click here to add event date Double click here to add event time Double click here to add event location.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
From C to C++. What is C++ C++ is the work of Bjarne Stroustrup of AT&T Bell Labs. C++ is a mostly upward compatible extension of C that provides: A better.
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 19 – Inheritance – Part 1 Outline 19.1Introduction 19.2Inheritance: Base Classes and Derived Classes.
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.
1 Introduction to Object Oriented Programming Chapter 10.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Programming 2. Arrays & structure Arrays : allow you to define variables that combine several data items of the same kind. Structure : is another user.
CS 116 Object Oriented Programming II Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
A First Book of C++ Chapter 12 Extending Your Classes.
Seventh step for Learning C++ Programming CLASS Declaration Public & Private Constructor & Destructor This pointer Inheritance.
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.
Inheritance.
Class Inheritance Part I
Chapter 5 Classes.
CS250 Introduction to Computer Science II
Insert Presentation Title Here Insert Presentation Summary Here
Object Oriented Programming (OOP) LAB # 8
Instructor: Dr. Michael Geiger Spring 2017 Lecture 34: Inheritance
IS437: Fall 2004 Instructor: Dr. Boris Jukic
Testing with OO OO has several key concepts:
Virtual Functions Example
C++ Programming CLASS This pointer Static Class Friend Class
Insert Presentation Title Here Insert Presentation Summary Here
Please insert Title Please insert sub-title 1
_______ Book Title #1 Here Book Title #1 Book Title #3 Book Title #5 Book Title #2 Book Title #4 This is an example of what the QR Code will look.
Computer Science II for Majors
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Inheritance Math 130 B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours

2 Overview to cover  sub title also cover this is a box a callout this is code this is also code

3 Motivation Want to reuse code Don’t want to destroy the perfection of the existing code that we’ll reuse Goal: Use C++ classes without breaking the existing code Solution: Create a new class as a type of an existing class  inherit the features you’re interested in

4 Example 1 class Circle { protected: double radius; public: Circle(double = 1.0); // constructor double getArea(); };

5 // class implementation Circle::Circle(double r) // constructor { radius = r; } double Circle::getArea() // this calculates an area { return(PI * radius * radius); } Implementation

6 class Cylinder : public Circle // Cylinder is derived from Circle { protected: double length; // add one additional data member and public: // two additional function members Cylinder(double r = 1.0, double l = 1.0) : Circle(r), length(l) {} double getArea(); }; // class implementation double Cylinder::getArea() // this calculates a volume { return (length * Circle::getArea()); // note the base function call } class Circle { protected: double radius; public: Circle(double = 1.0); double getArea(); }; B Smith: Insert pictures here to show how one builds/inherits attributes from the other B Smith: Insert pictures here to show how one builds/inherits attributes from the other

7 Example 2 class one // the base class { protected: float a; public: one(float = 2); // constructor float f1(float); // a member function float f2(float); // another member function };

8 Implementation // class implementation one::one(float val) // constructor { a = val; } float one::f1(float num) // a member function { return(num/2); } float one::f2(float num) // another member function { return( pow(f1(num),2) ); // square the result of f1() }

9 class two : public one // the derived class { public: float f1(float); // this overrides class one's f1() }; // class implementation float two::f1(float num) { return(num/3); }

10 Driver Code int main() { one object_1; // object_1 is an object of the base class two object_2; // object_2 is an object of the derived class // call f2() using a base class object call cout << "The computed value using a base class object call is " << object_1.f2(12) << endl; // call f2() using a derived class object call cout << "The computed value using a derived class object call is " << object_2.f2(12) << endl; return 0; }

11 Example 3 class One // the base class { protected: float a; public: One(float = 2); // constructor virtual float f1(float); // a member function float f2(float); // another member function };

12 Implementation // class implementation One::One(float val) // constructor { a = val; } float One::f1(float num) // a member function { return(num/2); } float One::f2(float num) // another member function { return( pow(f1(num),2) ); // square the result of f1() }

13 class Two : public One // the derived class { public: virtual float f1(float); // this overrides class One's f1() }; // class implementation float Two::f1(float num) { return(num/3); }

14 int main() { One object_1; // object_1 is an object of the base class Two object_2; // object_2 is an object of the derived class // call f2() using a base class object call cout << "The computed value using a base class object call is " << object_1.f2(12) << endl; // call f2() using a derived class object call cout << "The computed value using a derived class object call is " << object_2.f2(12) << endl; return 0; }

15 Summary this is code