Содержание
- 2. CLASSES AND OBJECTS The main purpose of C++ programming is to add object orientation to the
- 3. CLASS ACCESS MODIFIERS Data hiding is one of the important features of Object Oriented Programming which
- 4. CLASS ACCESS MODIFIERS class Base { public: // public members go here protected: // protected members
- 5. THE PUBLIC MEMBERS EXAMPLE A public member is accessible from anywhere outside the class but within
- 6. THE PUBLIC MEMBERS EXAMPLE CON… // Member functions definitions double Line::getLength(void) { return length ; }
- 7. THE PUBLIC MEMBERS EXAMPLE CON… // Main function for the program int main( ) { Line
- 8. THE PRIVATE MEMBERS A private member variable or function cannot be accessed, or even viewed from
- 9. THE PRIVATE MEMBERS EXAMPLE #include using namespace std; class Box { public: double length; void setWidth(
- 10. THE PRIVATE MEMBERS EXAMPLE CON… void Box::setWidth( double wid ) { width = wid; } int
- 11. THE PROTECTED MEMBERS EXAMPLE A protected member variable or function is very similar to a private
- 12. THE PROTECTED MEMBERS EXAMPLE CON… class SmallBox:Box // SmallBox is the derived class. { public: void
- 13. THE PROTECTED MEMBERS EXAMPLE CON… void SmallBox::setSmallWidth( double wid ) { width = wid; } //
- 14. CLASS DEFINITIONS When you define a class, you define a blueprint for a data type. This
- 15. CLASS DEFINITIONS EXAMPLE class Box { public: double length; // Length of a box double breadth;
- 16. DEFINE C++ OBJECTS: Box Box1; // Declare Box1 of type Box Box Box2; // Declare Box2
- 17. ACCESSING THE DATA MEMBERS #include using namespace std; class Box { public: double length; // Length
- 18. ACCESSING THE DATA MEMBERS CON… int main( ) { Box Box1; // Declare Box1 of type
- 19. ACCESSING THE DATA MEMBERS CON… // box 2 specification Box2.height = 10.0; Box2.length = 12.0; Box2.breadth
- 20. CLASS MEMBER FUNCTIONS A member function of a class is a function that has its definition
- 21. CLASS MEMBER FUNCTIONS CON… Method 1 class Box { public: double length; // Length of a
- 22. FULL EXAMPLE https://ideone.com/n9IX03
- 23. INHERITANCE “C++ is Multi Inheritance, unlike Java is Single inheritance”. Inheritance allows us to define a
- 24. BASE & DERIVED CLASSES A class can be derived from more than one classes, which means
- 25. FULL EXAMPLE Consider a base class Shape and its derived class Rectangle: https://ideone.com/dwJAOM
- 26. ACCESS CONTROL AND INHERITANCE A derived class can access all the non-private members of its base
- 27. TYPE OF INHERITANCE [ PUBLIC ] Public Inheritance: When deriving a class from a public base
- 28. TYPE OF INHERITANCE [ PROTECTED AND PRIVATE ] CON… Protected Inheritance When deriving from a protected
- 29. MULTIPLE INHERITANCES EXAMPLE https://ideone.com/yFSOrV
- 30. FUNCTION OVERLOADING An overloaded declaration is a declaration that had been declared with the same name
- 31. POLYMORPHISM The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy
- 32. POLYMORPHISM [STATIC RESOLUTION ] Output of previous example: WHY !!! The reason for the incorrect output
- 33. POLYMORPHISM CON… class Shape { protected: int width, height; public: Shape( int a=0, int b=0) {
- 34. VIRTUAL FUNCTION A virtual function is a function in a base class that is declared using
- 35. PURE VIRTUAL FUNCTIONS class Shape { protected: int width, height; public: Shape( int a=0, int b=0)
- 36. DATA ENCAPSULATION Data encapsulation led to the important OOP concept of data hiding. Encapsulation is an
- 37. DATA ENCAPSULATION CON… C++ supports the properties of encapsulation and data hiding through the creation of
- 38. DATA ENCAPSULATION CON… class Box { public: double getVolume(void) { return length * breadth * height;
- 40. Скачать презентацию