BCE Practical
BCE Practical
#include <iostream>
int main()
int x = 25;
int y = 13;
int z= x*y;
int a= x/y;
int b= x%y;
}
Write a program to illustrate Arrays
#include <iostream>
int main()
int arr[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
return 0;
}
Write a program to illustrate Functions
#include <iostream>
int main() {
displayNum(10, 14.2);
return 0;
}
Write a program to illustrate Constructor & Destructor
#include <iostream>
class student
int rno;
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>
class MyClass {
public:
int myNum;
string myString;
};
int main() {
MyClass a;
a.myNum = 15;
a.myString = "hello";
return 0;
}
Write a program to illustrate Operator Overloading
#include <iostream>
class Vector {
private:
int x, y;
public:
// Constructor
std::cout << "Vector(" << x << ", " << y << ")" << std::endl;
};
int main() {
Vector v3 = v1 + v2;
v3.display();
return 0; }
#include <iostream>
int d= a+b+c;
int main()
add(10, 2);
add(5, 6, 4);
return 0;
}
Write a program to illustrate Derived Classes & Inheritance
#include <iostream>
// Base class
class Shape
public:
void display()
};
private:
double radius;
public:
Circle(double r) : radius(r) {}
double calculateArea()
{
void display()
cout << "This is a Circle with radius: " << radius << endl;
};
private:
public:
double calculateArea() {
void display() {
cout << "This is a Rectangle with length: " << length << " and width: " << width << endl;
}
};
int main() {
// Object of Circle
Circle myCircle(5.0);
myCircle.display();
// Object of Rectangle
myRectangle.display();
return 0;
}
Write a program to insert and delete and element from the Stack
#include <iostream>
int main() {
st.push(5);
st.push(10);
st.push(15);
while (!st.empty()) {
st.pop();
if (st.empty()) {
}
return 0;
Write a program to insert and delete and element from the Queue
#include <iostream>
#define SIZE 5
class Queue {
public:
if (rear == SIZE - 1) {
return;
items[++rear] = value;
void dequeue() {
return;
}
cout << items[front++] << " removed.\n";
void displayFront() {
return;
};
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) {}
newNode->data = value;
newNode->next = nullptr;
if (head == nullptr) {
head = newNode;
} else {
temp = temp->next;
temp->next = newNode;
if (head->data == value) {
head = head->next;
delete temp;
return;
temp = temp->next;
temp->next = temp->next->next;
delete toDelete;
void display() {
temp = temp->next;
};
int main() {
LinkedList list;
list.insert(10);
list.insert(20);
list.insert(30);
list.display();
list.deleteNode(20);
list.display();
return 0;