ANKIT_OOP
ANKIT_OOP
cout << "Enter " << size << " numbers:" << endl;
int temp = a;
a = b;
b = temp;
}}}}
int main() {
int size;
// Call functions
return 0;
Call By value
#include <iostream>
cout << "Inside callByValue, num = " << num << endl;
int main() {
int x = 5;
cout << "After callByValue, x = " << x << endl; // x is not changed
return 0;
}
Call By reference
#include <iostream>
cout << "Inside callByReference, num = " << num << endl;
int main() {
int x = 5;
return 0;
}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 2- Write a C++ program that illustrates the concept of Function over
loading.
#include <iostream>
return a + b;}
return a + b + c; }
return a + b; }
int main() {
cout << "Sum of " << x << " and " << y << " = " << add(x, y) << endl;
cout << "Sum of " << x << ", " << y << " and " << z << " = " << add(x, y, z) << endl;
cout << "Sum of " << p << " and " << q << " = " << add(p, q) << endl;
return 0;}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 3- Write a program in C++ to perform following operations on complex
numbers Add, Subtract, Multiply, Divide, Complex conjugate. Design the class for
complex number representation and the operations to be performed.
#include <iostream>
class Complex {
private:
public:
if (imag >= 0) cout << " + " << imag << "i";
Complex conjugate() {
};
int main() {
num1.display();
num2.display();
sum.display();
diff.display();
product.display();
quotient.display();
return 0;
}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 4- Write a program in C++ to implement Stack. Design the class for
stack and the operations to be performed on stack.
#include <iostream>
class Stack {
private:
public:
Stack(int size) {
capacity = size;
~Stack() {
delete[] arr;
bool isEmpty() {
bool isFull() {
if (isFull()) {
cout << "Stack Overflow! Unable to push " << value << endl;
} else {
arr[++top] = value; // Increment top and add the value to the stack
int pop() {
if (isEmpty()) {
return -1;
} else {
int poppedValue = arr[top--]; // Return the top value and decrement top
return poppedValue;
int peek() {
if (isEmpty()) {
return -1;
} else {
void display() {
if (isEmpty()) {
} else {
};
int main() {
Stack stack(5);
stack.push(10);
stack.push(20);
stack.push(30);
stack.push(40);
stack.push(50);
stack.display();
cout << "Top element is: " << stack.peek() << endl;
stack.display();
stack.push(60);
stack.display();
return 0;
}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 5- Write a program in C++ to perform following operations on complex
numbers Add, Subtract, Multiply, Divide. Use operator overloading for these
operations.
#include <iostream>
class Complex {
private:
public:
}};
int main() {
num1.display();
num2.display();
sum.display();
diff.display();
product.display();
quotient.display();
return 0;
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 6- Write a program in C++ to Read and Display the information of
Employee using Multiple Inheritance. Use Basic Info and Department Info as a base
class.
#include <iostream>
#include <string>
class BasicInfo {
protected:
string name;
int employeeID;
int age;
public:
};
class DepartmentInfo {
protected:
string departmentName;
string position;
public:
};
public:
};
int main() {
emp.displayEmployeeInfo();
return 0;
}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 7- Write a program in C++ to implement string class. Write constructors,
destructor, Accepts function and Display function.
#include <iostream>
#include <cstring>
private:
public:
MyString() {
~MyString() {
void Accepts() {
str = new char[strlen(temp) + 1]; // Allocate memory for the new string
};
int main() {
MyString str1;
return 0;
}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 8- : Write a C++ program that illustrates run time polymorphism by using
virtual functions.
#include <iostream>
// Base class
class Shape {
public:
};
private:
double radius;
public:
Circle(double r) : radius(r) {}
cout << "Area of Circle: " << 3.14 * radius * radius << endl; }};
private:
public:
cout << "Area of Rectangle: " << length * width << endl;}};
public:
cout << "Area of Triangle: " << 0.5 * base * height << endl; }};
int main() {
Circle circle(5);
Shape* shapePtr;
shapePtr = &circle;
shapePtr = &rectangle;
shapePtr = ▵
return 0;
}
Subject: Object Oriented Programming [C++]
Name: ANKIT SUNIL KHARADE
Roll No: 53
Practical No: 9- : Write a C++ program which use try and catch for exception handling.
#include <iostream>
public:
};
if (b == 0) {
return a / b;
int main() {
int x, y;
try {
cout << "An error occurred: " << e.what() << endl;
return 0;