SlideShare a Scribd company logo
Name – Rajveer Kaur
Section – N2
Roll No. - 115312
 Classes   in C++
 Objects
 Creating an object of class
 Special member functions
 Implementing class methods
 Accessing class members
 Destructors
 Instance variable methods
 Class abstraction
A  class definition begins with the keyword
  class.
 The body of the class is contained within a
  set of braces, { } ; (notice the semi-colon).


                    class class_name       Any valid
                    {                      identifier
                              ….
                    ….
                                       Class body (data member +
                    ….
                                       methods)
                    };
Objects

  • Objects have three
  responsibilities:
 What they know about themselves – (e.g., Attributes)
 What they do – (e.g., Operations)
What they know about other objects – (e.g., Relationships)




                                                    4
Defining Class
  A CLASS is a template (specification, blueprint)
  for a collection of objects that share a common
  set of attributes and operations.



                                 HealthClubMember
                                      attributes
Class                                 operations




Objects



                                                     5
 Member        access specifiers
    public:
        can be accessed outside the class directly.
          The public stuff is the interface.
    private:
        Accessible only to member functions of class
        Private members and methods are for internal use
         only.
 Thisclass example shows how we can
 encapsulate (gather) a circle information
 into one package (unit or class)
                                            No need for others classes to
    class Circle                            access and retrieve its value
                                            directly. The
    {
                                            class methods are responsible for
       private:                             that only.
              double radius;
       public:
              void setRadius(double r);    They are accessible from outside
              double getDiameter();        the class, and they can access the
              double getArea();            member (radius)
              double getCircumference();
    };
 Declaringa variable of a class type
 creates an object. You can have many
 variables of the same type (class).
    Instantiation
 Once  an object of a certain class is
  instantiated, a new memory location is
  created for it to store its data members
  and code
 You can instantiate many objects from a
  class type.
    Ex) Circle c; Circle *c;
 Constructor:
    Public function member
    called when a new object is created
     (instantiated).
    Initialize data members.
    Same name as class
    No return type
    Several constructors
        Function overloading
class Circle
                                       Constructor with no
{
                                       argument
   private:
          double radius;
   public:                             Constructor with one
          Circle();                    argument
          Circle(int r);
           void setRadius(double r);
          double getDiameter();
          double getArea();
          double getCircumference();
};
       Class implementation: writing the code
        of class methods.
       There are two ways:
    1.    Member functions defined outside class
            Using Binary scope resolution operator (::)
            “Ties” member name to class name
            Uniquely identify functions of particular class
            Different classes can have member functions with
             same name
         Format for defining member functions
         ReturnType
            ClassName::MemberFunctionName( ){
            …
         }
2.   Member functions defined inside class
        Do not need scope resolution
         operator, class name;
          class Circle
          {                                                    Defined
             private:                                          inside
                    double radius;                             class
             public:
                    Circle() { radius = 0.0;}
                    Circle(int r);
                    void setRadius(double r){radius = r;}
                    double getDiameter(){ return radius *2;}
                    double getArea();
                    double getCircumference();
          };
class Circle
{
   private:
          double radius;
   public:
          Circle() { radius = 0.0;}
          Circle(int r);
          void setRadius(double r){radius = r;}
          double getDiameter(){ return radius *2;}
          double getArea();
          double getCircumference();
};
Circle::Circle(int r)
{
   radius = r;
}
double Circle::getArea()
{
   return radius * radius * (22.0/7);
}
double Circle:: getCircumference()
{
   return 2 * radius * (22.0/7);
}
 Operators         to access class members
    Identical to those for structs
    Dot member selection operator (.)
        Object
        Reference to object
    Arrow member selection operator (->)
        Pointers
 Destructors
    Special member function
    Same name as class
        Preceded with tilde (~)
    No arguments
    No return value
    Cannot be overloaded
    Before system reclaims object’s memory
        Reuse memory for new objects
        Mainly used to de-allocate dynamic memory locations
 This   class shows how to handle time parts.
               class Time
               {
                   private:
                       int *hour,*minute,*second;
                   public:
                       Time();
                       Time(int h,int m,int s);
                       void printTime();
                       void setTime(int h,int m,int s);
                       int getHour(){return *hour;}
                       int getMinute(){return *minute;}
  Destructor           int getSecond(){return *second;}
                       void setHour(int h){*hour = h;}
                       void setMinute(int m){*minute = m;}
                       void setSecond(int s){*second = s;}
                       ~Time();
               };
