Obj As Function Argument PDF
Obj As Function Argument PDF
Obj As Function Argument PDF
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
Name of Subject:- Object Oriented Programming Using C++ MSBTE Subject Code:- 22316
Chapter 2: CLASSES & OBJECTS
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;
• }
• {
• 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;
• }; • }