You are on page 1of 12

# BERNARD ONG YUZHE/EDWIN NEOH HAN CHERN

# TP065754/TP065980

BEGIN

IMPORT datetime

# APU Online Food Service Home Page


DEFINE FUNCTION home_page
DECLARE user_choice as INTEGER
PRINT("""
******************** Home Page ********************
1. Login
2. Register
3. Exit
""")
DOWHILE True:
TRY:
user_choice = PRINT("Please enter your choice to proceed:
"))
READ INTO user_choice
BREAK
EXCEPT ValueError:
PRINT("Something else went wrong, please choose the three
option had given above, thank you.")
CALL home_page() FUNCTION
ENDDO
IF user_choice == 1 THEN:
PRINT("Welcome member of APU, thanks for using AOFS")
PRINT(""".\n.\n.""")
PRINT("Proceeding to next page....................")
CALL user_login_page FUNCTION
ELSE IF user_choice == 2 THEN:
PRINT("Welcome to Asia Pacific University, thanks for using
AOFS,please register before you order")
PRINT(""".\n.\n.""")
PRINT("Proceeding to next page....................")
CALL user_register_page FUNCTION
ELSE IF user_choice == 3 THEN:
PRINT("Directing you to guest mode")
CALL guest_page() FUNCTION
ELSE IF user_choice == 4 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE:
PRINT("Something else went wrong, please choose the three option
had given above, thank you.")
CALL home_page() FUNCTION
ENDIF
ENDDEFINE

# APU Online Food Service User Register Page


DEFINE FUNCTION user_register_page
DECLARE user_register_page_option as INTEGER
PRINT("""
********** APU Food Online Service (Register Page) **********
1. Registration Form
2. Back to Home Page
3. Exit
""")
DOWHILE True:
TRY:
user_choice = PRINT("Please enter your choice to proceed:
"))
READ INTO user_choice
BREAK
EXCEPT ValueError:
PRINT("Something else went wrong, please choose the
three option had given above, thank you.")
ENDDO
IF user_register_page_option == 1 THEN:
PRINT("Proceeding to Registration Form...")
CALL user_registration_form FUNCTION
ELSE IF user_register_page_option == 2 THEN:
PRINT("Proceeding to the Home Page...")
CALL home_page FUNCTION
ELSE IF user_register_page_option == 3 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE
PRINT("Error selection.........")
PRINT("Please try again ^_^")
CALL user_register_page FUNCTION
ENDIF
ENDDEFINE

# APU Online Food Service User Register Form


DEFINE FUNCTION as user_registration_form()
DECLARE user_tp, user_name, user_address as STRING
DECLARE user_phone, user_registration_form_option as INTEGER
PRINT("Please fill in the registration form below")
DOWHILE TRUE:
user_tp = PRINT("Enter your TP number (TPxxxxxx): ")
READ INTO user_tp
IF user_tp == "" THEN:
PRINT("Input invalid")
ELSE:
BREAK
ENDIF
ENDDO
DOWHILE TRUE:
user_name = PRINT("Enter your name: ")
READ INTO user_name
IF user_name == "" THEN:
PRINT("Input invalid")
ELSE:
BREAK
ENDIF
ENDDO
DOWHILE TRUE:
DOWHILE TRUE:
TRY:
user_phone = PRINT("Enter your phone number: ")
READ INTO user_phone
BREAK
EXCEPT:
PRINT("Please enter number")
ENDDO
user_phone = "0" + (user_phone)
IF len(user_phone) == 10 OR len(user_phone) == 11 THEN:
BREAK
ELSE:
PRINT("Input invalid. Phone number must only be 10 or 11
digit")
ENDIF
ENDDO
DOWHILE TRUE:
user_address = PRINT("Enter your address: ")
READ INTO user_address
IF user_address == "" THEN:
PRINT("Input invalid")
ELSE:
BREAK
ENDIF
ENDDO
DOWHILE TRUE:
user_password = PRINT("Enter a password: ")
READ INTO user_password
IF len(user_password) < 8 OR len(user_password) > 15 THEN:
PRINT("Password is not valid \n It total characters should
be between 8 and 15")
CONTINUE
ELSE IF user_password == "" THEN:
PRINT("Password is not valid \n It should contain letter.")
CONTINUE
ELSE:
PRINT("Password is valid")
PRINT("""
Option:
1. Submit the registration form
2. Back to previous page
3. Exit
""")
DOWHILE TRUE:
TRY:
user_registration_form_option = PRINT("Please
select an option: ")
READ INTO user_registration_form_option
OPENFILE ("user_data.txt") for APPEND as
datafile1
BREAK
EXCEPT ValueError:
PRINT("Something else went wrong, please choose
the three option had given above, thank you.")
ENDDO
IF user_registration_form_option == 1 THEN:
WRITEFILE ("user_data.txt"), (datafile1)
user_tp + ";" + user_name + ";" + user_password
+ ";" + user_phone + ";" + user_address + "\n")
CLOSEFILE ("user_data.txt"), (datafile1)
PRINT("""
Registration Form Received !
Sending to staff.....
Redirecting back to Home Page
""")
CALL home_page() FUNCTION
ELSE IF user_registration_form_option == 2 THEN:
PRINT("Proceeding back to previous page......")
CALL user_register_page() FUNCTION
ELSE IF user_registration_form_option == 3 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE:
PRINT("Error option........")
PRINT("Please try again ^_^")
CALL user_registration_form() FUNCTION
ENDIF
ENDIF
ENDDEFINE

# APU Online Food Service Guest Page


DEFINE FUNCTION as guest_page
DECLARE guest_choice as INTEGER
PRINT("Welcome to APU Food Online Service")
CALL food_main_menu FUNCTION
PRINT("""Please register an account before ordering food
1. Register
2. Back to Home Page
3. Exit
""")
DOWHILE True:
TRY:
guest_choice = PRINT("Please enter your choice to proceed:
")
READ INTO guest_choice
BREAK
EXCEPT ValueError:
PRINT("Something else went wrong, please choose the three
option had given above, thank you.")
CALL home_page() FUNCTION
ENDDO
IF guest_choice == 1 THEN:
PRINT("Directing you to register page...")
CALL user_register_page FUNCTION
ELSE IF guest_choice == 2 THEN:
PRINT("Redirecting you back to Home Page...")
CALL home_page FUNCTION
ELSE IF guest_choice == 3 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE:
PRINT("Something else went wrong, please choose the three option
had given above, thank you.")
CALL home_page FUNCTION
ENDIF
ENDDEFINE

# APU Online Food Service Food Main Menu


DEFINE FUNCTION as food_main_menu
PRINT("Food Menu".center(44, "*"))
OPENFILE file = ("food_menu.txt") IN READ MODE
PRINT("Code".center(6) + "Name".center(30) + "Price(RM)".center(8))
food = READLINES IN file("food_menu.txt")
LOOP line IN RANGE food STEP 1
SPLIT food_code, food_name, food_price, food_cat USING ";" as A
DELIMITER
PRINT(food_code.center(6) + food_name.center(30) +
food_price.center(8))
NEXT line
ENDLOOP
CLOSEFILE file("food_menu.txt")
ENDDEFINE

# APU Online Food Service User Login Page


DEFINE FUNCTION as user_login_page
DECLARE user_login_page_option as INTEGER
DECLARE user_tp_num_cs, user_password_cs as STRING
DECLARE admin_id_num_as, admin_password_as as STRING
DECLARE user_staff_num_ds, user_password_ds as STRING
PRINT("""
** APU Food Online Service (Login Page) **
__ Select An Account Type __
1. Customer Account
2. Admin Staff Account
3. Delivery Staff Account
4. Back to Home Page
5. Exit
""")
DOWHILE TRUE:
TRY:
user_login_page_option = PRINT("Please enter an option: "))
READ INTO user_login_page_option
BREAK
EXCEPT ValueError:
PRINT("Something else went wrong, please choose the three
option had given above, thank you.")
ENDDO
IF user_login_page_option == 1 THEN:
user_tp_num_cs = PRINT("TP number: ")
READ INTO user_tp_num_cs
user_password_cs = PRINT("Password: ")
READ INTO user_password_cs
CALL user_login_cs(user_tp_num_cs, user_password_cs) FUNCTION
ELSE IF user_login_page_option == 2 THEN:
admin_id_num_as = PRINT("Staff number: ")
READ INTO admin_id_num_as
admin_password_as = PRINT("Password: ")
READ INTO admin_password_as
CALL admin_login_as(admin_id_num_as, admin_password_as)FUNCTION
ELSE IF user_login_page_option == 3 THEN:
user_staff_num_ds = PRINT("Staff number: ")
READ INTO user_staff_num_ds
user_password_ds = PRINT("Password: ")
READ INTO user_password_ds
CALL delivery_staff_login_ds(user_staff_num_ds, user_password_ds)
FUNCTION
ELSE IF user_login_page_option == 4 THEN:
PRINT("Proceeding back to Home Page...")
CALL home_page FUNCTION
ELSE IF user_login_page_option == 5 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE:
PRINT("Error selection..........")
PRINT("Please try again ^^")
CALL user_login_page FUNCTION
ENDIF
ENDDEFINE

# Customer User Login Verification Page


DEFINE FUNCTION as user_login_cs
access = False
OPENFILE ("user_data.txt") for READ MODE as datafile2
LOOP user_data IN RANGE datafile2 STEP 1
SPLIT user_data tp_cs, name_cs, password_cs, phone_cs, address_cs
USING ";" as A DELIMITER
STRIP tp_cs INTO tp_cs
STRIP password_cs INTO password_cs
IF tp_cs == user_tp_num_cs AND password_cs == user_password_cs
THEN:
STRIP name_cs INTO name_cs
access = TRUE
PRINT("Dear " + name_cs + ". Welcome to APU Food Online
Service")
PRINT("Dear customer, you have login successfully!")
BREAK
ENDIF
NEXT user_data
ENDLOOP
CLOSEFILE datafile2("user_data.txt")
IF access THEN:
PRINT("Dear " + name_cs + ". Welcome to APU Food Online Service")
PRINT("Dear customer, you have login successfully!")
CALL customer_account_page(tp_cs, address_cs) FUNCTION
ELSE:
PRINT("Error. Please try again.")
CALL user_login_page() FUNCTION
ENDIF
ENDDEFINE

***
# Admin Staff Login Verification Page
DEFINE FUNCTION as admin_login_as(admin_id_num_as, admin_password_as)
access = FALSE
OPENFILE ("admin_data.txt") for READ MODE as datafile3
LOOP admin_data IN RANGE datafile3 STEP 1
SPLIT admin_data id_as, name_as, password_as USING "," AS
DELIMITER
STRIP id_as INTO id_as
STRIP password_as INTO password_as
IF id_as == admin_id_num_as AND password_as == admin_password_as
THEN:
STRIP name_as INTO name_as
access = TRUE
PRINT("Dear " + name_as + ". Welcome back, you have login
successfully")
BREAK
ELSE:
PRINT("Error. Please try again.")
ENDIF
NEXT admin_data
ENDLOOP
CLOSEFILE datafile3("admin_data.txt")
IF access THEN:
CALL admin_staff_menu() FUNCTION
ELSE:
CALL user_login_page() FUNCTION
ENDIF
ENDDEFINE

# Delivery Staff Login Verification Page


DEFINE FUNCTION as delivery_staff_login_ds(user_staff_num_ds,
user_password_ds)
access = False
OPENFILE ("ds_account_data.txt") for READ MODE as datafile4
LOOP data IN datafile4:
SPLIT ds_account_data id_ds, name_ds, password_ds, phone_ds,
availability_ds USING ";" AS DELIMITER
STRIP id_ds INTO id_ds
STRIP password_ds INTO password_ds
IF id_ds == user_staff_num_ds AND password_ds == user_password_ds
THEN:
STRIP name_ds INTO name_ds
access = TRUE
PRINT("Dear " + name_ds + ". Welcome back, you have login
successfully")
BREAK
ELSE:
PRINT("Error. Please try again.")
ENDIF
NEXT ds_account_data
ENDLOOP
CLOSEFILE datafile4 ("admin_data.txt")
IF access THEN:
CALL delivery_staff_menu() FUNCTION
ELSE:
CALL user_login_page() FUNCTION
ENDIF
ENDDEFINE

# Customer User Interface


DEFINE FUNCTION as customer_account_page(tp_cs, address_cs)
DECLARE customer_account_page_option as INTEGER
PRINT("""
** APU Food Online Service **
---------- Customer Log In Page ----------
1. Food Menu
2. Shopping Cart
3. Payment
4. Back to Login Page
5. Exit
""")
DOWHILE TRUE:
TRY:
customer_account_page_option = PRINT("Please select an
option: ")
READ INTO customer_account_page_option
BREAK
EXCEPT ValueError:
PRINT("Something else went wrong, please choose the five
option had given above, thank you.")
ENDDO
IF customer_account_page_option == 1 THEN:
PRINT("Proceeding to Food Menu categories")
CALL food_menu(tp_cs, address_cs) FUNCTION
ELSE IF customer_account_page_option == 2 THEN:
PRINT("Proceeding to your order cart")
CALL shopping_cart(tp_cs, address_cs) FUNCTION
ELSE IF customer_account_page_option == 3 THEN:
PRINT("Proceeding to payment page")
CALL customer_payment(tp_cs, address_cs) FUNCTION
ELSE IF customer_account_page_option == 4 THEN:
PRINT("Proceeding back to Login Page")
CALL user_login_page() FUNCTION
ELSE IF customer_account_page_option == 5 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE:
PRINT("Error..........")
PRINT("Please try again ^^")
CALL customer_account_page(tp_cs, address_cs) FUNCTION
ENDIF
ENDDEFINE

# Food Menu Interface


DEFINE FUNCTION as food_menu(tp_cs, address_cs)
DECLARE user_choice, option as INTEGER
DECLARE food_list, next_id as STRING
PRINT("""********** Food Menu **********
1. Rice Menu
2. Noodles Menu
3. Salad Menu
4. Side Dish Menu
5. Beverages Menu
6. Back to previous page
7. Exit
""")
DOWHILE TRUE:
TRY:
user_choice = PRINT("Please enter your choice to proceed:
")
READ INTO user_choice
IF user_choice == 1 THEN:
PRINT("Rice Menu".center(44, "*"))
OPENFILE ("food_menu.txt") IN READ MODE as file
PRINT("Code".center(6) + "Name".center(30) +
"Price(RM)".center(8))
food_rice = READLINES IN file("food_menu.txt")
LOOP line IN RANGE food_rice STEP 1
SPLIT food_rice food_code, food_name,
food_price, food_cat = STRIP line USING ";" AS DELIMITER
IF food_cat == "r" THEN:
PRINT(food_code.center(6) +
food_name.center(30) + food_price.center(8))
ENDIF
NEXT line
ENDLOOP
CLOSEFILE file("food_menu.txt")
BREAK
ELSE IF user_choice == 2 THEN:
PRINT("Noodles Menu".center(44, "*"))
OPENFILE ("food_menu.txt") IN READ MODE as file
PRINT("Code".center(6) + "Name".center(30) +
"Price(RM)".center(8))
food_noodles = READLINES IN file("food_menu.txt")
LOOP line IN RANGE food_noodles STEP 1
SPLIT food_noodles food_code, food_name,
food_price, food_cat = STRIP line USING ";" AS DELIMITER
IF food_cat == "n" THEN:
PRINT(food_code.center(6) +
food_name.center(30) + food_price.center(8))
ENDIF
NEXT line
ENDLOOP
CLOSEFILE file("food_menu.txt")
BREAK
ELSE IF user_choice == 3 THEN:
PRINT("Salad Menu".center(44, "*"))
OPENFILE ("food_menu.txt") IN READ MODE as file
PRINT("Code".center(6) + "Name".center(30) +
"Price(RM)".center(8))
food_salad = READLINES IN file("food_menu.txt")
LOOP line IN RANGE food_salad STEP 1
SPLIT food_noodles food_code, food_name,
food_price, food_cat = STRIP line USING ";" AS DELIMITER
IF food_cat == "s" THEN:
PRINT(food_code.center(6) +
food_name.center(30) + food_price.center(8))
ENDIF
NEXT line
ENDLOOP
CLOSEFILE file("food_menu.txt")
BREAK
ELSE IF user_choice == 4 THEN:
PRINT("Side dish Menu".center(44, "*"))
OPENFILE ("food_menu.txt") IN READ MODE as file
PRINT("Code".center(6) + "Name".center(30) +
"Price(RM)".center(8))
food_sidedish = READLINES IN file("food_menu.txt")
LOOP line IN RANGE food_sidedish STEP 1
SPLIT food_noodles food_code, food_name,
food_price, food_cat = STRIP line USING ";" AS DELIMITER
IF food_cat == "d" THEN:
PRINT(food_code.center(6) +
food_name.center(30) + food_price.center(8))
ENDIF
NEXT line
ENDLOOP
CLOSEFILE file("food_menu.txt")
BREAK
ELSE IF user_choice == 5 THEN:
PRINT("Beverages Menu".center(44, "*"))
OPENFILE ("food_menu.txt") IN READ MODE as file
PRINT("Code".center(6) + "Name".center(30) +
"Price(RM)".center(8))
food_beverages = READLINES IN file("food_menu.txt")
LOOP line IN RANGE food_beverages STEP 1
food_code, food_name, food_price, food_cat =
line.strip().split(";")
IF food_cat == "m" THEN:
PRINT(food_code.center(6) +
food_name.center(30) + food_price.center(8))
ENDIF
NEXT line
ENDLOOP
CLOSEFILE file("food_menu.txt")
BREAK
ELSE IF user_choice == 6 THEN:
PRINT("Redirecting back to previous page...")
CALL customer_account_page(tp_cs, address_cs)
FUNCTION
ELSE IF user_choice == 7 THEN:
PRINT("Thank you for using APU Food Online Service")
PRINT("Have a Nice Day....... BYE BYE")
EXIT PROGRAM
ELSE:
PRINT("Something went wrong....")
PRINT("Redirecting back to Food Menu Page")
CALL food_menu(tp_cs, address_cs) FUNCTION
ENDIF
EXCEPT ValueError:
PRINT("Something else went wrong, please choose the five
options had given above, thank you.")
CALL food_menu(tp_cs, address_cs) FUNCTION
ENDDO
option = PRINT("Do you wish to purchase any of the food? (y/n): ")
READ INTO option
DOWHILE TRUE:
IF option.lower() == "y" THEN:
DOWHILE TRUE:
flag = 1
food_list = list(map, SPLIT PRINT("Please enter food
code to add in order cart: ")))
READ INTO food_list
LOOP food_code IN RANGE food_list STEP 1
WITH OPENFILE ("food_menu.txt") IN READ MODE AS
fm:
LOOP line IN RANGE fm STEP 2
SPLIT (line) field USING ";" AS
DELIMITER
IF food_code == field[0] THEN:
flag = 0
BREAK
ENDIF
NEXT line
ENDLOOP
ENDWITH
NEXT food_code
ENDLOOP
IF flag == 1 THEN:
PRINT("Food code input is invalid")
ELSE:
BREAK
ENDIF
PRINT("Food Code added into order cart: ", food_list)
cnt = 0
DOWHILE TRUE:
size = len(food_list)
WITH OPENFILE("food_menu.txt") IN READ MODE as fm:
LOOP line IN RANGE fm STEP 1
SPLIT (line) field USING ";" AS DELIMITER
IF food_list[cnt] == field[0] THEN:
food_name = field[1]
food_price = field[2]
ENDIF
NEXT line
ENDLOOP
ENDWITH
flag1 = 0
WITH OPENFILE("shopping_cart.txt") IN READ MODE as
fh:
LOOP line IN RANGE fh STEP 1
SPLIT (line) field USING ";" AS DELIMITER
flag1 = 1
NEXT line
ENDLOOP
IF flag1 == 0 THEN:
next_id = "SC001"
ELSE:
ID = field[0]
next_id = int(ID[2:]) + 1
ENDIF
IF len(str(next_id)) == 1 THEN:
next_id = "SC" + "00" +
str(next_id)
ENDIF
IF len(str(next_id)) == 2 THEN:
next_id = "SC" + "0" + str(next_id)
ENDIF
IF len(str(next_id)) == 3 THEN:
next_id = "SC" + str(next_id)
ENDIF
ENDWITH
WITH OPENFILE("shopping_cart.txt") IN APPEND as fh:
WRITEFILE (next_id + ";" + food_list[cnt] + ";"
+ food_name + ";" + food_price + ";" + tp_cs + ";" + "n" + "\n") as fh
IF cnt == size - 1 THEN:
BREAK
ENDIF
cnt += 1
ENDWITH
ENDDO
CALL food_menu(tp_cs, address_cs) FUNCTION
ELSE IF option.lower() == "n" THEN:
PRINT("Back to Food Menu categories.")
CALL food_menu(tp_cs, address_cs) FUNCTION
ELSE:
PRINT("Error...")
PRINT("Please try again")
CALL food_menu(tp_cs, address_cs) FUNCTION
ENDIF
ENDDO
ENDDEFINE

You might also like