24es132-Programming and Algorithms Lab Manual-1
24es132-Programming and Algorithms Lab Manual-1
LAB MANUAL
I Year - I Semester
Regulation 2021
Course PROGRAMMING AND
24ES132 Course Title:
Code: ALGORITHMS LABORATORY
Credits: 2 L–T–P 0-0-4
Course objectives:
To develop an algorithm & programming on software tools and Digital processors with
peripheral interfaces.
To expertise in open source software / packages /tools.
To do hands-on in commercial and licensed Hardware-software suites.
Teaching-Learning Process:
Suggested strategies that teachers may use to effectively achieve the course outcomes:
1. Interactive Simulations
2. Lab experiment videos
3. Blended Mode of Learning
4. Project based Learning
5. Experiential Learning
6. NPTEL and Other Videos
7. Smart Class Room
8. Flipped Class
LIST OF EXPERIMENTS
1. Implementation of basic programming concepts like conditionals and loops
2. Implementation of function and operator overloading
3. Creation of classes and objects.
4. Implementation of constructors and destructors
5. Implementation of array of objects and dynamic objects.
6. Implementation of inheritance and its types
7. Implementation of polymorphism and its types.
8. Implementation of various sorting algorithms.
9. Application of Stack
10. Implementation of queue using array.
11. Implementation of Linked Lists: Singly linked, doubly linked and Circular lists and applications.
Course outcomes: On completion of the course, the student will have the ability to:
CO3 Apply the different data structures for implementing solutions to practical problems
Level 3- Highly Mapped, Level 2- Moderately Mapped, Level 1- Low Mapped, Level 0- Not
Mapped
Scheme of Evaluation:
Final
Max Reduce Total
Component Typeof assessment mark
Marks d
s
Marks
Continuous Internal Continuous 75 75 10
Examination (CIE) - Assessment 60
0
Laboratory
Model Lab Exam 25 25
End Semester
Lab Exam 100 40 40 40
Examination (ESE)
Total 100
Exp. No. :
Date :
IMPLEMENTATION OF BASIC PROGRAMMING CONCEPTS LIKE
CONDITIONALS AND LOOPS
AIM :-
To write a program to implement the basic programming concepts like conditions and
loops.
PROGRAM:-
#include <iostream>
Int main() {
Int num;
// Conditional statement
If (num > 0) {
Cout << “You entered a positive number.” << endl;
} else if (num == 0) {
Cout << “You entered zero.” << endl;
} else {
Cout << “You entered a negative number.” << endl;
}
Return 0;
}
Output:
RESULT :-
Thus the program to implement the basic programming concepts like conditions and
loops is executed and the output is verified.
Exp. No. :
Date :
AIM :-
To write a program to implement the function and operator overloading.
PROGRAM :-
#include <iostream>
Return a + b;
}
// Function to add three integers
Return a + b + c;
}
Return a + b;
}
Int main() {
Cout << “Add two integers: “ << add(3, 4) << endl; // Calls add(int, int)
Cout << “Add three integers: “ << add(3, 4, 5) << endl; // Calls add(int, int, int)
cout << "Add two doubles: " << add(2.5, 3.5) << endl; // Calls add(double, double)
return 0;
Output:
RESULT :-
Thus the program to implement the function and operator overloading is executed and the
output is verified.
Exp. No. :
Date :
AIM :-
To write a program to create classes and objects .
PROGRAM :-
#include <iostream>
using namespace std;
class Car {
private:
string brand;
string model;
int year;
public:
brand = b;
model = m;
year = y;
cout << "Brand: " << brand << ", Model: " << model << ", Year: " << year << endl;
void setYear(int y) {
year = y;
int getYear() {
return year;
}
};
int main() {
car1.displayDetails();
car2.displayDetails();
car1.setYear(2021);
cout << "Updated year of car1: " << car1.getYear() << endl;
return 0;
Output:
RESULT :-
Thus the program to create classes and objects is executed and the output is verified.
Exp. No. :
Date :
IMPLEMENTATION OF CONSTRUCTORS AND DESTRUCTORS
AIM :-
To write a program to implement the constructors and destructors .
PROGRAM :-
#include <iostream>
class Person {
private:
string name;
int age;
public:
// Default constructor
Person() {
name = "Unknown";
age = 0;
// Parameterized constructor
Person(string n, int a) {
name = n;
age = a;
cout << "Parameterized constructor called for " << name << endl;
}
// Destructor
~Person() {
cout << "Destructor called for " << name << endl;
void display() {
cout << "Name: " << name << ", Age: " << age << endl;
};
int main() {
Person person1;
person1.display();
person2.display();
person3.display();
} // person3 goes out of scope here, and the destructor is called
cout << "End of main function" << endl;
return 0;
}
Output:
RESULT :-
Thus the program to implement the constructors and destructors is executed and the output is
verified.
Exp. No. :
Date :
AIM :-
To write a program to implement the array of objects and dynamic objects.
PROGRAM :-
#include <iostream>
using namespace std;
class Student {
private:
string name;
int rollNumber;
public:
// Parameterized constructor
Student(string n, int r) {
name = n;
rollNumber = r;
// Default constructor
Student() {
name = "Unknown";
rollNumber = 0;
}
// Function to display student details
void display() {
cout << "Name: " << name << ", Roll Number: " << rollNumber << endl;
}
};
int main() {
students[i].display();
return 0;
Output:
RESULT :-
Thus the program to implement the array of objects and dynamic objects is executed and the
output is verified .
Exp. No. :
Date :
AIM :-
To write a program to implement the inheritance and its types.
PROGRAM :-
#include <iostream>
using namespace std;
// Base class
class Animal {
public:
void eat() {
};
public:
void bark() {
};
public:
void beFriendly() {
};
public:
void guard() {
}
};
public:
void weep() {
};
int main() {
Dog dog;
Puppy puppy;
return 0;
Output:
RESULT :-
Thus the program to implement the inheritance and its types is executed and the output is
verified .
Exp. No. :
Date :
AIM :-
To write a program to implement the polymorphism and its types.
PROGRAM :-
#include <iostream>
using namespace std;
// Base class
class Shape {
public:
};
// Derived class
public:
};
// Derived class
class Rectangle : public Shape {
public:
};
int main() {
// Runtime polymorphism
shape1->draw(); // Output: Drawing a circle
delete shape1;
delete shape2;
return 0;
}
Output:
RESULT :-
Thus the program to implement the polymorphism and its types is executed and the output is
verified .
Exp. No. :
Date :
AIM :-
To write a program to implement the various sorting algorithms .
PROGRAM :-
#include <iostream>
}
}
I++;
Swap(arr[i], arr[j]);
quickSort(arr, pi + 1, high);
}
Int main() {
bubbleSort(arr, n);
return 0;
Output:
RESULT :-
Thus the program to implement the various sorting algorithms is executed and the output is
verified .
Exp. No. :
Date :
APPLICATION OF STACK
AIM :-
To write a program of application of stack .
PROGRAM :-
#include <iostream>
#include <stack>
Int main() {
Stack<int> stk;
Stk.push(10);
Stk.push(20);
Stk.push(30);
While (!stk.empty()) {
Cout << “Stack top: “ << stk.top() << endl;
Stk.pop();
Return 0;
}
Output:
RESULT :-
Thus the program of application of stack is executed and the output is verified .
Exp. No. :
Date :
AIM :-
To write a program to implement the queue using array .
PROGRAM :-
#include <iostream>
using namespace std;
#define SIZE 5
class Queue {
private:
public:
Queue() {
front = -1;
rear = -1;
else {
void dequeue() {
else
void display() {
if (front == -1)
else {
}
cout << endl;
};
int main() {
Queue q;
q.enqueue(10);
q.enqueue(20);
q.enqueue(30);
q.display();
q.dequeue();
q.display();
return 0;
Output:
RESULT :-
Thus the program to implement the queue using array is executed and the output is verified.
Exp. No. :
Date :
AIM :-
To write a program to implement the Linked Lists: Singly linked, doubly linked and Circular
lists and applications.
PROGRAM :-
#include <iostream>
Class Node {
Public:
Int data;
Node* next;
};
Class SinglyLinkedList {
Private:
Node* head;
Public:
SinglyLinkedList() : head(nullptr) {}
Void insert(int data) {
If (!head) {
Head = newNode;
} else {
While (temp->next)
Temp = temp->next;
Temp->next = newNode;
Void display() {
While (temp) {
Temp = temp->next;
};
Int main() {
SinglyLinkedList list;
List.insert(10);
List.insert(20);
List.insert(30);
List.display();
Return 0;
}
#include <iostream>
Class Node {
Public:
Int data;
Node* next;
Node* prev;
Node(int val) : data(val), next(nullptr), prev(nullptr) {}
};
Class DoublyLinkedList {
Private:
Node* head;
Public:
DoublyLinkedList() : head(nullptr) {}
If (!head) {
Head = newNode;
} else {
Node* temp = head;
While (temp->next)
Temp = temp->next;
Temp->next = newNode;
newNode->prev = temp;
Void display() {
While (temp) {
};
Int main() {
DoublyLinkedList list;
List.insert(10);
List.insert(20);
List.insert(30);
List.display();
Return 0;
}
#include <iostream>
Class Node {
Public:
Int data;
Node* next;
};
Class CircularLinkedList {
Private:
Node* head;
Public:
CircularLinkedList() : head(nullptr) {}
If (head == nullptr) {
Head = newNode;
} else {
Temp->next = newNode;
Void display() {
If (head == nullptr) {
Return;
}
Do {
Temp = temp->next;
If (head == nullptr) {
If (head->data == key) {
If (head->next == head) {
Delete head;
Head = nullptr;
} else {
Temp = temp->next;
}
Head = head->next;
Temp->next = head;
Delete toDelete;
Cout << “Node with value “ << key << “ deleted.” << endl;
Return;
Do {
Previous = current;
Current = current->next;
If (current->data == key) {
Previous->next = current->next;
Delete current;
Cout << “Node with value “ << key << “ deleted.” << endl;
Return;
Cout << “Node with value “ << key << “ not found.” << endl;
};
Int main() {
CircularLinkedList list;
List.insert(10);
List.insert(20);
List.insert(30);
List.insert(40);
List.display();
List.display();
List.deleteNode(40);
List.display();
List.deleteNode(10);
List.display();
List.deleteNode(30);
List.display();
Return 0;
Output:
RESULT:-
Thus the program to implement the Linked Lists: Singly linked, doubly linked and Circular
lists and applications is executed and the output is verified.