Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

Similar documents
C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

C++ Important Questions with Answers

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

Chapter 10 Introduction to Classes



Darshan Institute of Engineering & Technology for Diploma Studies

Lecture 18 Tao Wang 1

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

And Even More and More C++ Fundamentals of Computer Science

OBJECTS. An object is an entity around us, perceivable through our senses. Types of Object: Objects that operate independently.

Introduction Of Classes ( OOPS )

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Chapter 4. Defining Classes I

Implementing Abstract Data Types (ADT) using Classes

Object Oriented Programming. Solved MCQs - Part 2

Object-Oriented Programming (OOP) Fundamental Principles of OOP

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

The syntax of structure declaration is. struct structure_name { type element 1; type element 2; type element n;

Friends and Overloaded Operators

Chapter 6 Introduction to Defining Classes

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Friends and Overloaded Operators

C++ (classes) Hwansoo Han

Chapter 6 Structures and Classes. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

JAVA: A Primer. By: Amrita Rajagopal

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Notes on Chapter Three

(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University

Object Oriented Programming in C#

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

1. An object of a class can be treated as an object of its corresponding class.

Object-Oriented Design (OOD) and C++

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

CS201 Latest Solved MCQs

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

ADTs & Classes. An introduction

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Chapter 11. Abstract Data Types and Encapsulation Concepts

EL2310 Scientific Programming

Global & Local Identifiers

Object Oriented Programming(OOP).

Data Structures using OOP C++ Lecture 3

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

CLASSES AND OBJECTS IN JAVA

W3101: Programming Languages C++ Ramana Isukapalli

CS201 Some Important Definitions

Implementing an ADT with a Class

Preview 9/20/2017. Object Oriented Programing with C++ Object Oriented Programing with C++ Object Oriented Programing with C++

C++ 8. Constructors and Destructors

Sri Vidya College of Engineering & Technology

CS201- Introduction to Programming Current Quizzes

Methods. Contents Anatomy of a Method How to design a Method Static methods Additional Reading. Anatomy of a Method

Classes and Objects. Class scope: - private members are only accessible by the class methods.

Object-Oriented Principles and Practice / C++

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Classes: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods.

Understanding main() function Input/Output Streams

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

What is Class? Remember

Interview Questions of C++

Lecture 7. Log into Linux New documents posted to course webpage

C++ Classes, Constructor & Object Oriented Programming

Come and join us at WebLyceum

Introduction to Classes

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Recharge (int, int, int); //constructor declared void disply();

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

IS 0020 Program Design and Software Tools

Object Oriented Software Design II

Computer Programming C++ Classes and Objects 6 th Lecture

Object-Oriented Programming. Lecture 2 Dr Piotr Cybula

Fundamental Concepts and Definitions

Padasalai.Net s Model Question Paper

Classes - 2. Data Processing Course, I. Hrivnacova, IPN Orsay

UNIT-2 Introduction to C++

C++ Inheritance and Encapsulation

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Declaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Recap: Pointers. int* int& *p &i &*&* ** * * * * IFMP 18, M. Schwerhoff

Ch02. True/False Indicate whether the statement is true or false.

COMP 2355 Introduction to Systems Programming

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

M.EC201 Programming language

7. C++ Class and Object

Object Oriented Design

EL2310 Scientific Programming

CSE 230 Intermediate Programming in C and C++ Functions

Transcription:

UNITII

Classes Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

It s a User Defined Data-type. The Data declared in a Class are called Data- Members of the Class. The Functions declared or defined in a Class are called Member-Functions of the Class. The members of a Class can only be accessed through Objects of the class.

Syntax Syntax: class class_name { access specifier: member1; access specifier: member function;... } [object_name]; for example class a { private; int x public : void show() {cout << a;} };

Characteristics of a class The keyword class specifies abstract data type of type class name. The body of a class is enclosed with in braces and terminated by a semicolon The functions and variables with in the class are collectively called as members The members that have been declared as private can be accessed only from with in the class. Class definition is only a template and does not create any memory space for a class By default all the members are of type private.

Access Specifiers Public Any member declared under this specifier is Accessible from Outside the class, by using the object of the Class. Syntax :- Class definition { public : declarations or definitions } ;

Private Any member declared under this specifier is Not Accessible from Outside the Class. The Private members are accessible to only the Member Functions and Friend Functions in the Class. Syntax :- Class definition { private : declarations or definitions } ;

Protected Any member declared under this specifier is Not Accessible from Outside the class, by using the object of the Class. Syntax :- Class definition { protected : declarations or definitions } ;

Structure Structure can be defined as a collection of dissimilar data items. By default all members are public The size of the structure = size of the individual data items of a structure Separate copy of data members are created for all structure variables To create a structure variable use keyword struct It is Not possible to inherit structures Structure are called as Passive data item Class Class can be defined as combination of data items and functionality applied on that data By default all members are private The size of the structure = size of the individual data items of a class Separate copy of data members and only one copy of member functions are created for class To create a class variable the keyword class is optional It is possible to inherit class Classes are called as Active data items

Member function outside the class To declare the member function of a class outside the class definition the function prototype declared within the body of a class and defined them out side the body of a class.

Objects Object can be defined as an Instance of a class. The process of creating objects (variables) of the class is called class instantiation. In C++ the class variables are called as objects. The complier allocates required memory for objects.

Memory allocation for objects For each object of a class a separate copy of data members and one copy of member functions is created.

Object 1 Object 2 Object 3 Variable1 Variable2 Common for all objects Member func. 1 Member func. 2

Static Data Members One copy of the member, shared by all objects of the class. Visible only with in class, but its lifetime is the entire program. By default initialized to 0. Also known as class variable. For Making data member static we require: a) Declare with in class; b) Define it out side the class

Static Member Functions A static member function can access only the static members of class. It is called using the name of the class. Syntax for calling static member function classname : : function-name;

Array of objects

Friend Function Private members of a class can be accessed only by the member functions of the same class. But there are some cases where the private member needs to be accessed by members of other classes. This can be achieved by declaring a nonmember function called Friend Function Note: Just Bcoz of friend function C++ is not fully object oriented.

Friend Functions Friend functions are Not member functions of any class, but they can access the private, protected and public members of the class. They are declared using friend keyword. They Don t belong to any specific Class. They can be invoked as ordinary functions, with out using any object.

They can be defined outside the Class, here also they are defined like ordinary functions and Not like member functions. The access specifiers does not effect the visibility of Friend Functions. Usually a friend function receives the object as arguments. Syntax :- friend return-type function-name ( inputarguments ) ; It is not affected by the access control keywords.

We can also declare all the member function of a class as friend function of another class using friend class. Eg class first { friend class second; }; class second {.. }