Chapter-3.1 (Basics of Object Oriented Programming)
Chapter-3.1 (Basics of Object Oriented Programming)
and C++
Subject Code-CST-152
UNIT-I
Chapter-3
Topic-->Object Oriented Programming Using C++
Course Objectives
• To understand the concept of the various Programming Paradigms.
• To apply different programming languages for modeling real world
problems.
CLASS STRUCTURE
Way to group both data & functions Way to group related data
Reference type & its object is created on heap Value type & its object is created on stack
memory memory.
Can inherit the another class. Does not support the inheritance.
Can have the all types of constructor & Can only have the parameterized constructor.
destructor.
Member variable can be initialized directly. Member variable can not be initialized directly.
i. Object
ii. Class
iii. Data abstraction and Encapsulation
iv. Information hiding
v. Inheritance
vi. Polymorphism
Wrapping up of data & functions into a single unit (called class) -encapsulation.
Data is not accessible to the outside world
Functions which are wrapped in the class can access it.
Abstraction - act of representing essential features without background details.
Fig.5. Encapsulation
Fig. 8. Polymorphism
27-04-2019 University Institute of Engineering 11
Specifying a class
Class specification has two parts:
• Class declaration
• Class function definitions
Class declaration describes type and scope of its members
Class function definition describes how class functions are implemented.
Example:
class class_name Class body contains the
Declaration of variables
{ private: variable declarations; And functions.
public: function declaration;
};
COLON
27-04-2019 University Institute of Engineering 12
Creating objects
For utilizing the defined class, we need variables of the class type. For example,
Largest ob1,ob2; //object declaration will create two objects ob1 and ob2 of
largest class type.
Memory space is allocated separately to each object for their data members.
Member variables store different values for different objects of a class.
A static member function can access only the static members of a class.
In C++, a static member function fifers from the other member functions in the
following ways:
(i) Only static members (functions or variables) of the same class can be accessed
by a static member function.
(ii) It is called by using the name of the class rather than an object as given
below:
Name_of_the_class :: function_name
For example:
student::showcount();
27-04-2019 21
University Institute of Engineering
Friend functions Example
Eg.
class B;
class A void fun(A ob, B obj)
{
{ public:
cout<<"sum"<<ob.a+obj.b;
void set() }
{ } void main()
{
friend void fun(A,B);
A ob;
}; B obj;
class B ob.set( );
obj.set( );
{ public:
fun(ob,obj);
void set( ) getch();
{ } }
friend void fun(A,B);
};
27-04-2019 22
University Institute of Engineering
References
i. https://books.google.co.in/books?isbn=0070669074
ii. E Balagurusamy., “Object Oriented Programming in C++”, Tata McGraw-Hill.
iii. https://www.tutorialspoint.com/cplusplus/cpp_classes_objects.htm
iv. http://www.studytonight.com/cpp/class-and-objects.php
v. http://www.cplusplus.com/doc/tutorial/classes/
27-04-2019
University Institute of Engineering
Unit Course Outcomes