Lecture3 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Lecture3

Description:

class and object in 'C++' – PowerPoint PPT presentation

Number of Views:11
Updated: 20 November 2014
Slides: 20
Provided by: SAURABH301
Category: Other
Tags:
Why and how: Simple and Easiest language

less

Transcript and Presenter's Notes

Title: Lecture3


1
Dev Bhoomi Group of Institutions
Saharanpur
  • Name Saurabh Chauhan
  • Class M.C.A. 1ST (2013-15)
  • Roll no 1358614017
  • Topic Classes and Object.

Sub To Mr. Rakesh Kumar Sub
By Saurabh Chauhan
2
C Classes Object
  • WELCOME

3
Outline
  • Introduction of the class
  • Characteristics of the class
  • Format of the class
  • Define a class type
  • Implementing class methods
  • Introduction of an Object
  • Declaration of an object
  • Reasons for OOP
  • Thank you

4
Introduction of the class
  • A class is binding the data and methods.
  • A class is a collection of objects of similar
    type.
  • A class is an object factory (or producer ) that
    produces similar objects.
  • A class is just like an image and model and can
    say a template.
  • A class does not exists physically because its a
    image only in our mind
  • But object exists physically because a object is
    a real world entity i.e. a pen , a chair , a desk
    , a dog , a bike , a car ,a men etc
  • The class and object both are sub method of the
    OOPs methodology

5
Why do we need to have class ?
  • Characteristics of the class
  • Structures are public by default and classes are
    private by default.
  • Data more secure in the class.
  • Class reduce the complexity.
  • We can easy and well programming, if we use the
    class in our program .

6
Classes in C
  • 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)
7
Classes in C
  • Within the body, the keywords private and
    public specify the access level of the members
    of the class.
  • the default is private.
  • Usually, the data members of a class are declared
    in the private section of the class and the
    member functions are in public section.

8
Classes in C
  • Format

class class_name private
public
private members data or variables or
characteristics
Public members or methods Or behavior
9
Define a Class Type
  • class class_name
  • access specifier
  • data
  • access specifier
  • methods
  • ...

class Rectangle private int width
int length public void set(int
w, int l) int area()
10
Implementing class methods
  • Class implementation writing the code of class
    methods.
  • There are two ways
  • 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 ClassNameMemberFunctionName( )

11
Implementing class methods
  • Member functions(method) defined inside class
  • Do not need scope resolution operator, class
    name

class Circle private double r,ar
public void area ()
cinltltr arrr3.14
coutltlt\n \a area of circle -ltltar
Method Defined inside class
12
// this is a program of area of circle //
methods (Defined outside class) class Circle
private double r,ar public
void area() // mehtod void
circle area coutltlt\n enter the radius of
the circle cingtgtr arrr3.14
coutltltarea of the circle ltltar
Method Defined outside class
13
Object
  • Object
  • a variable or an instance of a class
  • Objects may represent any entity ,such as a
    person , a cat
  • a chair , a pen , a place , a bank account , a
    customer , a table of data ,etc.
  • for ex ,bike is an object .its characteristics
    are its color is black ,Its engine is of 500cc
    ,Its company is Suzuki .Its behavior is to
    starting the engine ,changing the gear ,using the
    break, etc.
  • Declaration of an Object
  • Initiation of an Object

14
What is an object?
OBJECT
set of methods (public member functions) interna
l state (values of private data members)
Operations Data
15
Example A Rabbit object
  • You could (in a game, for example) create an
    object representing a rabbit
  • It would have data
  • How hungry it is
  • How frightened it is
  • Where it is
  • And methods
  • eat, hide, run, dig

16
Concept Classes describe objects
  • Every object belongs to (is an instance of) a
    class
  • An object may have fields, or variables
  • The class describes those fields
  • An object may have methods
  • The class describes those methods
  • A class is like a template, or cookie cutter

17
Declaration of an Object
class Rectangle private int width
int length public void set(int w, int
l) int area()
main() Rectangle r1 Rectangle r2
r1.set(5, 8) coutltltr1.area()ltltendl r2.set(8,
10) coutltltr2.area()ltltendl
18
Reasons for OOP
  • Simplify programming
  • Interfaces
  • Information hiding
  • Implementation details hidden within classes
    themselves
  • Software reuse
  • Class objects included as members of other
    classes

19
Thank You
Write a Comment
User Comments (0)
About PowerShow.com