CLASSES AND OBJECTS.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

C++ Classes & Data Abstraction
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
1 C++ Structures Starting to think about objects...
C++ Classes & Object Oriented Programming. Object Oriented Programming  Programmer thinks about and defines the attributes and behavior of objects. 
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 10 Inheritance and Polymorphism
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
CITA 342 Section 1 Object Oriented Programming (OOP)
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Classes, Interfaces and Packages
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Matthew Small Introduction to Object-Oriented Programming.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Programming 2. Arrays & structure Arrays : allow you to define variables that combine several data items of the same kind. Structure : is another user.
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Introduction to Object-oriented Programming
Pointer to an Object Can define a pointer to an object:
Lecture 3 (UNIT -1) SUNIL KUMAR CIT-UPES.
Procedural and Object-Oriented Programming
Classes C++ representation of an object
Visit for more Learning Resources
2 Chapter Classes & Objects.
Class and Objects UNIT II.
10.2 Classes Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.
Review: Two Programming Paradigms
Table of Contents Class Objects.
Chapter 3: Using Methods, Classes, and Objects
Chapter 11: Structured Data.
Classes & Objects.
Introduction to Classes
Concepts and Basics of C++ Programming
Chapter 5 Classes.
This technique is Called “Divide and Conquer”.
Concepts and Basics of C++ Programming
Lecture 4-7 Classes and Objects
C++ Classes & Object Oriented Programming
Introduction to Classes
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Contents Introduction to Constructor Characteristics of Constructor
Starting to think about objects...
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
CPS120: Introduction to Computer Science
COP 3330 Object-oriented Programming in C++
Introduction to Classes and Objects
By Rajanikanth B OOP Concepts By Rajanikanth B
Class.
Classes C++ representation of an object
Final and Abstract Classes
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

CLASSES AND OBJECTS

Class A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions. The combination of data members and member functions constitute a data object or simply an object.

Object Instantiation of a class. In terms of variables, class would be the type and an object would be a variable.

General Structure of a class Class name or name of class Data Members Member functions Access Specifiers Declaring objects

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)

class classname { private: variable declarations; function declarations; public: protected: } obj1, obj2,…..objN;

Class name Name given to a particular class. Serves as a name specifier for the class using which we can create objects. The class is specified by keyword “class”

Data Members Data type properties that describe the characteristics of a class. We can declare any number of data members of any type in a class. We can say that variables in C and data members in C++. E.g. int rn;

Member functions Various operations that can be performed to data members of that class. We can declare any number of member functions of any type in a class. E.g. void read();

Access Specifiers Used to specify access rights for the data members and member functions of the class. Depending upon the access level of a class member, access to it is allowed or denied. 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.

Classes in C++ class class_name { private: … public: }; private members or methods Public members or methods

Private members and methods are for internal use only. only members of that class have accessibility can be accessed only through member functions of that class. Private members and methods are for internal use only.

Public: Accessible from outside the class can be accessed through member function of any class in the same program.

Protected: Stage between private and public access. They cannot be accessed from outside the class, but can be accessed from the derived class.(inheritance)

Class Example This class example shows how we can encapsulate (gather) a circle information into one package (unit or class) No need for others classes to access and retrieve its value directly. The class methods are responsible for that only. class Circle { private: double radius; public: void setRadius(double r); double getDiameter(); double getArea(); double getCircumference(); }; They are accessible from outside the class, and they can access the member (radius)

C++ supports three access specifiers: public private protected The public access specifier allows a class to subject its member variables and member functions to other functions and objects The private access specifier allows a class to hide its member variables and member functions from other class objects and functions The protected access specifier allows a class to hide its member variables and member functions from other class objects and functions just like private access specifier - is used while implementing inheritance

A class declaration only uses to build the structure of an object. Declaring objects: A class declaration only uses to build the structure of an object. Declaration of an object is same as declaration of class. Defining objects of class data type is known as class instantiation(instances of class) When we create objects during that moment , memory is allocated to them. Ex- Circle c;

class Customer { void accept() cout << “Accepting Customer Details” << endl; } void display() cout << “Displaying Customer Details” << endl; }; Void main() Customer C1; C1.accept(); C1.display(); getch();