Professional Documents
Culture Documents
Object Oriented Programming Lab (DCO-312)
Object Oriented Programming Lab (DCO-312)
Object Oriented Programming Lab (DCO-312)
(DCO-312)
Dr. Sunil & Ms. Farah Jamal Ansari Student Name: Zainul Aabidin
Assistant Professor Roll No.: 20DCS058
Semester: 3rd
PRACTICAL DETAILS
Practical Practical Name Date of Date of Marks/ Teacher’s
No. Performance Checking Grades Signature
#include <iostream.h>
#include<conio.h>
int main()
{
// first function call
displayNum(5);
OUTPUT
5
8
666
Practical No. 08 : Write a Program in C++ to Understand Constructors & Destructors.
//Program to swap the values of three nos. using constructor and destructor.
#include<iostream.h>
#include<conio.h>
class swapping
{ public:
int x, y, z, s;
public:
swapping()
{ x=5;
y=10;
z=20;
cout<<"\n---Values Before Swapping---";
cout<<"\n x : "<<x<<endl;
cout<<"\n y : "<<y<<endl;
cout<<"\n z : "<<z<<endl;
}
public:
void swap()
{
s=x;
x=y;
y=z;
z=s;
cout<<"\n---Values Ater Swapping---";
cout<<"\n x : "<<x<<endl;
cout<<"\n y : "<<y<<endl;
cout<<"\n z : "<<z<<endl;
}
public:
~swapping()
{
cout<<"\n Inside the destructor ";
}
};
int main()
{
swapping S;
clrscr();
S.swap();
getch();
return 0;
}
OUTPUT
y : 10
z : 20
---Values Ater Swapping---
x : 10
y : 20
z:5
#include<iostream.h>
#include<conio.h>
class Test
{
private:
int x;
int y;
public:
Test(int x = 0, int y = 0)
{
this->x = x; this->y = y;
}
Test &setX(int a)
{
x = a; return *this;
}
Test &setY(int b)
{
y = b; return *this;
}
void print()
{
cout << "x = " << x << " y = " << y << endl;
}
};
int main()
{
Test obj1(5, 5);
obj1.print();
getch();
return 0;
}
OUTPUT
x = 10 y = 20