Note: Please add all these experiments to the BCE lab manual.
These experiments should be handwritten.
Write a program to illustrate Arithmetic Expressions
#include <iostream>
using namespace std;
int main()
int x = 25;
int y = 13;
int z= x*y;
int a= x/y;
int b= x%y;
cout << " x + y = " << (x + y)<< endl ;
cout << " x - y = " << (x - y) << endl;
cout << " x * y = " << z << endl;
cout << " x / y = " << a << endl;
cout << " x % y = " << b << endl;
}
Write a program to illustrate Arrays
#include <iostream>
using namespace std;
int main()
int arr[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
cout << "arr[0]: " << arr[0] << endl;
cout << "arr[1]: " << arr[1] << endl;
cout << "arr[2]: " << arr[2] << endl;
return 0;
}
Write a program to illustrate Functions
#include <iostream>
using namespace std;
void displayNum(int n1, float n2)
cout << "The int number is " << n1 << "\n";
cout << "The double number is " << n2;
int main() {
displayNum(10, 14.2);
return 0;
}
Write a program to illustrate Constructor & Destructor
#include <iostream>
using namespace std;
class student
int rno;
char name[50]; double fee; public: student()
cout<<"Enter the RollNo:"; cin>>rno;
cout<<"Enter the Name:"; cin>>name;
cout<<"Enter the Fee:"; cin>>fee; }
void display()
cout<<endl<<rno<<"\t"<<name<<"\t"<<fee;
};
int main()
student s; //constructor gets called automatically when we create the object of the class
s.display();
return 0;
}
Write a program to illustrate Object and Classes
#include <iostream>
#include <string>
using namespace std;
class MyClass {
public:
int myNum;
string myString;
};
int main() {
MyClass a;
a.myNum = 15;
a.myString = "hello";
cout << a.myNum << "\n";
cout << a.myString << endl;
return 0;
}
Write a program to illustrate Operator Overloading
#include <iostream>
class Vector {
private:
int x, y;
public:
// Constructor
Vector(int x = 0, int y = 0) : x(x), y(y) {}
// Overload the + operator
Vector operator+(const Vector& other) const {
return Vector(x + other.x, y + other.y);
// Display the vector
void display() const {
std::cout << "Vector(" << x << ", " << y << ")" << std::endl;
};
int main() {
// Create two Vector objects
Vector v1(2, 3);
Vector v2(4, 5);
Vector v3 = v1 + v2;
v3.display();
return 0; }
Write a program to illustrate Function Overloading
#include <iostream>
using namespace std;
void add(int a, int b)
cout << "sum = " << (a + b);
void add(int a, int b, int c)
int d= a+b+c;
cout << endl << "sum = " << d;
int main()
add(10, 2);
add(5, 6, 4);
return 0;
}
Write a program to illustrate Derived Classes & Inheritance
#include <iostream>
#include <cmath> // For mathematical operations
using namespace std;
// Base class
class Shape
public:
void display()
cout << "This is a shape." << endl;
};
// Derived class 1: Circle
class Circle : public Shape
private:
double radius;
public:
Circle(double r) : radius(r) {}
double calculateArea()
{
return M_PI * radius * radius; // Area of Circle = pr²
void display()
cout << "This is a Circle with radius: " << radius << endl;
cout << "Area of Circle: " << calculateArea() << endl;
};
// Derived class 2: Rectangle
class Rectangle : public Shape {
private:
double length, width;
public:
Rectangle(double l, double w) : length(l), width(w) {}
double calculateArea() {
return length * width; // Area of Rectangle = length × width
void display() {
cout << "This is a Rectangle with length: " << length << " and width: " << width << endl;
cout << "Area of Rectangle: " << calculateArea() << endl;
}
};
int main() {
// Object of Circle
Circle myCircle(5.0);
myCircle.display();
cout << endl;
// Object of Rectangle
Rectangle myRectangle(4.0, 7.0);
myRectangle.display();
return 0;
}
Write a program to insert and delete and element from the Stack
#include <iostream>
#include <stack> // Include the C++ stack library
using namespace std;
int main() {
stack<int> st; // Declare a stack of integers
// Push elements onto the stack
st.push(5);
st.push(10);
st.push(15);
// Pop elements from the stack
cout << "Popping elements from the stack:" << endl;
while (!st.empty()) {
cout << "Popped: " << st.top() << endl;
st.pop();
// Try popping from an empty stack
if (st.empty()) {
cout << "Stack is empty!" << endl;
}
return 0;
Write a program to insert and delete and element from the Queue
#include <iostream>
using namespace std;
#define SIZE 5
class Queue {
int items[SIZE], front = -1, rear = -1;
public:
void enqueue(int value) {
if (rear == SIZE - 1) {
cout << "Queue is full!\n";
return;
if (front == -1) front = 0;
items[++rear] = value;
cout << value << " added.\n";
void dequeue() {
if (front == -1 || front > rear) {
cout << "Queue is empty!\n";
return;
}
cout << items[front++] << " removed.\n";
void displayFront() {
if (front == -1 || front > rear) {
cout << "Queue is empty!\n";
return;
cout << "Front: " << items[front] << "\n";
};
int main() {
Queue q;
q.enqueue(10);
q.enqueue(20);
q.displayFront();
q.dequeue();
q.displayFront();
return 0;
}
Write a program to insert and delete and element from the Linked List
#include <iostream>
struct Node {
int data;
Node* next;
};
class LinkedList {
private:
Node* head;
public:
LinkedList() : head(nullptr) {}
// Insert a new node at the end
void insert(int value) {
Node* newNode = new Node();
newNode->data = value;
newNode->next = nullptr;
if (head == nullptr) {
head = newNode;
} else {
Node* temp = head;
while (temp->next != nullptr) {
temp = temp->next;
temp->next = newNode;
// Delete a node by value
void deleteNode(int value) {
if (head == nullptr) return;
if (head->data == value) {
Node* temp = head;
head = head->next;
delete temp;
return;
Node* temp = head;
while (temp->next != nullptr && temp->next->data != value) {
temp = temp->next;
if (temp->next == nullptr) return;
Node* toDelete = temp->next;
temp->next = temp->next->next;
delete toDelete;
// Display the list
void display() {
Node* temp = head;
while (temp != nullptr) {
std::cout << temp->data << " -> ";
temp = temp->next;
std::cout << "nullptr" << std::endl;
};
int main() {
LinkedList list;
list.insert(10);
list.insert(20);
list.insert(30);
list.display();
list.deleteNode(20);
list.display();
return 0;