0% found this document useful (0 votes)
4 views6 pages

Pizza Parlor Order Management System

The document contains multiple code snippets in C++ and Python demonstrating various algorithms and data structures. Key functionalities include a pizza parlor order management system, heap sort, merge sort, naive string matching, and infix to postfix/prefix conversion with evaluation. Each section includes a main program that allows user interaction for input and output.

Uploaded by

MAHENDRA GADHAVE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Pizza Parlor Order Management System

The document contains multiple code snippets in C++ and Python demonstrating various algorithms and data structures. Key functionalities include a pizza parlor order management system, heap sort, merge sort, naive string matching, and infix to postfix/prefix conversion with evaluation. Each section includes a main program that allows user interaction for input and output.

Uploaded by

MAHENDRA GADHAVE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

***2-A***

#include <iostream>
using namespace std;

#define MAX 5 // maximum number of orders

class PizzaParlor {
int orders[MAX];
int front, rear;

public:
PizzaParlor() { front = rear = -1; }

bool isFull() { return (front == (rear + 1) % MAX); }


bool isEmpty() { return (front == -1); }

void placeOrder(int orderNo) {


if (isFull())
cout << "Cannot place order, parlor is full!\n";
else {
if (front == -1) front = 0;
rear = (rear + 1) % MAX;
orders[rear] = orderNo;
cout << "Order " << orderNo << " placed successfully.\n";
}
}

void serveOrder() {
if (isEmpty())
cout << "No orders to serve!\n";
else {
cout << "Order " << orders[front] << " served.\n";
if (front == rear)
front = rear = -1;
else
front = (front + 1) % MAX;
}
}

void display() {
if (isEmpty())
cout << "No pending orders.\n";
else {
cout << "Pending Orders: ";
int i = front;
while (i != rear) {
cout << orders[i] << " ";
i = (i + 1) % MAX;
}
cout << orders[rear] << endl;
}
}
};

int main() {
PizzaParlor p;
int choice, orderNo = 1;

do {
cout << "\[Link] Order\[Link] Order\[Link] Orders\[Link]\nEnter choice: ";
cin >> choice;
switch (choice) {
case 1: [Link](orderNo++); break;
case 2: [Link](); break;
case 3: [Link](); break;
case 4: cout << "Exiting...\n"; break;
default: cout << "Invalid choice!\n";
}
} while (choice != 4);

return 0;
}

***3-B***
def heapify(arr, n, i):
largest = i # Initialize largest as root
left = 2 * i + 1 # left child
right = 2 * i + 2 # right child

# If left child exists and is greater than root


if left < n and arr[left] > arr[largest]:
largest = left

# If right child exists and is greater than largest so far


if right < n and arr[right] > arr[largest]:
largest = right

# If largest is not root, swap and continue heapifying


if largest != i:
arr[i], arr[largest] = arr[largest], arr[i]
heapify(arr, n, largest)

def heap_sort(arr):
n = len(arr)

# Build max heap


for i in range(n // 2 - 1, -1, -1):
heapify(arr, n, i)

# Extract elements one by one


for i in range(n - 1, 0, -1):
arr[i], arr[0] = arr[0], arr[i] # swap
heapify(arr, i, 0)

# ---- Main Program ----


marks = list(map(int, input("Enter marks separated by space: ").split()))
heap_sort(marks)
print("Sorted marks:", marks)
print("Minimum marks:", marks[0])
print("Maximum marks:", marks[-1])

***4-A***
def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
left = arr[:mid]
right = arr[mid:]

# Recursive sort both halves


merge_sort(left)
merge_sort(right)

i=j=k=0

# Merge the two halves


while i < len(left) and j < len(right):
if left[i] < right[j]:
arr[k] = left[i]
i += 1
else:
arr[k] = right[j]
j += 1
k += 1

# Copy remaining elements (if any)


while i < len(left):
arr[k] = left[i]
i += 1
k += 1
while j < len(right):
arr[k] = right[j]
j += 1
k += 1

# ---- Main Program ----


orders = list(map(int, input("Enter estimated delivery times (in minutes): ").split()))
merge_sort(orders)

print("\nOrders sorted by quickest delivery time:")


print(orders)
print(f"\nFastest delivery: {orders[0]} min")
print(f"Slowest delivery: {orders[-1]} min")
***6-A***
def naive_string_match(text, pattern):
n, m = len(text), len(pattern)
positions = []

for i in range(n - m + 1):


if text[i:i+m] == pattern:
[Link](i)
return positions

# ---- Main Program ----


text = input("Enter text: ")
pattern = input("Enter pattern: ")

result = naive_string_match(text, pattern)

if result:
print("Pattern found at indices:", result)
else:
print("Pattern not found.")

***1-B***
#include <iostream>
#include <stack>
#include <algorithm>
#include <cmath>
using namespace std;

int prec(char c) {
if (c == '^') return 3;
if (c == '*' || c == '/') return 2;
if (c == '+' || c == '-') return 1;
return -1;
}

// Infix to Postfix
string infixToPostfix(string s) {
stack<char> st;
string res;
for (char c : s) {
if (isalnum(c)) res += c;
else if (c == '(') [Link](c);
else if (c == ')') {
while (![Link]() && [Link]() != '(') {
res += [Link](); [Link]();
}
[Link]();
} else {
while (![Link]() && prec([Link]()) >= prec(c)) {
res += [Link](); [Link]();
}
[Link](c);
}
}
while (![Link]()) { res += [Link](); [Link](); }
return res;
}

// Infix to Prefix
string infixToPrefix(string s) {
reverse([Link](), [Link]());
for (char &c : s)
if (c == '(') c = ')'; else if (c == ')') c = '(';
string pre = infixToPostfix(s);
reverse([Link](), [Link]());
return pre;
}

// Evaluate Postfix
int evalPostfix(string s) {
stack<int> st;
for (char c : s) {
if (isdigit(c)) [Link](c - '0');
else {
int b = [Link](); [Link]();
int a = [Link](); [Link]();
if (c == '+') [Link](a + b);
else if (c == '-') [Link](a - b);
else if (c == '*') [Link](a * b);
else if (c == '/') [Link](a / b);
else if (c == '^') [Link](pow(a, b));
}
}
return [Link]();
}

// Evaluate Prefix
int evalPrefix(string s) {
stack<int> st;
for (int i = [Link]() - 1; i >= 0; i--) {
char c = s[i];
if (isdigit(c)) [Link](c - '0');
else {
int a = [Link](); [Link]();
int b = [Link](); [Link]();
if (c == '+') [Link](a + b);
else if (c == '-') [Link](a - b);
else if (c == '*') [Link](a * b);
else if (c == '/') [Link](a / b);
else if (c == '^') [Link](pow(a, b));
}
}
return [Link]();
}

int main() {
string infix;
cout << "Enter infix expression: ";
cin >> infix;

string postfix = infixToPostfix(infix);


string prefix = infixToPrefix(infix);

cout << "\nPostfix: " << postfix;


cout << "\nPrefix: " << prefix;
cout << "\nPostfix Value: " << evalPostfix(postfix);
cout << "\nPrefix Value: " << evalPrefix(prefix) << endl;
}

You might also like