Online Cake Ordering System: 1) Add a new order 2) Retrieve an order 3) Deliver an order 4) Print summary report 5) Exit system
Add a new order
Retrieve an order
The system shall retrieve and remove the order (with the nearest delivery data and time) from the binary heap data structure and update the status as “in progress” and move the order into a queue data structure.
Deliver an order
The user will retrieve a work in progress order from queue based on first in first out (FIFO) concept and move the order to a stack. Status of the order will be updated as “delivered”.
View summary report
Note: No built-in classes of the data structure (heap, queue and stack) are allowed.
import time
main_menu=('Add a new order', 'Retrieve an order', 'Deliver an order', 'Print summary report', 'Exit system')
class Bin_heap:
def __init__(self):
self.heap_list = [[0]]
self.current_size = 0
def perc_up(self,i):
while i // 2 > 0:
if self.heap_list[i][0] < self.heap_list[i // 2][0]:
tmp = self.heap_list[i // 2]
self.heap_list[i // 2] = self.heap_list[i]
self.heap_list[i] = tmp
i = i // 2
def insert(self,k):
self.heap_list.append(k)
self.current_size = self.current_size + 1
self.perc_up(self.current_size)
def perc_down(self,i):
while (i * 2) <= self.current_size:
mc = self.min_child(i)
if self.heap_list[i][0] > self.heap_list[mc][0]:
tmp = self.heap_list[i]
self.heap_list[i] = self.heap_list[mc]
self.heap_list[mc] = tmp
i = mc
def min_child(self,i):
if i * 2 + 1 > self.current_size:
return i * 2
else:
if self.heap_list[i*2][0] < self.heap_list[i*2+1][0]:
return i * 2
else:
return i * 2 + 1
def del_min(self):
retval = self.heap_list[1]
self.heap_list[1] = self.heap_list[self.current_size]
self.current_size = self.current_size - 1
self.heap_list.pop()
self.perc_down(1)
return retval
def build_heap(self,alist):
i = len(alist) // 2
self.current_size = len(alist)
self.heap_list = [0] + alist[:]
while (i > 0):
self.perc_down(i)
i = i - 1
def print_all(self):
return self.heap_list
def new_id():
time.sleep(0.0001)
s = str(time.time())
new_s = ''
for el in s:
if el.isdigit():
new_s += el
return int(new_s)
def add_order():
info = []
info.append(new_id())
info.append(input('Delivery date and time: '))
info.append(input('Name of the cake: '))
info.append(input('Weight of the cake: '))
info.append(input('Price of the cake: '))
info.append('New')
heap_data.insert(info)
print('Order added ')
heap_data = Bin_heap()
while True:
for i in range(len(main_menu)):
print('{}) {}'.format(i+1, main_menu[i]))
try:
com = int(input('goto '))
except ValueError:
print('incorrect input')
continue
if com == 5:
break
elif com == 1:
add_order()
Comments
Leave a comment