Instance variables belong to a specific
instance.

Instance methods are invoked by an instance
of the class.
Class variables are shared by all the instances
of the class.

Class methods are not tied to a specific object.
Class constants are final variables shared by all
the instances of the class.
 The   scope of instance and class variables is
    the entire class. They can be declared
    anywhere inside a class.
    The scope of a local variable starts from its
    declaration and continues to the end of the
    block that contains the variable. A local
    variable must be declared before it can be
    used.
 Use   this to refer to the current object.
 Usethis to invoke other constructors of the
 object.
Class abstraction means to separate class
implementation from the use of the class. The
creator of the class provides a description of the class
and let the user know how the class can be used. The
user of the class does not need to know how the class
is implemented. The detail of implementation is
encapsulated and hidden from the user.
THANKS

More Related Content

What's hot

How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
Fajar Baskoro
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
Rokonuzzaman Rony
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
Fajar Baskoro
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
class c++
class c++class c++
class c++
vinay chauhan
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
Sohanur63
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
Tareq Hasan
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
NainaKhan28
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
mcollison
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 

What's hot (20)

How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
 
Object and class
Object and classObject and class
Object and class
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
class c++
class c++class c++
class c++
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
C++ classes
C++ classesC++ classes
C++ classes
 

Viewers also liked

Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15
myrajendra
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
arnold 7490
 
Operators
OperatorsOperators
Operators
moniammu
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
arnold 7490
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
 
Template at c++
Template at c++Template at c++
Template at c++
Lusain Kim
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
arnold 7490
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
Rai University
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
Mayank Bhatt
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
arnold 7490
 
C++ Template
C++ TemplateC++ Template
C++ Template
Saket Pathak
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
arnold 7490
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
Sachin Sharma
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 

Viewers also liked (20)

Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
Operators
OperatorsOperators
Operators
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
Template at c++
Template at c++Template at c++
Template at c++
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Managing console
Managing consoleManaging console
Managing console
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
C++ Template
C++ TemplateC++ Template
C++ Template
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 

Similar to Classes and objects

C++ classes
C++ classesC++ classes
C++ classes
Zahid Tanveer
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
kailash454
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
kksupaul
 
Oo ps
Oo psOo ps
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
FALLEE31188
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
VGaneshKarthikeyan
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
VGaneshKarthikeyan
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.ppt
aasuran
 
Unit i
Unit iUnit i
Unit i
snehaarao19
 
oops-1
oops-1oops-1
oops-1
snehaarao19
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
Mohamad Al_hsan
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
ANURAG SINGH
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Lovely Professional University
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Classes
ClassesClasses
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
Rai University
 

Similar to Classes and objects (20)

C++ classes
C++ classesC++ classes
C++ classes
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Oo ps
Oo psOo ps
Oo ps
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.ppt
 
Unit i
Unit iUnit i
Unit i
 
oops-1
oops-1oops-1
oops-1
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Classes
ClassesClasses
Classes
 
Class and object
Class and objectClass and object
Class and object
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 

