Object Oriented Programming Lab (DCO-312)

You might also like

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

OBJECT ORIENTED PROGRAMMING LAB

(DCO-312)

Submitted to: Submitted by:

Dr. Sunil & Ms. Farah Jamal Ansari Student Name: Zainul Aabidin
Assistant Professor Roll No.: 20DCS058
Semester: 3rd

Computer Engineering Section


University Polytechnic
Faculty of Engineering & Technology
Jamia Millia Islamia, New Delhi-110025
PRACTICAL RECORD
PAPER CODE -
: DCO 312
Name of the Student : Zainul Aabidin
University Roll No. : 20DCS058
Section : Computer Engineering

PRACTICAL DETAILS
Practical Practical Name Date of Date of Marks/ Teacher’s
No. Performance Checking Grades Signature

1. Write Programs in C++ 03/09/2021


Implement Various
controls Statements.
2. Write Programs in C++ 20/09/2021
to understand Structure.

3. Write Programs in C++ 20/09/2021


to understand Functions.
4. Write Programs in C++ 20/09/2021
to understand Pointer
Arithmatic.
5. Write Programs in C++ 25/09/2021
to understand different
functions call mechanism.
a. Call by value
b. Call by referance
6. Write Programs in C++ 25/09/2021
to understand Classes and
Objects.
7. Write a Program in C++ to 17/10/2021
Understand Inline
Functions.

8. Write a Program in C++ to 17/10/2021


Understand Constructors
& Destructors.
9. Write a Program in C++ 17/10/2021
Using Class to
Demonstrate the Use of
“this” Pointer.
10.
Practical No. 07 : Write a Program in C++ to Understand Inline Functions.

#include <iostream.h>
#include<conio.h>

inline void displayNum(int num)


{
cout << num << endl;
}

int main()
{
// first function call
displayNum(5);

// second function call


displayNum(8);

// third function call


displayNum(666);
getch();
return 0;
}

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

---Values Before Swapping---


x:5

y : 10

z : 20
---Values Ater Swapping---
x : 10

y : 20

z:5

Inside the destructor


Practical No. 09 : Write a Program in C++ Using Class to Demonstrate the Use of “this”
Pointer.

#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);

// Chained function calls. All calls modify the same object


// as the same object is returned by reference
obj1.setX(10);
obj1.setY(20);

obj1.print();
getch();
return 0;
}

OUTPUT

x = 10 y = 20

You might also like