Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Basic Of C++ , Classes and Objects




            Presented By:
         Shashank Srivastava


                       31 July,2012 onwards
Structure of a Program




2                            16 August 2012
Structure of a Program
     #include
     <iostream>


    - Lines beginning with a hash sign (#) are directives
      for the preprocessor.
    - In this case the directive #include<iostream> tells
      the preprocessor to include the iostream standard
      file.
    - This specific file (iostream) includes the declarations
      of the basic standard input-output library in C++.


3                                                  16 August 2012
Structure of a Program
     using namespace
     std;


    - All the elements of the standard C++ library are declared
      within what is called a namespace, the namespace with
      the name std.
     int main()



      -    This line corresponds to the beginning of the definition of the
      main function.
       - The main function is the point by where all C++ programs start
      their execution, independently of its location within the source code.
4                                                               16 August 2012
Structure of a Program
     cout<<“Hello World”;


       cout is the name of the standard output stream in C++, and the
      meaning of the entire statement is to insert a sequence of
      characters into the standard output stream (cout, which usually
      corresponds to the screen).

       cout is declared in the iostream standard file within
      return 0;
      the std namespace



    The return statement causes the main function to finish.
5                                                              16 August 2012
Basic Structure of a Program( Without Class)




6                                          16 August 2012
Basic input/output in C++
           Standard Output

    By default, the standard output of a program is the screen, and the
    C++ stream object defined to access it is cout.



     cout is used in conjunction with the insertion operator, which is
    written as << (two "less than" signs).




7                                                            16 August 2012
Basic input/output in C++
              Standard Input

        The standard input device is usually the keyboard. Handling the
      standard input in C++ is done by applying the overloaded operator
      of extraction (>>) on the cin stream.
         The operator must be followed by the variable that will store the
      data that is going to be extracted from the stream. For example:




8                                                              16 August 2012
Introduction
     A class is an extension of the idea of structure used in ‘C’.


     It is a new way of creating and implementing user defined data

      types.



                Structure : Member are public(By Default)
                Class:    Members are private (By Default)




9                                                                 16 August 2012
Class specification
      When we are creating a class, we are creating a new abstract data

         types that can be treated like any other built in data types.

        Class declaration describes the type and scope of its member.

        Class function definitions describe how the class functions are

         implemented?
                Class Specification=Class declaration + Class
                              function definition




10                                                                   16 August 2012
Class Declarations



                      Data Member




                          Member
                          Function




11                                   16 August 2012
Private and public
     The data is hidden so it will be safe from accidental manipulation,
       while the functions that operate on the data are public so they can
       be accessed from outside the class.




12                                                            16 August 2012
A Simple Class




     Data members are usually declared as private and member
                       functions as public

13                                                      16 August 2012
Object Creation
     Creates a variable s1 of type smallobj.

                smallobj s1 ;      // Memory for x is created.

     Note-:   In C++, the class variables are known as objects . Therefore
                          x is called an object of type smallobj.


                We may also declare more than one objects in a single
                                    statements.
                                Smallobj s1, s2, s3;



14                                                                    16 August 2012
Accessing Class members
     Object-name . function-name( actual
                arguments)




15                                         16 August 2012
Accessing Class members
     A variable declared as public can be accessed by the objects
                               directly.




16                                                         16 August 2012
Accessing Class members
     A variable declared as public can be accessed by the objects
                               directly.




17                                                         16 August 2012
Defining Member function

              Defining
              Member
              Function


     Outside the      Inside the
        class            class
      definition       definition

18                                  16 August 2012
Member Functions Within Class Definition
       We can define the member function with the class to replace the
     function declaration by the actual function definition inside the class.




                                                                      Inline
                                                                    function




19                                                                16 August 2012
Member Functions outside Class Definition
       Function that are declared inside a class have to be defined
                       separately outside the class.




20                                                            16 August 2012
Member Functions outside Class Definition( implementation)




21                                                      16 August 2012
Member Functions :Some Special characteristics

      Several different classes can use the same function name.
       Membership level will resolve the issue.
      Membership function can access the private data of the class. A
       non member function can not do so.
                                - Friend function is the exception of this
      A member function can call another member function directly
       without using dot operator.




22                                                               16 August 2012
A C++ Program with a class




23                                16 August 2012
A C++ Program with a class(Multiple Data)




24                                               16 August 2012
C++ objects as a data type




25                                16 August 2012
Nested Function


     A member function can be called by using its
       name inside another function declaration




26                                            16 August 2012
Private member function


     Normal practices:
     To place all the data items in a private section
     and all the functions in public section



       But some situations may require certain functions to
                           be hidden




27                                                       16 August 2012
Private member function(Cont…)

     A private member function can only be called by
      another function that is a member of its class.




       Note: Even an object cannot invoke a private
           member function using dot operator




28                                              16 August 2012
Private member function(Cont…)




            If S1 is an object of class sample, then
     S1.read(); //illegal , object can not access the private
                             member




29                                                    16 August 2012
Private member function(Cont…)

     te




          Function read() can be called by the function update()
                        to update the value of m.

30                                                     16 August 2012
Memory allocation for objects

      Memory space for object is allocated when they are declared and
       not when the class is specified.

      Member functions are created and placed in the memory space
       only once when they are defined as apart of class specification.

      Since all the objects belonging to that class use the same member
       functions, no    separate space is allocated for member functions
       when the objects are created.

      Only space for the member variable is allocated separately for each
       object

31                                                              16 August 2012
Memory allocation for objects

                Member Function1                Memory
                                                Created
                                              when function
                Member Function2               is defined


     Object 1                      Object 2

                                   Var1
      Var1

      Var2                         Var2




32                                               16 August 2012
Static Data members

      In general, each object contains its own separate data.


      If a data item in a class is declared as static , only one such item is
       created for the entire class, no matter how many objects there are.

      A static data item is useful when all objects of the same class must
       share a common item of information

      Static member variable is visible only within the class, but its
       lifetime is the entire program.



33                                                                16 August 2012
Static Data members(Exp1 &Exp2)




     Statdata.cpp           Statdata2.cp
                                 p




34                                         16 August 2012
Static Data members
        Note:


      The Type and scope of each static member variable must be
       defined outside the class definition.



      Because the static data members are stored separately rather than
       as a part of an object.

      Static variables are normally used to maintain values common to
       the entire class



35                                                           16 August 2012
Static data member

     Object 1                   Object 2

      Var1                       Var1


       Var2                        Var2




                  Static data        Common to all
                   variable           the objects




36                                              16 August 2012
Static function

      A static function can have access to only other static members (
       functions or variables) declared in the same class .

      A static member function can be called using the class name (
       instead of its objects)

                          Class-name :: function-name;


      However it can be called by objects of the class also.
      Static member can also be defined in the private region of a class
       also.


37                                                              16 August 2012
Static function (Ex.)




38                           16 August 2012
Objects as function arguments

     It is possible to have functions which accepts objects of a class
       as arguments, just as there are functions which accept other
                          variables as arguments.


           Pass-by-value                         Pass-by-reference
     A copy of entire object is             Only the address of the
       passed to the function                objects is passed to the
     Any modification made to                        function.
        the object inside the               Any changes made to the
     function is not reflected in           object inside the function is
      the object used to call a                reflected in the actual
               function                                object.




39                                                               16 August 2012
Objects as function arguments(Ex.)




40                                        16 August 2012
41   16 August 2012
42   16 August 2012

More Related Content

What's hot

Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
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
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
Fajar Baskoro
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
NainaKhan28
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
class c++
class c++class c++
class c++
vinay chauhan
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
Class or Object
Class or ObjectClass or Object
Class or Object
Rahul Bathri
 
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
Hoang Nguyen
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
ahmed hmed
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
Jeff TUYISHIME
 
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
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
rumanatasnim415
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan
 

What's hot (20)

Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
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
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
class c++
class c++class c++
class c++
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
C++ classes
C++ classesC++ classes
C++ classes
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
 
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
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 

Viewers also liked

Big Data Visualization With ParaView
Big Data Visualization With ParaViewBig Data Visualization With ParaView
Big Data Visualization With ParaView
Swiss Big Data User Group
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
FALLEE31188
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
Subhasis Nayak
 
Pointer in c++ part3
Pointer in c++ part3Pointer in c++ part3
Pointer in c++ part3
Subhasis Nayak
 
OOP
OOPOOP
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
Subhasis Nayak
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
Subhasis Nayak
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
AAKASH KUMAR
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
emailharmeet
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
Tareq Hasan
 

Viewers also liked (12)

Big Data Visualization With ParaView
Big Data Visualization With ParaViewBig Data Visualization With ParaView
Big Data Visualization With ParaView
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
Pointer in c++ part3
Pointer in c++ part3Pointer in c++ part3
Pointer in c++ part3
 
OOP
OOPOOP
OOP
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array in c++
Array in c++Array in c++
Array in c++
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 

Similar to Classes and objects till 16 aug

Lecture 9
Lecture 9Lecture 9
Lecture 9
Mohammed Saleh
 
Chapter 1- Introduction.ppt
Chapter 1- Introduction.pptChapter 1- Introduction.ppt
Chapter 1- Introduction.ppt
TigistTilahun1
 
OOP_chapter _1.pptx
OOP_chapter _1.pptxOOP_chapter _1.pptx
OOP_chapter _1.pptx
AbdexAliyi
 
Oop lec 4(oop design, style, characteristics)
Oop lec 4(oop design, style, characteristics)Oop lec 4(oop design, style, characteristics)
Oop lec 4(oop design, style, characteristics)
Asfand Hassan
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
paramisoft
 
My c++
My c++My c++
My c++
snathick
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
lokeshG38
 
C++
C++C++
C++
Rome468
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
Durgesh Singh
 
Getting Started with Android Application Development
Getting Started with Android Application DevelopmentGetting Started with Android Application Development
Getting Started with Android Application Development
Asanka Indrajith
 
C++ Notes
C++ NotesC++ Notes
Test02
Test02Test02
Test02
testingPdf
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
krismishra
 
Dojo Toolkit from a Flex developer's perspective
Dojo Toolkit from a Flex developer's perspectiveDojo Toolkit from a Flex developer's perspective
Dojo Toolkit from a Flex developer's perspective
cjolif
 
Object oriented fundamentals_in_java
Object oriented fundamentals_in_javaObject oriented fundamentals_in_java
Object oriented fundamentals_in_java
Self
 

Similar to Classes and objects till 16 aug (20)

Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Chapter 1- Introduction.ppt
Chapter 1- Introduction.pptChapter 1- Introduction.ppt
Chapter 1- Introduction.ppt
 
OOP_chapter _1.pptx
OOP_chapter _1.pptxOOP_chapter _1.pptx
OOP_chapter _1.pptx
 
Oop lec 4(oop design, style, characteristics)
Oop lec 4(oop design, style, characteristics)Oop lec 4(oop design, style, characteristics)
Oop lec 4(oop design, style, characteristics)
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
 
My c++
My c++My c++
My c++
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Class and object
Class and objectClass and object
Class and object
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 
C++
C++C++
C++
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
Getting Started with Android Application Development
Getting Started with Android Application DevelopmentGetting Started with Android Application Development
Getting Started with Android Application Development
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
Test02
Test02Test02
Test02
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
 
Dojo Toolkit from a Flex developer's perspective
Dojo Toolkit from a Flex developer's perspectiveDojo Toolkit from a Flex developer's perspective
Dojo Toolkit from a Flex developer's perspective
 
Object oriented fundamentals_in_java
Object oriented fundamentals_in_javaObject oriented fundamentals_in_java
Object oriented fundamentals_in_java
 

Recently uploaded

Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
Vijayananda Mohire
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
James Anderson
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
kantakumariji156
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
ScyllaDB
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
Edge AI and Vision Alliance
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
SeasiaInfotech2
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
Liveplex
 
K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024
The Digital Insurer
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
Matthew Sinclair
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
SATYENDRA100
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
Linda Zhang
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 

Recently uploaded (20)

Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
 
K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 

Classes and objects till 16 aug

  • 1. Basic Of C++ , Classes and Objects Presented By: Shashank Srivastava 31 July,2012 onwards
  • 2. Structure of a Program 2 16 August 2012
  • 3. Structure of a Program #include <iostream> - Lines beginning with a hash sign (#) are directives for the preprocessor. - In this case the directive #include<iostream> tells the preprocessor to include the iostream standard file. - This specific file (iostream) includes the declarations of the basic standard input-output library in C++. 3 16 August 2012
  • 4. Structure of a Program using namespace std; - All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. int main() - This line corresponds to the beginning of the definition of the main function. - The main function is the point by where all C++ programs start their execution, independently of its location within the source code. 4 16 August 2012
  • 5. Structure of a Program cout<<“Hello World”; cout is the name of the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters into the standard output stream (cout, which usually corresponds to the screen). cout is declared in the iostream standard file within return 0; the std namespace The return statement causes the main function to finish. 5 16 August 2012
  • 6. Basic Structure of a Program( Without Class) 6 16 August 2012
  • 7. Basic input/output in C++ Standard Output By default, the standard output of a program is the screen, and the C++ stream object defined to access it is cout. cout is used in conjunction with the insertion operator, which is written as << (two "less than" signs). 7 16 August 2012
  • 8. Basic input/output in C++ Standard Input  The standard input device is usually the keyboard. Handling the standard input in C++ is done by applying the overloaded operator of extraction (>>) on the cin stream.  The operator must be followed by the variable that will store the data that is going to be extracted from the stream. For example: 8 16 August 2012
  • 9. Introduction  A class is an extension of the idea of structure used in ‘C’.  It is a new way of creating and implementing user defined data types. Structure : Member are public(By Default) Class: Members are private (By Default) 9 16 August 2012
  • 10. Class specification  When we are creating a class, we are creating a new abstract data types that can be treated like any other built in data types.  Class declaration describes the type and scope of its member.  Class function definitions describe how the class functions are implemented? Class Specification=Class declaration + Class function definition 10 16 August 2012
  • 11. Class Declarations Data Member Member Function 11 16 August 2012
  • 12. Private and public The data is hidden so it will be safe from accidental manipulation, while the functions that operate on the data are public so they can be accessed from outside the class. 12 16 August 2012
  • 13. A Simple Class Data members are usually declared as private and member functions as public 13 16 August 2012
  • 14. Object Creation Creates a variable s1 of type smallobj. smallobj s1 ; // Memory for x is created. Note-: In C++, the class variables are known as objects . Therefore x is called an object of type smallobj. We may also declare more than one objects in a single statements. Smallobj s1, s2, s3; 14 16 August 2012
  • 15. Accessing Class members Object-name . function-name( actual arguments) 15 16 August 2012
  • 16. Accessing Class members A variable declared as public can be accessed by the objects directly. 16 16 August 2012
  • 17. Accessing Class members A variable declared as public can be accessed by the objects directly. 17 16 August 2012
  • 18. Defining Member function Defining Member Function Outside the Inside the class class definition definition 18 16 August 2012
  • 19. Member Functions Within Class Definition We can define the member function with the class to replace the function declaration by the actual function definition inside the class. Inline function 19 16 August 2012
  • 20. Member Functions outside Class Definition Function that are declared inside a class have to be defined separately outside the class. 20 16 August 2012
  • 21. Member Functions outside Class Definition( implementation) 21 16 August 2012
  • 22. Member Functions :Some Special characteristics  Several different classes can use the same function name. Membership level will resolve the issue.  Membership function can access the private data of the class. A non member function can not do so. - Friend function is the exception of this  A member function can call another member function directly without using dot operator. 22 16 August 2012
  • 23. A C++ Program with a class 23 16 August 2012
  • 24. A C++ Program with a class(Multiple Data) 24 16 August 2012
  • 25. C++ objects as a data type 25 16 August 2012
  • 26. Nested Function A member function can be called by using its name inside another function declaration 26 16 August 2012
  • 27. Private member function Normal practices: To place all the data items in a private section and all the functions in public section But some situations may require certain functions to be hidden 27 16 August 2012
  • 28. Private member function(Cont…) A private member function can only be called by another function that is a member of its class. Note: Even an object cannot invoke a private member function using dot operator 28 16 August 2012
  • 29. Private member function(Cont…) If S1 is an object of class sample, then S1.read(); //illegal , object can not access the private member 29 16 August 2012
  • 30. Private member function(Cont…) te Function read() can be called by the function update() to update the value of m. 30 16 August 2012
  • 31. Memory allocation for objects  Memory space for object is allocated when they are declared and not when the class is specified.  Member functions are created and placed in the memory space only once when they are defined as apart of class specification.  Since all the objects belonging to that class use the same member functions, no separate space is allocated for member functions when the objects are created.  Only space for the member variable is allocated separately for each object 31 16 August 2012
  • 32. Memory allocation for objects Member Function1 Memory Created when function Member Function2 is defined Object 1 Object 2 Var1 Var1 Var2 Var2 32 16 August 2012
  • 33. Static Data members  In general, each object contains its own separate data.  If a data item in a class is declared as static , only one such item is created for the entire class, no matter how many objects there are.  A static data item is useful when all objects of the same class must share a common item of information  Static member variable is visible only within the class, but its lifetime is the entire program. 33 16 August 2012
  • 34. Static Data members(Exp1 &Exp2) Statdata.cpp Statdata2.cp p 34 16 August 2012
  • 35. Static Data members Note:  The Type and scope of each static member variable must be defined outside the class definition.  Because the static data members are stored separately rather than as a part of an object.  Static variables are normally used to maintain values common to the entire class 35 16 August 2012
  • 36. Static data member Object 1 Object 2 Var1 Var1 Var2 Var2 Static data Common to all variable the objects 36 16 August 2012
  • 37. Static function  A static function can have access to only other static members ( functions or variables) declared in the same class .  A static member function can be called using the class name ( instead of its objects) Class-name :: function-name;  However it can be called by objects of the class also.  Static member can also be defined in the private region of a class also. 37 16 August 2012
  • 38. Static function (Ex.) 38 16 August 2012
  • 39. Objects as function arguments It is possible to have functions which accepts objects of a class as arguments, just as there are functions which accept other variables as arguments. Pass-by-value Pass-by-reference A copy of entire object is Only the address of the passed to the function objects is passed to the Any modification made to function. the object inside the Any changes made to the function is not reflected in object inside the function is the object used to call a reflected in the actual function object. 39 16 August 2012
  • 40. Objects as function arguments(Ex.) 40 16 August 2012
  • 41. 41 16 August 2012
  • 42. 42 16 August 2012