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.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Object-Oriented PHP (1)
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
C++ fundamentals.
Review of C++ Programming Part II Sheng-Fang Huang.
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.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ C++ Overview (I) What is Object Orientated Programming? Approach: Break problem into subgroups of related parts that take into account code and data;
Pointer Data Type and Pointer Variables
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Module 7: Object-Oriented Programming in Visual Basic .NET
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 9 Defining New Types. Objectives Explore the use of member functions when creating a struct. Introduce some of the concepts behind object-oriented.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Overview of Previous Lesson(s) Over View  Operator Overloading:  Operator overloading is a very important capability, it enables to make standard C++
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Overview of Previous Lesson(s) Over View .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows.  It.
Object-Oriented Programming in C++
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Programming in Java CSCI-2220 Object Oriented Programming.
Object-Oriented Programming in C++ More examples of Association.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Data Structures Lecture 2: Array Azhar Maqsood NUST Institute of Information Technology (NIIT)
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Virtual FunctionstMyn1 Virtual Functions A virtual function is declared in a base class by using the keyword virtual. A function that you declare as virtual.
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.
Introduction to Object-Oriented Programming Lesson 2.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Overview of Previous Lesson(s) Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons,
Overview of Previous Lesson(s) Over View 3  CLR Programming  Common Language Runtime (CLR) is a programming, that manages the execution of programs,
Object-Oriented Programming (OOP) and C++
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
A First Book of C++ Chapter 12 Extending Your Classes.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
Memory Management.
LESSON 18.
group work #hifiTeam
CIS 199 Final Review.
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
Computer Science II for Majors
Presentation transcript:

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 designed to represent something abstract, such as a complex number, which is a mathematical concept, or a truck, which is physical.  Cbox class 3

Over View.. 4

Over View… 5  Inheritance  Inheritance is an essential part of OOP  It is the process of creating new classes, called derived classes, from existing or base classes.  The derived class inherits all the capabilities of the base class & can also add its own functionality.

Over View… 6  Advantages of Inheritance  Reusability  Extensibility  Data hiding  Overriding

Over View... 7

Over View… 8  Strings  The string class type that is defined in the system namespace represents a string in C++/CLI.  String creation System::String^ saying(L"Many hands make light work.");

Over View… 9  Tracking Handles:  A tracking handle is a form of pointer used to reference variables defined on the CLR heap.  A tracking handle is automatically updated if what it refers to is relocated in the heap by the garbage collector.  Variables that reference objects and arrays on the heap are always tracking handles.

Over View… 10  Tracking references  A tracking reference is similar to a native reference, except that the address it contains is automatically updated if the object referenced is moved by the garbage collector.  Interior pointers  An interior pointer is a C++/CLI pointer type to which you can apply the same operation as a native pointer.

11

Contents  Inheritance  Protected Members  Access Levels  Friends Classes  Virtual Functions  Polymorphism  Pointer with Objects  References to Virtual Functions  CLR Programming  Functions  Variable number of Arguments  Arguments to main() 12

Protected Members 13  In addition to the public and private access specifiers for members of a class we can also declare members of a class as protected.  Within the class, the protected keyword has the same effect as the private keyword  Members of a class that are protected can only be accessed by member functions of the class, and by friend functions of the class.

Protected Members.. 14 class CBox { public: CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0): m_Length(lv), m_Width(wv), m_Height(hv) { cout < < endl < < "CBox constructor called"; } ~CBox() { cout << “CBox destructor called” << endl; } protected: double m_Length; double m_Width; double m_Height; };

Protected Members.. 15  Now, the data members are still effectively private and can’t be accessed by ordinary global functions.  They will still be accessible to member functions of a derived class.

Access Level 16  Members of a base class that are declared as private are never accessible in a derived class.  Defining a base class as public doesn’t change the access level of its members in the derived class.  Defining a base class as protected changes its public members to protected in the derived class.

Access Level.. 17

