Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Obj As Function Argument PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

SANJIVANI K. B. P.

POLYTECHNIC, KOPARGAON
With NBA ACCREDIATED programs , Approved by AICTE, New Delhi,
Recognized by Govt. of Maharashtra, Affiliated to Maharashtra State Board of Technical Education, Mumbai,
ISO 9001:2015 Certified Institute

Department:- COMPUTER TECHNOLOGY Class:- SYCM-B

Name of Subject:- Object Oriented Programming Using C++ MSBTE Subject Code:- 22316
Chapter 2: CLASSES & OBJECTS

2.1 Class & Object: Introduction, specifying a class, access


specifiers, defining member functions, creating Objects,
memory allocations for objects.

2.2 Static data members, static member function, friend function

2.3 Array of Objects, Object as function arguments.

Sanjivani K.B.P. Polytechnic, Kopargaon Department of Compute Technology P. M. Dhanrao 2


Chapter 1: Principles of OOP

2.4 Concepts of constructors, Types of


Constructors
2.5 Multiple Constructors in a Class,
Constructors with default arguments.

2.6 Destructors.
Sanjivani K.B.P. Polytechnic, Kopargaon Department of Compute Technology P. M. Dhanrao 3
• 2a. Develop relevant friend functions to solve the
given problem.
• 2b. Write C++ program to use array of given objects.
• 2c. Write C++ program to create the given object
using constructor.
• 2d. Write program to delete the given object using
destructor in C++ program.
Sanjivani K.B.P. Polytechnic, Kopargaon Department of Compute Technology P. M. Dhanrao 4
Like any other data type, an object can be used as
a function argument.
•Copy of entire object is passed to funcion=>
pass by value => changes done only on copy of
object.
•Only address of the object is tranferred to the
function => pass by reference=> changes done
to original data items of origional object.
Sanjivani K.B.P. Polytechnic, Kopargaon Department
5
of Compute Technology P. M. Dhanrao
Function declaration
• int main()
• void sum(time, time); • {
• time t1,t2,t3; Function calling
• t1.get(20);
void time::sum(time t1, time t2) • t2.get(30);
{
min=t1.min+t2.min;
• t3.sum(t1,t2);
} Function definition • t3.put();
• return 0;
• }

Sanjivani K.B.P. Polytechnic, Kopargaon Department


6
of Compute Technology P. M. Dhanrao
• #include <iostream.h> • void time::sum(time t1, time t2)
• class time • { min=t1.min+t2.min; }

• {
• int min; • int main()
• public: • {
• void get(int x) • time t1,t2,t3;
• { min=x;} • t1.get(20); t2.get(30);
• void put() • t3.sum(t1,t2);
• { cout<<"min:"<<min;} • t3.put();
• void sum(time, time); • return 0;
• }; • }

Sanjivani K.B.P. Polytechnic, Kopargaon Department


7
of Compute Technology P. M. Dhanrao
• void time::sum(time t1, time t2) SUM() function is invoked by
• { object t3
It accepting t1 and t2 as
•min=t1.min+t2.min; function arguments.
Sum function have direct access
• } to private data of t3 object
Minutes of t2 accessed by using
//Invoked as
object.minutes=> t2.min
Minutes of t1 accessed by using
t3.sum(t1,t2) object.minutes=> t1.min

Sanjivani K.B.P. Polytechnic, Kopargaon Department


8
of Compute Technology P. M. Dhanrao
• Accessing members of objects within called function

Sanjivani K.B.P. Polytechnic, Kopargaon Department


9
of Compute Technology P. M. Dhanrao

You might also like