Classes and objects

  • 1. Name – Rajveer Kaur Section – N2 Roll No. - 115312
  • 2.  Classes in C++  Objects  Creating an object of class  Special member functions  Implementing class methods  Accessing class members  Destructors  Instance variable methods  Class abstraction
  • 3. A class definition begins with the keyword class.  The body of the class is contained within a set of braces, { } ; (notice the semi-colon). class class_name Any valid { identifier …. …. Class body (data member + …. methods) };
  • 4. Objects • Objects have three responsibilities:  What they know about themselves – (e.g., Attributes)  What they do – (e.g., Operations) What they know about other objects – (e.g., Relationships) 4
  • 5. Defining Class A CLASS is a template (specification, blueprint) for a collection of objects that share a common set of attributes and operations. HealthClubMember attributes Class operations Objects 5
  • 6.  Member access specifiers  public:  can be accessed outside the class directly.  The public stuff is the interface.  private:  Accessible only to member functions of class  Private members and methods are for internal use only.
  • 7.  Thisclass example shows how we can encapsulate (gather) a circle information into one package (unit or class) No need for others classes to class Circle access and retrieve its value directly. The { class methods are responsible for private: that only. double radius; public: void setRadius(double r); They are accessible from outside double getDiameter(); the class, and they can access the double getArea(); member (radius) double getCircumference(); };
  • 8.  Declaringa variable of a class type creates an object. You can have many variables of the same type (class).  Instantiation  Once an object of a certain class is instantiated, a new memory location is created for it to store its data members and code  You can instantiate many objects from a class type.  Ex) Circle c; Circle *c;
  • 9.  Constructor:  Public function member  called when a new object is created (instantiated).  Initialize data members.  Same name as class  No return type  Several constructors  Function overloading
  • 10. class Circle Constructor with no { argument private: double radius; public: Constructor with one Circle(); argument Circle(int r); void setRadius(double r); double getDiameter(); double getArea(); double getCircumference(); };
  • 11. Class implementation: writing the code of class methods.  There are two ways: 1. Member functions defined outside class  Using Binary scope resolution operator (::)  “Ties” member name to class name  Uniquely identify functions of particular class  Different classes can have member functions with same name  Format for defining member functions ReturnType ClassName::MemberFunctionName( ){ … }
  • 12. 2. Member functions defined inside class  Do not need scope resolution operator, class name; class Circle { Defined private: inside double radius; class public: Circle() { radius = 0.0;} Circle(int r); void setRadius(double r){radius = r;} double getDiameter(){ return radius *2;} double getArea(); double getCircumference(); };
  • 13. class Circle { private: double radius; public: Circle() { radius = 0.0;} Circle(int r); void setRadius(double r){radius = r;} double getDiameter(){ return radius *2;} double getArea(); double getCircumference(); }; Circle::Circle(int r) { radius = r; } double Circle::getArea() { return radius * radius * (22.0/7); } double Circle:: getCircumference() { return 2 * radius * (22.0/7); }
  • 14.  Operators to access class members  Identical to those for structs  Dot member selection operator (.)  Object  Reference to object  Arrow member selection operator (->)  Pointers
  • 15.  Destructors  Special member function  Same name as class  Preceded with tilde (~)  No arguments  No return value  Cannot be overloaded  Before system reclaims object’s memory  Reuse memory for new objects  Mainly used to de-allocate dynamic memory locations
  • 16.  This class shows how to handle time parts. class Time { private: int *hour,*minute,*second; public: Time(); Time(int h,int m,int s); void printTime(); void setTime(int h,int m,int s); int getHour(){return *hour;} int getMinute(){return *minute;} Destructor int getSecond(){return *second;} void setHour(int h){*hour = h;} void setMinute(int m){*minute = m;} void setSecond(int s){*second = s;} ~Time(); };
  • 17. Instance variables belong to a specific instance. Instance methods are invoked by an instance of the class.
  • 18. Class variables are shared by all the instances of the class. Class methods are not tied to a specific object. Class constants are final variables shared by all the instances of the class.
  • 19.  The scope of instance and class variables is the entire class. They can be declared anywhere inside a class.  The scope of a local variable starts from its declaration and continues to the end of the block that contains the variable. A local variable must be declared before it can be used.
  • 20.  Use this to refer to the current object.  Usethis to invoke other constructors of the object.
  • 21. Class abstraction means to separate class implementation from the use of the class. The creator of the class provides a description of the class and let the user know how the class can be used. The user of the class does not need to know how the class is implemented. The detail of implementation is encapsulated and hidden from the user.