Class Members as Friends 18  Declaring function as a friend of a class, gives the friend function the privilege of free access to any of the class members.  We can also allow all the function members of one class to have access to all the data members of another by declaring it as a friend class.  Limitations:  Class friendship is not reciprocated.

Class Members as Friends 19  Limitations..  Making the “A ” class a friend of the class “B” does not mean that the “B” class is a friend of the “A” class.  If you want this to be so, you must add a friend declaration for the “B” class to the “A” class.  Class friendship is also not inherited.

Virtual Functions 20  Virtual means existing in appearance but not in reality.  When virtual functions are used, a program that appears to be calling a function of one class may in reality be calling a function of a different class.  Why virtual functions ?  Suppose you have a number of objects of different classes but you want to put them all in an array and perform a particular operation on them using the same function call.

Virtual Functions 21  For ex a graphics program includes several different shapes:  triangle  ball  square and so on.  Each of these classes has a member function draw() that causes the object to be drawn on the screen.  Now we have to make a picture by grouping a number of these elements together.  One approach is to create an array that holds pointers to all the different objects in the picture.

Virtual Functions 22  The array might be defined like this: shape* ptrarr[100]; // array of 100 pointers to shapes  To insert pointers to all the shapes into this array, an entire picture is drawn using a simple loop for(int j=0; j<N; j++) ptrarr[j]->draw();  Completely different functions are executed by the same function call.  If the pointer in ptrarr points to a ball, the function that draws a ball is called.  if it points to a triangle, the triangle-drawing function is called.

Polymorphism 23  This phenomena is called polymorphism, which means different forms.  The functions have the same appearance, the draw() expression, but different actual functions are called, depending on the contents of ptrarr.  Polymorphism is one of the key features of oop after classes and inheritance.

Polymorphism.. 24  For the polymorphic approach to work, several conditions must be met.  First, all the different classes of shapes, such as balls and triangles, must be descended from a single base class.  Second, the draw() function must be declared to be virtual in the base class.

Virtual Functions 25  Lets implement the Virtual phenomena to our same Cbox class …

Using Pointers with Objects 26  A pointer can be used to a base class type to store the address of a derived class object and also of a base class object.  We can use a pointer of the type “ pointer to base ” to obtain different behavior with virtual functions, depending on what kind of object the pointer is pointing to.  Lets see an ex..

Using Pointers with Objects.. 27

References with Virtual ()s 28  A function can be defined with a reference to a base class as a parameter or we can pass an object of a derived class to it as an argument.  When the function executes, the appropriate virtual function for the object passed is selected automatically.  Lets see an ex..

C++ / CLI Programming 29

Functions 30  For the most part, functions in a C++/CLI program work in exactly the same way as in a native program.  As we deal in handles and tracking references when programming for the CLR, not native pointers & references, so that introduces some differences.  Function parameters and return values in a CLR program can be value class types, tracking handles, tracking references, and interior pointers.

Functions.. 31  When a parameter is an array, there is no need to have a separate parameter for the size of the array because C++/CLI arrays have the size built into the Length property.  We cannot do address arithmetic with array parameters in a C++/CLI program as in native C++ program, so we use array indexing for this.  Returning a handle to memory we have allocated on the CLR heap is not a problem because the garbage collector takes care of releasing the memory when it is no longer in use.

Functions  The mechanism for accepting a variable number of arguments in C++/CLI is different from the native C++ mechanism.  Accessing command line arguments in main() in a C++/CLI program is also different from the native C++ mechanism.  Lets go deeper for these two points …

Variable Number of Arguments 33  The C++/CLI language provides for a variable number of arguments by allowing specification the parameter list as an array with the array specification. int sum(... array ^ args) { // Code for sum }  Accepts number of arguments

Variable Number of Arguments 34  Lets do it..

Arguments to main() 35  One parameter to the main() function in a C++/CLI program.  It is an array of elements of type String^.  Accessing and processing command - line arguments in a CLR program, for the time being boils down to just accessing the elements in the array parameter.  Lets do it …

Thank You 36