Answer To: ITECH5403 – Comparative Programming Languages School of Science, Engineering and Information...
Yogesh answered on Sep 26 2021
Lisp Code/pizzaorders.txt
Name: Yogesh.@Phone Number: 8075462515.@Address: N.A..@@1.) Pizza size: Small, Price: $5, Number of Pizzas: 4, @ Toppings: Bacon, Mushrooms, Anchovies, Pineapple.@@2.) Pizza size: Medium, Price: $8, Number of Pizzas: 1, @ Toppings: Mushrooms, Anchovies, Bacon, Pineapple.@1$ charged for Each Topping on each pizza.@@Order Type: Collect. @@Total Amount: $48.
Name: Yogi.@Phone Number: 8888888888.@Address: austrelia.@@1.) Pizza size: Large, Price: $12, Number of Pizzas: 1, @ Toppings: Bacon, Mushrooms, Anchovies, Pineapple.@1$ charged for Each Topping on each pizza.@@Order Type: Deliver.@(Additional $8 Delivery Charge for Total Amount below $30.)@@Total Amount: $24.
Name: Yogisan.@Phone Number: 8787878798.@Address: N.A..@@1.) Pizza size: Small, Price: $5, Number of Pizzas: 4, @ Toppings: Bacon, Mushrooms, Anchovies, Pineapple.@@2.) Pizza size: Medium, Price: $8, Number of Pizzas: 1, @ Toppings: Bacon, Mushrooms, No Topping, Anchovies.@1$ charged for Each Topping on each pizza.@@Order Type: Collect. @@Total Amount: $47.
Lisp Code/PizzaShop.lisp
(setq *print-case* :capitalize)
;file for storing data
(setq *creds* "pizzaorders.txt")
; temp list storing data before storing to text file
(defparameter *file* (make-array 5 :initial-element 'fl)) ;[fl, fl, fl, fl, fl]
; list of pizza sizes
(defparameter *sizes* (make-array 4 :initial-element 'None)) ;["None", "Small", "Medium", "Large"]
(setf (aref *sizes* 0) "None")
(setf (aref *sizes* 1) "Small")
(setf (aref *sizes* 2) "Medium")
(setf (aref *sizes* 3) "Large")
; list of pizza prices according to size
(defparameter *price* (make-array 4 :initial-element 0)) ; [0, 5, 8, 12]
(setf (aref *price* 0) 0)
(setf (aref *price* 1) 5)
(setf (aref *price* 2) 8)
(setf (aref *price* 3) 12)
; list of pizza toppings
(defparameter *toppings* (make-array 8 :initial-element 'NoTopping)) ; ["No Topping", "Bacon", "Olives", "Ham", "Mushrooms", "Pineapple", "Salami", "Anchovies"]
(setf (aref *toppings* 0) "No Topping")
(setf (aref *toppings* 1) "Bacon")
(setf (aref *toppings* 2) "Olives")
(setf (aref *toppings* 3) "Ham")
(setf (aref *toppings* 4) "Mushrooms")
(setf (aref *toppings* 5) "Pineapple")
(setf (aref *toppings* 6) "Salami")
(setf (aref *toppings* 7) "Anchovies")
; list of order type
(defparameter *ortype* (make-array 3 :initial-element '"None")) ; ["None", "Collect", "Deliver"]
(setf (aref *ortype* 0) "None")
(setf (aref *ortype* 1) "Collect")
(setf (aref *ortype* 2) "Deliver")
; order list flags.
(defparameter *order* (make-array '(10 8) :initial-element 0))
(defun start0()
(format t "~%~%-------------------------------------------------------------------------")
(format t "~%--------------------- Welcome to Pizza Shop ---------------------")
(format t "~%-------------------------------------------------------------------------")
(format t "~%Main Menu - ")
(format t "~% Option 1.) Add Order.")
(format t "~% Option 2.) View Orders.")
(format t "~% Option 3.) Exit.")
(start1)
)
(defun start1()
(format t "~%Please Enter an Option: ")
(setq ip0a (read))
(if (equalp ip0a 1)
(start3)
(if (equalp ip0a 2)
(views)
(if (equalp ip0a 3)
(exitp)
(excep0)
)))
)
(defun excep0()
(format t "~%~%Please Enter the Correct Option.")
(start1)
)
(defun exitp()
(format t "~%~%Do you really want to QUIT ?")
(format t "~%[Y]es / [N]o : ")
(setq aq5 (read))
(setq y 'y)
(setq n 'n)
(if (equalp aq5 y)
(endprog)
(if (equalp aq5 n)
(gotostart)
(if (equalp aq5 " ")
(gotostart)
(excep1)
)))
)
(defun endprog()
(format t "~%~% Thanks for using Pizza Shop Application...!~%~%")
(quit)
)
(defun gotostart()
(format t " ")
(start0)
)
(defun excep1()
(format t "~%Please Enter Correct Option...")
(exitp)
)
(defun start2()
(format t "~%~%Add a new Order...")
(start3)
)
(defun start3()
(format t "~%~%Please Select an Option for Pizza Size from below: ")
(format t "~% Option 1.) Small Pizza - $5 ")
(format t "~% Option 2.) Medium Pizza - $8 ")
(format t "~% Option 3.) Large Pizza - $12 ")
(sizeselect)
)
(defun sizeselect()
(defparameter *psize* 0)
(format t "~%Please Enter an Option for Pizza Size : ")
(setq *inp1a* (read))
(if (or (equalp *inp1a* 1)(equalp *inp1a* 2)(equalp *inp1a* 3))
(size2)
(excep2)
)
)
(defun size2()
(setq *psize* *inp1a*)
(sizesave)
)
(defun excep2()
(format t "~%~%Please Enter the Correct Option for Pizza size.")
(sizeselect)
)
(defun sizesave()
(defparameter *i* 0)
(loop for j from 0 to 9
do (setq s (aref *order* j 0))
(if (not(equalp s 0))
(setq *i* (+ *i* 1))
)
)
(setf (aref *order* *i* 0) *psize*)
(format t "~%All pizzas come on a 'Tomato base'(for our Pizza Shop this is the only option),
and have the topping 'Cheese' by default, at no Extra cost.
You may Choose up to a Maximum of '4' additional toppings from the following list :-
(Each topping adds an additional $1 to the price of the pizza.)")
(format t "~%~%Please Select an Option for Toppings from below: ")
(format t "~% Option 0.) No Topping")
(format t "~% Option 1.) Bacon")
(format t "~% Option 2.) Olives")
(format t "~% Option 3.) Hum")
(format t "~% Option 4.) Mushrooms")
(format t "~% Option 5.) Pineapple")
(format t "~% Option 6.) Salami")
(format t "~% Option 7.) Anchovies")
(toppingselect)
)
(defun toppingselect()
(format t "~%Please Enter an Option between '0' and '7' : ")
(format t "~%Please Enter First topping : ")
(setq *topping1* (read))
(format t "~%Please Enter Second topping : ")
(setq *topping2* (read))
(format t "~%Please Enter Third topping : ")
(setq *topping3* (read))
(format t "~%Please Enter Fourth topping : ")
(setq *topping4* (read))
(if (and (and (>= *topping1* 0) (<= *topping1* 7)) (and (>= *topping2* 0) (<= *topping2* 7))
(and (>= *topping3* 0) (<= *topping3* 7)) (and (>= *topping4* 0) (<= *topping4* 7)))
(setvalues)
(excep3))
)
(defun setvalues()
(setf (aref *order* *i* 1) *topping1*)
(setf (aref *order* *i* 2) *topping2*)
(setf (aref *order* *i* 3) *topping3*)
(setf (aref *order* *i* 4) *topping4*)
(showpizza)
)
(defun excep3()
(format t "~%~%Please Enter Correct Toppings Options...")
(toppingselect)
)
(defun showpizza()
(format t "~%~%Your Customized Pizzas are: ")
(loop for j from 0 to 9
do (setq s (aref *order* j 0))
(if (not(equalp s 0))
(format t "~% Pizza Size: ~a, Toppings: ~a, ~a, ~a, ~a." (aref *sizes* (aref *order* j 0)) (aref *toppings* (aref *order* j 1))
(aref *toppings* (aref *order* j 2)) (aref *toppings* (aref *order* j 3)) (aref *toppings* (aref *order* j 4))))
(if (not (equalp (aref *order* j 5) 0))
(format t "~% Quantity: ~d.~%" (aref *order* j 5)))
)
(pizzacount)
)
(defun pizzacount()
(format t "~%~%Please Enter number of Pizzas: ")
(setq pizzano (read))
(setf (aref *order* *i* 5) pizzano)
(check0)
)
(defun check0()
(format t "~%~%Would you like to Add another pizza in your Order ? ([Y]es/[N]o)")
(setq ans (read))
(setq y 'y)
(setq n 'n)
(if (equalp ans y)
(start3)
(if (equalp ans n)
(ordertype)
(if (equalp ans " ")
(excep4)
(excep4))))
)
(defun excep4()
(format t "~%~%Please Enter Valid Option...")
(check0)
)
(defun ordertype()
(format t "~%Will you [C]ollect your Order from Shop or want to get [D]elivered to you ?")
(setq ans (read))
(setq c 'c)
(setq d 'd)
(loop for j from 0 to 9
do (setq s (aref *order* j 0 ))
(if (not (equalp s 0))
(if (equalp ans c)
(setf (aref *order* j 6) 1)
(if (equalp ans d)
(setf (aref *order* j 6) 2)
(if (equalp ans " ")
(excep5)
(excep5))))
)
)
(enterdetails)
)
(defun excep5()
(format t "~%~%Please Enter Valid Option.")
(ordertype)
)
(defun enterdetails()
(format t "~%Please enter your Name: ")
(setq *name* (read-line))
(format t "~%Please enter your Phone Number: ")
(setq *phone* (read-line))
(setq *address* '"N.A.")
(if (equalp (aref *order* 0 6) 2)
(add)
)
(showorder)
)
(defun add()
(format t "~%Please enter delivery Address: ")
(setq *address* (read-line))
)
(defun showorder()
(setq namec (string-capitalize *name*))
(format t "~%~%--------------------- Order Invoice ---------------------")
(setq *invoicep1* (format nil "~%Name: ~a.~%Phone Number: ~a.~%Address: ~a." namec *phone* *address*))
(setq *save1* (format nil "Name: ~a.@Phone Number: ~a.@Address: ~a." namec *phone* *address*))
(format t *invoicep1*)
(setq *totalprice* 0)
(setq *k* 1)
(defparameter *invoicep2* (make-array 10 :initial-element 'a)) ;[a, a, a, a, a, a, a, a, a, a]
(defparameter *save2* (make-array 10 :initial-element 'a)) ;[a, a, a, a, a, a, a, a, a, a]
(loop for j from 0 to 9
do (setq s (aref *order* j 0))
(if (not (equalp s 0))
(progn
(loop for k from 1 to 4
do (if (not (equalp (aref *order* j k) 0))
(setq *totalprice* (+ *totalprice* (aref *order* j 5)))
)
)
(setq *totalprice* (+ *totalprice* (* (aref *price* (aref *order* j 0)) (aref *order* j 5))))
(setf (aref *invoicep2* j) (format nil "~%~%~d.) Pizza size: ~a, Price: $~d, Number of Pizzas: ~d, ~% Toppings: ~a, ~a, ~a, ~a."
*k* (aref *sizes* (aref *order* j 0)) (aref *price* (aref *order* j 0)) (aref *order* j 5) (aref *toppings* (aref *order* j 1))
(aref *toppings* (aref *order* j 2)) (aref *toppings* (aref *order* j 3)) (aref *toppings* (aref *order* j 4))))
(setf (aref *save2* j) (format nil "@@~d.) Pizza size: ~a, Price: $~d, Number of Pizzas: ~d, @ Toppings: ~a, ~a, ~a, ~a."
*k* (aref *sizes* (aref *order* j 0)) (aref *price* (aref *order* j 0)) (aref *order* j 5) (aref *toppings* (aref *order* j 1))
(aref *toppings* (aref *order* j 2)) (aref *toppings* (aref *order* j 3)) (aref *toppings* (aref *order* j 4))))
(format t (aref *invoicep2* j))
(setq *k* (+ *k* 1))
)
)
)
(setq *invoicep3* (format nil "~%1$ charged for Each Topping on each pizza.~%~%Order Type: ~a." (aref *ortype* (aref *order* 0 6))))
(setq *save3* (format nil "@1$ charged for Each Topping on each pizza.@@Order Type: ~a." (aref *ortype* (aref *order* 0 6))))
(setq *invoicep4* " ")
(setq *save4* " ")
(if (and (<= *totalprice* 30) (equalp (aref *order* 0 6) 2))
(progn
(setq *totalprice* (+ *totalprice* 8))
(setq *invoicep4* (format nil "~%~%(Additional $8 Delivery Charge for Total Amount below $30.)"))
(setq *save4* (format nil "@(Additional $8 Delivery Charge for Total Amount below $30.)")))
)
(setq *invoicep5* (format nil "~%~%Total Amount: $~d." *totalprice*))
(setq *save5* (format nil "@@Total Amount: $~d." *totalprice*))
(format t *invoicep3*)
(format t *invoicep4*)
(format t *invoicep5*)
(setf (aref *file* 0) *save1*)
(setf (aref *file* 1) "")
(setq a 'a)
(loop for j from 0 to 9
do (if (not (equalp (aref *save2* j) a))
(setf (aref *file* 1) (concatenate 'string (aref *file* 1) "" (aref *save2* j)))
)
)
(setf (aref *file* 2) *save3*)
(setf (aref *file* 3) *save4*)
(setf (aref *file* 4) *save5*)
(setq save (format nil "~a~a~a~a~a" (aref *file* 0) (aref *file* 1) (aref *file* 2) (aref *file* 3) (aref *file* 4)))
(setq f (open *creds* :direction :output :if-exists :append))
(princ save f)
(write-line " " f)
(close f)
(loop for o from 0 to 9
do (loop for p from 0 to 7
do (setq orp (aref *order* o p))
(if (not (equalp orp 0))
(setf (aref *order* o p) 0))
)
)
(loop for f from 0 to 4
do (setf (aref *file* f) 'fl))
(question)
)
(defun question()
(format t "~%~%Do you want to [A]dd another Order or [R]eturn to main Menu ?")
(setq ans (read))
(setq a 'a)
(setq r 'r)
(if (equalp ans a)
(start2)
(if (equalp ans r)
(start0)
(if (equalp ans " ")
(start0)
(progn
(format t "~%~%Please Enter a Valid Option...")
(question)))))
)
(defun views()
(format t " ")
(setq on 1)
(let ((in (open *creds* :if-does-not-exist nil)))
(when in
(loop for line = (read-line in nil)
while line
do (format t "~%Order Number: ~d~%" on)
(setq data (substitute #\Newline #\@ line))
(format t "~a~%" data)
(setq on (+ on 1))
)
(close in)
)
)
(question2)
)
(defun question2()
(format t "~%~%Do you want to [R]eturn to main Menu or [Q]uit ?")
(setq ans (read))
(setq q 'q)
(setq r 'r)
(if (equalp ans q)
(exitp)
(if (equalp ans r)
(start0)
(if (equalp ans " ")
(start0)
(progn
(format t "~%~%Please Enter a Valid Option...")
(question2)))))
)
(start0)
Python Code/.idea/dictionaries/hp.xml
creds
dataline
enterdetails
eturn
invoicep
ortype
pizzacount
pizzano
pizzaorders
psize
showorder
showpizza
sizesave
sizeselect
toppingselect
totalprice
Python Code/.idea/inspectionProfiles/Project_Default.xml
Python Code/.idea/misc.xml
Python Code/.idea/modules.xml
Python Code/.idea/Python Code.iml
Python Code/.idea/workspace.xml
;
()
1569249893782
1569249893782
Python Code/pizzaorders.txt
['Name: Yogesh\nPhone Number: 4569821751\nAddress: N.a..', '\n1.) Pizza size: Small, Price: $5, Number of Pizzas: 2,\n Toppings: Bacon, Bacon, Bacon, Bacon.\n2.) Pizza size: Medium, Price: $8, Number of Pizzas: 2,\n Toppings: Mushrooms, Mushrooms, Mushrooms, Mushrooms.', '\n1$ charged for Each Topping on each pizza.\nOrder Type: Collect.', ' ', '\nTotal Amount: $34.']
['Name: Nartana\nPhone Number: 7569821034\nAddress: Rama colony, near town gate, austria..', '\n1.) Pizza size: Large, Price: $12, Number of Pizzas: 1,\n Toppings: Mushrooms, Pineapple, Anchovies, No Topping.', '\n1$ charged for Each Topping on each pizza.\nOrder Type: Deliver.', '\n(Additional $8 Delivery Charge for Total Amount below $30.)', '\nTotal Amount: $24.']
['Name: Darshit\nPhone Number: 8756941203\nAddress: N.a..', '\n1.) Pizza size: Medium, Price: $8, Number of Pizzas: 2,\n Toppings: Mushrooms, Bacon, Olives, Pineapple.', '\n1$ charged for Each Topping on each pizza.\nOrder Type: Collect.', ' ', '\nTotal Amount: $20.']
Python Code/PizzaShop.py
import os
global creds, file, sizes, price, toppings, ortype, order
# file for storing data
creds = "pizzaorders.txt"
# temp list storing data before storing to text file
file = [0, 0, 0, 0, 0]
# list of pizza sizes
sizes = ["None", "Small", "Medium", "Large"]
# list of pizza prices according to size
price = [0, 5, 8, 12]
# list of pizza toppings
toppings = ["No Topping", "Bacon", "Olives", "Ham", "Mushrooms", "Pineapple", "Salami", "Anchovies"]
# list of order type
ortype = ["None", "Collect", "Deliver"]
# order list flags.
order = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
class PizzaShop:
def start0(self):
print("\n-------------------------------------------------------------------------")
print("--------------------- Welcome to Pizza Shop ---------------------")
print("-------------------------------------------------------------------------")
print("Main Menu - ")
print(" Option 1.) Add Order.")
print(" Option 2.) View Orders.")
print(" Option 3.) Exit.")
self.start1()
def start1(self):
ip0a = input("Please Enter an Option: ")
if ip0a == "1":
self.start3()
elif ip0a == "2":
self.views()
elif ip0a == "3":
self.exit()
else:
print("\nPlease Enter the Correct Option.")
self.start1()
def exit(self):
print("\nDo you really want to QUIT ?")
print("[Y]es / [N]o : ")
aq5 = input()
if aq5.upper() == "Y":
print("\n Thanks for using Pizza Shop Application...!\n")
input()
quit()
elif aq5.upper() == "N":
print(" ")
os.system("cls")
self.start0()
else:
print("Please Enter Correct Option...")
self.exit()
def start2(self):
print("\nAdd a new Order...")
self.start3()
def start3(self):
print("\nPlease Select an Option for Pizza Size from below: ")
print(" Option 1.) Small Pizza - $5 ")
print(" Option 2.) Medium Pizza - $8 ")
print(" Option 3.) Large Pizza - $12 ")
self.sizeselect()
def sizeselect(self):
global psize
try:
inp1a = int(input("Please Enter an Option for Pizza Size : "))
except:
print("\nPlease Enter a Valid Option for Pizza size.")
self.sizeselect()
if inp1a in range(0, 4):
psize = inp1a
self.sizesave()
else:
print("\nPlease Enter the Correct Option for Pizza size.")
self.sizeselect()
def sizesave(self):
global i
i = 0
for integers in order:
s =...