C - Code of Practical
C - Code of Practical
INPUT
#include <iostream>
#include <string>
using namespace std;
struct Node {
string PRN; // PRN number
string name; // Name of the student
Node* next; // Pointer to the next node
};
int main() {
Node* division1 = nullptr;
Node* division2 = nullptr;
// Deleting a member
deleteMember(concatenatedList, "PRN003");
cout << "\nMembers after deleting PRN003:" << endl;
displayMembers(concatenatedList);
return 0;
}
OUTPUT
/tmp/zpW0Gwklw1.o
Members of Division 1:
PRN: PRN001, Name: Alice
PRN: PRN002, Name: Bob
PRN: PRN003, Name: Charlie
Members of Division 2:
PRN: PRN004, Name: David
PRN: PRN005, Name: Eve
PRACTICAL NO 8
INPUT
#include <iostream>
using namespace std;
struct Node {
int data; // Stores binary digit (0 or 1)
Node* next;
Node* prev;
};
// Function to add a binary digit to the end of the doubly linked list
void addBinaryDigit(Node*& head, int data) {
Node* newNode = new Node{data, nullptr, nullptr};
if (!head) {
head = newNode;
} else {
Node* temp = head;
while (temp->next != nullptr) {
temp = temp->next;
}
temp->next = newNode;
newNode->prev = temp;
}
}
int carry = 0;
// Start adding from the least significant bit
while (temp1 || temp2 || carry) {
int sum = carry;
if (temp1) {
sum += temp1->data;
temp1 = temp1->prev;
}
if (temp2) {
sum += temp2->data;
temp2 = temp2->prev;
}
carry = sum / 2;
addBinaryDigit(result, sum % 2); // Add the digit to the result list
}
return result;
}
int main() {
Node* binary1 = nullptr;
Node* binary2 = nullptr;
return 0;
}
OUTPUT
/tmp/LR4NnN5Y2Z.o
First Binary Number: 1011
Second Binary Number: 1101
1's Complement of First Binary: 0100
2's Complement of First Binary: 0101
Sum of the two Binary Numbers: 01001
#include <iostream>
#include <stack>
#include <string>
using namespace std;
// Pop all characters from the stack and form the reversed string
while (!s.empty()) {
reversed += s.top();
s.pop();
}
return reversed;
}
int main() {
string input;
return 0;
}
SAMPLE INPUT/OUTPUT
/tmp/dk91AkFHoR.o
Enter a string: Poor Dan is in a droop
Original String: Poor Dan is in a droop
Reversed String: poord a ni si naD rooP
The string is not a palindrome.
PRACTICAL NO 10
INPUT
#include <iostream>
#include <stack>
#include <string>
using namespace std;
return postfix;
}
int main() {
string infix;
return 0;
}
SAMPE INPUT/OUTPUT
1.
Enter infix expression: A+B*C
Postfix expression: ABC*+
2.
Enter infix expression: (A+B)*(C-D)
Postfix expression: AB+CD-*
=== Code Execution Successful ===
PRACTICAL NO 11
INPUT
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main() {
queue<string> jobQueue;
int choice;
string job;
do {
cout << "\n1. Add Job\n2. Delete Job\n3. Display Jobs\n4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter job description: ";
cin.ignore(); // To ignore leftover newline from previous input
getline(cin, job);
addJob(jobQueue, job);
break;
case 2:
deleteJob(jobQueue);
break;
case 3:
displayJobs(jobQueue);
break;
case 4:
cout << "Exiting..." << endl;
break;
default:
cout << "Invalid choice! Please try again." << endl;
}
} while (choice != 4);
return 0;
}
SAMPLE INPUT/OUTPUT
1. Add Job
2. Delete Job
3. Display Jobs
4. Exit
Enter your choice: 1
Enter job description: Compile the project
Job added: Compile the project
1. Add Job
2. Delete Job
3. Display Jobs
4. Exit
Enter your choice: 1
Enter job description: Test the program
Job added: Test the program
1. Add Job
2. Delete Job
3. Display Jobs
4. Exit
Enter your choice: 3
Current Jobs in the Queue: Compile the project Test the program
1. Add Job
2. Delete Job
3. Display Jobs
4. Exit
Enter your choice: 2
Job completed and removed: Compile the project
=== Code Execution Successful ===
PRACTICAL NO 12
INPUT
#include <iostream>
using namespace std;
class PizzaParlor {
int orders[MAX];
int front, rear;
public:
PizzaParlor() {
front = -1;
rear = -1;
}
orders[rear] = order;
cout << "Order " << order << " added successfully!" << endl;
}
cout << "Order " << orders[front] << " is served." << endl;
if (front == rear) {
// Only one order was in the queue
front = rear = -1;
} else if (front == MAX - 1) {
front = 0; // Wrap around
} else {
front++;
}
}
int main() {
PizzaParlor p;
int choice, order;
do {
cout << "\n1. Add Order\n2. Serve Order\n3. Display Orders\n4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter order number: ";
cin >> order;
p.addOrder(order);
break;
case 2:
p.serveOrder();
break;
case 3:
p.displayOrders();
break;
case 4:
cout << "Exiting..." << endl;
break;
default:
cout << "Invalid choice! Please try again." << endl;
}
} while (choice != 4);
return 0;
}
SAMPLE INPUT/OUTPUT
1. Add Order
2. Serve Order
3. Display Orders
4. Exit
Enter your choice: 1
Enter order number: 101
Order 101 added successfully!
1. Add Order
2. Serve Order
3. Display Orders
4. Exit
Enter your choice: 3
Current orders in the queue: 101
1. Add Order
2. Serve Order
3. Display Orders
4. Exit
Enter your choice: 2
Order 101 is served.
1. Add Order
2. Serve Order
3. Display Orders
4. Exit
Enter your choice: 3
No orders in the queue.
PRACTICAL NO 13
INPUT
#include <iostream>
using namespace std;
class Deque {
int deque[MAX];
int front, rear;
public:
Deque() {
front = -1;
rear = -1;
}
deque[front] = value;
cout << "Inserted " << value << " at front." << endl;
}
deque[rear] = value;
cout << "Inserted " << value << " at rear." << endl;
}
// Function to delete an element from the front
void deleteFront() {
if (isEmpty()) {
cout << "Deque is empty! Cannot delete from front." << endl;
return;
}
cout << "Deleted " << deque[front] << " from front." << endl;
cout << "Deleted " << deque[rear] << " from rear." << endl;
int main() {
Deque dq;
int choice, value;
do {
cout << "\n1. Insert at Front\n2. Insert at Rear\n3. Delete from Front\n4. Delete from Rear\n5. Display
Deque\n6. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter value to insert at front: ";
cin >> value;
dq.insertFront(value);
break;
case 2:
cout << "Enter value to insert at rear: ";
cin >> value;
dq.insertRear(value);
break;
case 3:
dq.deleteFront();
break;
case 4:
dq.deleteRear();
break;
case 5:
dq.displayDeque();
break;
case 6:
cout << "Exiting..." << endl;
break;
default:
cout << "Invalid choice! Please try again." << endl;
}
} while (choice != 6);
return 0;
}
Sample Input/Output:
1. Insert at Front
2. Insert at Rear
3. Delete from Front
4. Delete from Rear
5. Display Deque
6. Exit
Enter your choice: 1
Enter value to insert at front: 10
Inserted 10 at front.
1. Insert at Front
2. Insert at Rear
3. Delete from Front
4. Delete from Rear
5. Display Deque
6. Exit
Enter your choice: 2
Enter value to insert at rear: 20
Inserted 20 at rear.
1. Insert at Front
2. Insert at Rear
3. Delete from Front
4. Delete from Rear
5. Display Deque
6. Exit
Enter your choice: 5
Deque elements: 10 20
1. Insert at Front
2. Insert at Rear
3. Delete from Front
4. Delete from Rear
5. Display Deque
6. Exit
Enter your choice: 3
Deleted 10 from front.