Posts

Showing posts from December, 2024

Pr13

 Pizza parlor accepting maximum M orders. Orders are served in first come first served basis. Order once placed cannot be cancelled. Write C++ program to simulate the system using circular queue using array. Objectives:- 1. To understand concept of circular queue. #include <iostream> #include <string> using namespace std; class PizzaParlor { private:     string* orders;    // Array to store pizza orders     int front;         // Front pointer (for serving orders)     int rear;          // Rear pointer (for placing orders)     int capacity;      // Maximum capacity (M orders)     int size;          // Current number of orders public:     // Constructor to initialize the queue with a given capacity     PizzaParlor(int M) {         capacity = M;         orders = new ...

Pr12

 A double-ended queue (deque) is a linear list in which additions and deletions may be made at either end. Obtain a data representation mapping a deque into a one-dimensional array. Write C++ program to simulate deque with functions to add and delete elements from either end of the deque. Objectives:- 1. To understand concept of double ended queue. 2. To study the different types of double ended queues. #include <iostream> using namespace std; class Deque { private:     int* arr;       // Array to store deque elements     int front;      // Front pointer     int rear;       // Rear pointer     int capacity;   // Maximum size of deque     int size;       // Current size of deque public:     // Constructor to initialize deque with a given capacity     Deque(int cap) {         capacity = cap;     ...

Pr11

 Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. If the operating system does not use priorities, then the jobs are processed in the order they enter the system. Write C++ program for simulating job queue. Write functions to add job and delete job from queue Objectives:- 1. To understand concept of queue. 2. To study the different types of queues. 3. To study the job scheduling problem as queue application. #include <iostream> #include <string> using namespace std; // Define a structure for a job node struct JobNode {     string jobID;  // Job identifier (could be a string or any type of ID)     JobNode* next; // Pointer to the next job node          JobNode(string id) : jobID(id), next(nullptr) {} }; // Class to represent a job queue class JobQueue { private:     JobNode* front; // Front pointer of the queue     JobNode*...

Pr10

 Implement C++ program for expression conversion as infix to postfix and its evaluation using stack based on given conditions: 1. Operands and operator, both must be single character. 2. Input Postfix expression must be in a desired format. 3. Only '+', '-', '*' and '/ ' operators are expected. OBJECTIVE: 1. Understand Stack ADT. 2. Understand stack application for Expression conversion and evaluation. #include <iostream> #include <stack> #include <cctype> #include <string> using namespace std; // Function to check if the character is an operator bool isOperator(char c) {     return (c == '+' || c == '-' || c == '*' || c == '/'); } // Function to get the precedence of the operator int precedence(char op) {     if (op == '+' || op == '-') {         return 1; // lower precedence     }     if (op == '*' || op == '/') {         return 2; // higher precedence     }   ...

pr9

 A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, and spaces are ignored. For example, “Poor Dan is in a droop” is a palindrome, as can be seen by examining the characters “poor danisina droop” and observing that they are the same forward and backward. One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program with functionsa)To print original string followed by reversed string using stack b)To check whether given string is palindrome or not #include <iostream> #include <stack> #include <string> #include <cctype> using namespace std; // Function to print original string followed by reversed string using stack void printOriginalAndReversed(const string& str) {     stack<char> s;     // Push each character of the string to the stack   ...

pr8

 Write C++ program for storing binary number using doubly linked lists. Write functions a)To compute 1‘s and 2‘s complement b)Add two binary numbers OBJECTIVES: 1. To understand concept of OOP. 2. To understand class structures for DLL in C++. 3. To understand primitive operations on DLL. #include <iostream> #include <string> using namespace std; // Define a structure for a doubly linked list node struct Node {     int bit;     Node* next;     Node* prev;          Node(int b) : bit(b), next(nullptr), prev(nullptr) {} }; // Class to represent a binary number using a doubly linked list class BinaryNumber { private:     Node* head;  // Head pointer for the doubly linked list     Node* tail;  // Tail pointer for the doubly linked list      public:     BinaryNumber() : head(nullptr), tail(nullptr) {}     // Function to add a bit at the end of the list (repr...

