Download presentation
Presentation is loading. Please wait.
Published byFelicity Norris Modified over 9 years ago
1
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming where - a system is considered as a collection of objects that interact together to accomplish certain tasks. Objects are entities that encapsulate data and procedures that operate on the data. In OOPS first a concept known as "Object Oriented Analysis (OOA)" is used to specify the objects in term of real world requirements, their behavior and interactions required. The next concept would be the "Object Oriented Design (OOD)" that converts these real-time requirements as a hierarchy of objects in terms of software development requirement. Finally OOPS is used to implement the requirements using the C++ programming language. The main purpose of object oriented programming is to simplify the design, programming and most importantly debugging a program. So to modify a particular data, it is easy to identify which function to use. To add additional features it is easy to identify where to add functions and its related data.
2
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming A Class : is a way to bind the data and its associated functions together. All the elements of a class are private by default, even elements can be declared as public or protected. An object is an instance of a class. Syntax: class class-name { access:specifier private data and functions } In the above syntax the every class has a unique name, the "access:specifier" can either private, public, protected. The "protected" is used when inhertinace is applied.
3
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Example : #include class dat { private: int sdata; public: void setdat( int a) { sdata =a; } void show( ) { cout << "\nSet data is " << sdata; } }; Result: Set Data is:1000 Set Data is:1245
4
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Example (cont.) In the above class example the "private" object "sdata" is used only within the function. But the functions "setdat", "show" are used in the main function since they are "public".
5
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Access Specifiers : defines the access rights for the statements or functions that follows it until another access specifier or till the end of a class. The three types of access specifiers are "private", "public", "protected". private: The members declared as "private" can be accessed only within the same class and not from outside the class. public: The members declared as "public" are accessible within the class as well as from outside the class. protected: The members declared as "protected" cannot be accessed from outside the class, but can be accessed from a derived class. This is used when inheritance is applied to the members of a class.
6
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Basic elements of Object oriented Following are the basic elements of Object oriented programming(OOPS) Object Classes Inheritance Dynamic Binding Polymorphism Message Passing Encapsulation
7
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Objects : Explanation Objects are instance of a class, that interact with each other at runtime. In OOPs, Objects are declared at the end of the class definition or after the "}" braces. They can be of any type based on its declaration In the following example "x" is an object of the class "Cube“ used to access the functions inside the class.
8
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Example #include class Cube { public: int cub( val) { r = val*val*val; return r; } void show() { cout << "The cube is::" << r; } private: int val, r; }x; Result: The cube is :: 8
9
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Classes : Explanation : has the data and its associated function wrapped in it. Classes are also known as a collection of similar objects or objects of same type. In the OOPs concept the variables declared inside a class are known as "Data Members" and the functions are known as "Member Functions". The Syntax : class class-name { private: variable declaration; function declaration; public: variable declaration; function declaration; };
10
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Example #include class Square { private: int side, a; public: int area( side) { a =side*side; return a; } void show() { cout << "The area is::" << a; } }; Result: The area is:: 100
11
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Example (cont. ) In the above OOPs example the class "square" has functions "area" and "show" to calculate the area of the square and to display the area. so all these are objects that are related to the class "Square".
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.