0% found this document useful (0 votes)
7 views

C++ Basics Presentation

The document provides an overview of Object-Oriented Programming (OOP) concepts in C++, including classes, objects, encapsulation, abstraction, and data hiding. It explains the structure of a class, how to create objects, and demonstrates encapsulation through examples. Additionally, it highlights the importance of data hiding to prevent accidental changes.

Uploaded by

riksohom3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C++ Basics Presentation

The document provides an overview of Object-Oriented Programming (OOP) concepts in C++, including classes, objects, encapsulation, abstraction, and data hiding. It explains the structure of a class, how to create objects, and demonstrates encapsulation through examples. Additionally, it highlights the importance of data hiding to prevent accidental changes.

Uploaded by

riksohom3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

BASICS of OOPS with C+

+ & Objects , Encapsulations ,


Classes
Abstraction

Name : Sohom Ghorai


Regd. No : 190301120001
B.Tech CSE , 3rd Sem
CUTM , BBSR
Classes & Objects
MIG
29 Class
Fighter HAL Tejas
Requirements :
Plane
Miraje 1.Attribute
2000 2.Functionalities
I Phone
X
Phon Google Pixel 2
e XL
Redmi Note 8 Pro

Class : A class in C++ is the building block, that leads to Object-


Oriented programming. It is a user-defined data type, which holds its
own data members and member functions, which can be accessed
and used by creating an instance of that class. A C++ class is like a
blueprint for an object.
Objects
An Object is an instance of a
Class.
Defining Class

Keywor User-defined
d name
class ClassName{
Access Specifier ; //can be public , private or
protected
Data Members ; //Variables to be used
Member Functions() //Methods to access data
members
{}
}; // class name ends
Declaring
with aObjects
semicolon
ClassName ObjectName ;
#include <iostream>
using namespace std;
Simple Example
class Phone{
string p_name;
string p_size;
public:
Phone(string name , string size){
p_name = name;
p_size = size;
}
void makeCall (){
cout << "Making Call using "<<p_name <<endl;
}

void receiveCall(){
cout << "Receiving Call using "<<p_name <<endl;
}

};
int main(){
Phone iphone("I Phone X","2000x500");
iphone.makeCall();
iphone.receiveCall();

Phone pixel("Google Pixel","3500x1500");


pixel.makeCall();
pixel.receiveCall();
return 0 ;
}
Encapsulation :
Encapsulation is a Object oriented Programming concept which talks
about binding together the data and the functions that manipulates
Base
those data .
#include <iostream> Data
Using namespace std ;
Function
Class Base {
int x;
public:
Class is an example of
void setX(int a){x=a;} Encapsualtion
int getX() {return X ;} >> If we have created some
}; class and have data member
Int main (){ and member function then it is
return 0; an example of encapsulation .
}
#include <iostream>
Using namespace std ;
Class Base {
public :
int x; Data
};
Function
Int main (){
Base b;
b.x = 10;
cout << b.x << endl;
return 0;
}
Abstracti
on :is it ?
What
It is an object oriented programming concept that talks about show only
necessary things

#include<iostream>
using namespace std;
class Rectangle{
Int ht , wd;
Public void set_val(int x , int y){ht = x ; wd = y;}
Int area (){return ht*wd;}
};
class Rocket{
Void fly() {……………….}
};
Int main(){
Rectangle obj ;
}
Data Hiding
:
What is it ?
It is an object oriented programming concept that hide data from user so that
accidental changes can be avoided .
#include<iostream>
#include<iostream> using namespace std;
using namespace std; class Rectangle{
class Rectangle{ public:
private: int ht , wd;
int ht , wd; public :
public : void set_val(int x , int y){ht = x ; wd = y;}
void set_val(int x , int y){ht = x ; wd = y;} int area (){return ht*wd;}
int area (){return ht*wd;} void setHeight (int height) {
void setHeight (int height) { if(height != 0 && height > 0) {ht =
if(height != 0 && height > 0) {ht = height;} height;}
} }
void setWidth (int width) { void setWidth (int width) {
if(height != 0 && height > 0) {wd = height;} if(height != 0 && height > 0) {wd =
} height;}
}
};
Int main(){ };
Rectangle obj ; Int main(){
obj. setHeight(3); Rectangle obj ;
obj. setWidth(2); obj. setHeight(3);
} obj. setWidth(2);

You might also like