pr7

 Department of Computer Engineering has student's club named 'Pinnacle Club'. Students of Second, third and final year of department can be granted membership on request. Similarly one may cancel the membership of club. First node is reserved for president of club and last node is reserved for secretary of club. Write C++ program to maintain club member‘s information using singly linked list. Store student PRN and Name. Write functions to a) Add and delete the members as well as president or even secretary. b) Compute total number of members of club c) Display members d) Display list in reverse order using recursion e) Two linked lists exists for two divisions. Concatenate two lists #include <iostream> #include <string> using namespace std; // Define a structure for a student node struct Student {     string prn;     string name;     Student* next; }; // Define a class for managing the club's members class PinnacleClub { private:   ...

PR6

 Write a Python program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using Quick Sort. OBJECTIVES: 1. To understand concept of Quick Sort. 2. To study the Quick Sort technique. 3. To study the application Quick Sort method. # Quick Sort function without using any built-in methods or classes def quick_sort(arr, low, high):     if low < high:         # Partitioning index         pi = partition(arr, low, high)                  # Recursively sort elements before and after partition         quick_sort(arr, low, pi - 1)         quick_sort(arr, pi + 1, high) # Function to partition the array for Quick Sort def partition(arr, low, high):     pivot = arr[high]  # Taking the last element as the pivot     i = low - 1  # Index of smaller elemen...

PR5

 Write a Python program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using 1. Selection Sort 2. Bubble sort and display top five scores. # Main program that takes user input and sorts the percentages without using functions or built-in methods n = int(input("Enter the number of students: "))  # Number of students percentages = [] print("Enter the percentages of students:") for i in range(n):     percentage = float(input(f"Percentage of student {i + 1}: "))     percentages.append(percentage) # Display the original list print("\nOriginal percentages:") for percentage in percentages:     print(percentage, end=" ") # Selection Sort (Without using functions) selection_sorted = percentages.copy() # Perform selection sort on the array for i in range(n):     # Find the index of the smallest element in the unsorted part     min_idx = i     fo...

pr4

 Write a Python program to maintain club members, sort on roll numbers in ascending order. Write function “Ternary_Search” to search whether particular student is member of club or not. Ternary search is modified binary search that divides array into 3 halves instead of two # Function to sort the roll numbers in ascending order (bubble sort) def sort_roll_numbers(roll_numbers):     n = len(roll_numbers)     for i in range(n):         for j in range(0, n - i - 1):             if roll_numbers[j] > roll_numbers[j + 1]:                 # Swap the elements                 roll_numbers[j], roll_numbers[j + 1] = roll_numbers[j + 1], roll_numbers[j] # Ternary search function def ternary_search(array, left, right, key):     if right >= left:         # Divide array into three parts        ...

pr3

 Write a python program to compute following computation on matrix: a) Addition of two matrices b) Subtraction of two matrices c) Multiplication of two matrices d) Transpose of a matrix # Matrix operations without using built-in functions, packages, or classes # Function to add two matrices def add_matrices(matrix1, matrix2):     rows, cols = len(matrix1), len(matrix1[0])     result = [[0 for _ in range(cols)] for _ in range(rows)]     for i in range(rows):         for j in range(cols):             result[i][j] = matrix1[i][j] + matrix2[i][j]     return result # Function to subtract two matrices def subtract_matrices(matrix1, matrix2):     rows, cols = len(matrix1), len(matrix1[0])     result = [[0 for _ in range(cols)] for _ in range(rows)]     for i in range(rows):         for j in range(cols):             result...

PR2

 Write a Python program to compute following operations on String: a) To display word with the longest length b) To determines the frequency of occurrence of particular character in the string c) To check whether given string is palindrome or not d) To display index of first appearance of the substring e) To count the occurrences of each word in a given string # Function to display the word with the longest length def longest_word(string):     words = []     word = ""     for char in string:         if char == ' ':             if word:                 words.append(word)             word = ""         else:             word += char     if word:         words.append(word)     max_length = 0     longest = ""     for w in words: ...

PR1

 Write a Python program to store marks scored in subject “Fundamental of Data Structure” by N students in the class. Write functions to compute following: a)The average score of class b)Highest score and lowest score of class c)Count of students who were absent for the test d)Display mark with highest frequency # Function to compute the average score of the class def compute_average(marks):     total_marks = sum(marks)     num_students = len(marks)     return total_marks / num_students if num_students > 0 else 0 # Function to find the highest and lowest score in the class def find_highest_lowest(marks):     return max(marks), min(marks) # Function to count the number of students absent for the test def count_absentees(marks):     return marks.count(-1) # Function to find the mark with the highest frequency def mark_with_highest_frequency(marks):     frequency = {}     for mark in marks:       ...