Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Copy of Brown and White Modern Photos Annual Report (3) (1)

Copy of Brown and White Modern Photos Annual Report (3) (1)

Published by hiranaseer35, 2020-06-12 16:17:48

Description: Copy of Brown and White Modern Photos Annual Report (3) (1)

Search

Read the Text Version

HIRA NASEER 2020 JUNE TROPER LAUNNA P1: Explaining the key features of OOP M1: Explain the importance of encapsulation, polymorphism and inheritance on OOP

CONTENTS CONTENTS | 02 P1: Introduction : Explaining the 03 main Key features of OOP languages that can be usable with 04 C++ 04 05 Classes 05 Objects 05 Data Abstraction 06 Inheritance 06 Encapsulation 07 Message Passing Polymorphism 07 How you do OOP programming with C++ ? 08 M1: Importance of Encapsulation, 09 Polymorphism and Inheritance 10 within OOP Encapsulation Polymorphism Inheritance

P1: INTRODUCTION PAGE | 03 Why choose Object Oriented Programming language over Procedural Programming Language?

BASIC CONCEPTS OF OOP PAGE| 04

PAGE | 05

PAGE | 06

How you do OOP programming with C++ ? M1: IMPORTANCE OF ENCAPSULATION, POLYMORPHISM AND INHERITANCE PAGE | 07

Encapsulation #include <iostream> This keyword means that they using namespace std; can be accessed only to the other members of this class, class Adder { and not by any other part of public: the program. This is one way encapsulation is achieved. // constructor Adder(int i = 0) { total = i; } // interface to outside world void addNum(int number) { total += number; } // interface to outside world int getTotal() { return total; }; private: // hidden data from outside world int total; }; int main() { Adder a; a.addNum(10); a.addNum(20); a.addNum(30); cout << \"Total \" << a.getTotal() <<endl; return 0; } When the code above is compiled and executed, it produces the following result: PAGE | 08 Total 60

On the right example \"add()\" is present in Addition class #include<iostream.> with the same name but with different signature or using namespace std; arguments. class Cal The Output of this is : 30 { public: 55 static int add(int a, int b) { Advantage of using Polymorphism : cout<<a+b; It is preferable to use polymorphism when referring to } something having many forms like those objects as well static int add(int a, int b, int c) as methods. Polymorphism allows us to code to an { interface that reduces coupling, increase re-usability, and return a+b+c; makes your code easier to read. } }; PAGE | 09 int main(void) { Cal C; cout<<C.add (10, 20)<<endI; cout<<C.add(12,20,23) ; return 0; }

Inheritance Here take the example of a base class Shape and its derived Rectangle as follows - When the code is compiled and executed, it produces the following output that is : PAGE | 10


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook