Oop concept in c++ by MUhammed Thanveer Melayi
-
Upload
muhammed-thanveer-danish-melayi -
Category
Software
-
view
126 -
download
1
description
Transcript of Oop concept in c++ by MUhammed Thanveer Melayi
Disclaimer: This presentation is prepared by trainees of baabtra.com as a part of mentoring program. This is not official document of baabtra.com – Mentoring Partner
Oop concepts in c++
Muhammed Thanveer [email protected] Muhammed Thanveer MelayiMhammed Thnaveer.MLinkedin Profile
Click to add text
typing speed:25
What is oop concept
Object oriented programming is method of programming where a system is considered as a collection of objects that interact together to accomplish certain tasks.
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
basic elements of Object oriented programming(OOPS)
Class:When define a class, define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.syntaxclass class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names;
Object:This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object.
Example
// Header Files#include <iostream>#include<conio.h>using namespace std;// Class Declarationclass person{//Access - Specifierpublic://Varibale Declaration string name; int number;};//Main Functionint main(){ // Object Creation For Class person obj;//Get Input Values For Object Varibales cout<<"Enter the Name :"; cin>>obj.name; cout<<"Enter the Number :"; cin>>obj.number; //Show the Output cout << obj.name << ": " << obj.number << endl; getch(); return 0;}
Inheritance:One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class.
example#include <iostream> using namespace std; class Rectangle{ protected: float length, breadth; public: Rectangle(): length(0.0), breadth(0.0) { cout<<"Enter length: "; cin>>length; cout<<"Enter breadth: "; cin>>breadth; } }; /* Area class is derived from base class Rectangle. */ class Area : public Rectangle { public: float calc() {
return length*breadth; } };
/* Perimeter class is derived from base class Rectangle. */ class Perimeter : public Rectangle { public: float calc() { return 2*(length+breadth); } }; int main() { cout<<"Enter data for first rectangle to find area.\n"; Area a; cout<<"Area = "<<a.calc()<<" square meter\n\n"; cout<<"Enter data for second rectangle to find perimeter.\n"; Perimeter p; cout<<"\nPerimeter = "<<p.calc()<<" meter"; return 0; }
Five type inheritanceSingle inheritance(one derived class from one base class)Multiple (single derived from two or more base classes)Hierarchical(multiple ……from one base class)Multilevel(derived class from a class what inherited from other)Hybrid (combination of Hierarchical and Multilevel inheritance)
Data Abstraction: data abstraction is a process of representing the essential features without including implementation details.
Data Encapsulation::Encapsulation is the method of combining the data and functions inside a class. This hides the data from being accessed from outside a class directly, only through the functions inside the class is able to access the information.
Abstraction solves the problem in the design level.
Encapsulation solves the problem in the implementation level.
Abstraction is used for hiding the unwanted data and giving only relevant data.
Encapsulation is hiding the code and data into a single unit to protect the data from outer world.
Example of Encapsulationclass employee /* Encapsultaion*/ { private: char name[20]; int age; float salary; public: /*Data Hiding, Following functions access data */ void getemployee { cout<< "Enter name"; cin>>name; cout<<"Enter Age"; cin>>age; cout<< "Enter Salary"; cin>>salary; } void showemployee { cout<<"\n Name"<<name; cout<<"\n Age"<<age; cout<<"\n Salary"<<salary; } }; void main() {
/*Abstraction:- working defined in employee class*/
employee e1; e1.getemployee(); e1.showemployee(); }
Polymorphism:The ability to use an operator or function in different ways ,in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers to many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism.
Below is a simple example of the above concept of polymorphism:6 + 10
The above refers to integer addition.The same + operator can be used with different meanings with strings:
“Exforsys” + “Training”The same + operator can also be used for floating point addition:
7.15 + 3.78
Overloading:The concept of overloading is also a branch of polymorphism. An overloaded declaration is a declaration that had been declared with the same name as a previously declared declaration in the same scope, except that both declarations have different arguments and obviously different definition (implementation).
operator([parameters]) { Statements }
It is two type:Function overloadingmultiple definitions for the same function name in the same scope
Operators overloadingOverloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined
Example for function overloading
#include <iostream> using namespace std; class printData { public: void print(int i) { cout << "Printing int: " << i << endl; } void print(double f) { cout << "Printing float: " << f << endl; } void print(char* c) { cout << "Printing character: " << c << endl; } }; int main(void) { printData pd; // Call print to print integer pd.print(5);// Call print to print float pd.print(500.263); // Call print to print character pd.print("Hello C++"); return 0; }
Thank you
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course @ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode
Start up VillageEranakulam,Kerala, India.Email: [email protected]
Contact Us