Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit






Assignment #9

 

  Hide Assignment Information

Instructions

 

Tim Horton's Order Simulator

Please note that the marks from this assignment cannot be dropped from your final mark.

You have been commissioned to write an order simulation program for your local Tim Horton's.

Orders are taken at Tim Horton's by the "cashiers" and are placed in a queue to be filled one at a time by the "chefs".   Chefs fill the orders in the order in which they are submitted by the cashiers.  You will write an application which simulate orders being added,     completed, updated etc.

You will store the order information using a "queue".  A "queue" in computer science is an ordered sequence of information to which            items are added at one end of the sequence and removed from the other end.  When a cashier takes an order, the order is assigned an ID  and added to the end of the queue.  Chefs complete the orders in the order that they were placed, so the next order to complete would     be at the head (front) of the queue.  This is what is called a "first in, first out queue (FIFO)" -- jobs are processed in the order that they are submitted.    When a chef finishes preparing the order, it is removed from the queue.

To implement the queue, you will use a list where each order is an element in the list.  New orders would be appended to the list.   Each     order will have a unique ID -- an integer value.   In addition, the order will have one or more food items  which should be stored in a list of strings, and lastly, the order will have the total amount paid (float).

So, an order might look like this:  [101, ["Wrap", "Coffee"], 8.25].     For the queue, you may have a list of orders such as [[101, ["Wrap",     "Coffee"], 8.25], [102, ["Soup", "Donut"], 7.59] ..... ].   A new order would be added to the end of the list (after order #102) and the order that is currently being processed is 101, the item at the start of the list.

When your program starts, it will read the initial order items from the following web site:

https:/www.cs.queensu.ca/home/cords2/timHortons.txt.

You may assume that each food item is only one word, but there may be any number of food items (but at least one) in each row of the   data file.  Your program should be able to read any file of data (structured in the same way), not just this file (that is, you should not be     programming something that assumes that there are two food items in the first line and two in the second line etc -- your program must be general).

The order queue must NOT be a global variable.

While you are reading in the data, you should update a global variable which will store the last used order ID.  When the file is read, the last used order ID will be 108.

Your program should provide the user with a menu to allow them to do the following tasks.  (Please note that "menu" in this assignment    means a menu of options for the user to choose -- not the Tim Horton's menu!!).     Each task must be coded in an appropriate function       with appropriate parameters and return values.   All user prompting should be done within the menu function and the information passed to an appropriate function which will carry out the task.   All outputs to the screen should also be done within the menu.  So, your menu   implementation should look something like this:

if  the  user  selects  "find  orders  with  a  particular  food  item " :

1) Submit a new order.  Your program will need to prompt the user for the food items and the total amount of the order.  Please note that  they may enter any food items -- you do not need to restrict them to the Tim Horton's actual menu, nor do you need to list potential food items.  The order ID will be generated using the last used order ID.  So, the first order to be submitted after reading the initial order file      will have an ID of 109.  Add the new order to the queue in the appropriate place (at the end).  Be sure to convert all items to the                    appropriate types before adding to the queue.  You may assume that the user enters values that can be converted without error.

2) Find all orders with a particular food item. The user will be prompted for the food item to search for.  You may assume that they enter a string, but the food item they enter may not be present in the current orders.   Return a list of all order IDs which include the selected food item.  An empty list should be returned if the food item is not in any of the current orders.   You will display something like:  "The following orders contain Coffee: 101, 107 121".  You must not print the list as [101, 107, 121].

3) Find the ids of the least and the most expensive totals and print the IDS on the screen.  (Remember, there may be two totals that are  the same).  Your function to locate the least and most expensive items should not do the printing -- it should return the order IDS of the most and least expensive orders.

4) Cancel an order given a particular id.  The user should be asked for an ID and that order should be removed from the queue.  Existing   order IDS should not be changed.  Show the queue before and after canceling the item.   You may assume that the user enters an integer for the ID.  If the ID is not in the queue, do nothing.

5) Display all the unique food items that are currently in the queue.  List each item only once.

6) Complete the next order.  (Remember the "next" order will be the one at the start of the list).  Show the queue before and after completion of the next order.  If the queue is empty, do nothing.

Hints for Program Development

Follow the decomposition process that we talked about in class.  Do a program design where you define all the functions that you will   need for this program and what the parameters to each function will be and what each function will return (if anything).  Each function should do a single task.   Consider breaking your function into multiple functions if you are doing more than one task.  Work on one       function at a time.  Test each function before moving on to the next.

Your main function (where you implement the menu) may be very long.  If so, try breaking it into individual functions.  For instance, if the user chooses option 3, call a function which will implement the functionality for option 3.

There should be ONLY ONE GLOBAL VARIABLE in your program.   Data should be stored using appropriate data types (ie. the order amount should not be stored as a string and order IDs should be stored as integers).

Note that if you cannot get the entire program working, try to get at least some functions implemented.  There are part marks!  The        decomposition process will allow you to work on functions independently -- even if you can't read the data from the website.  (If you     can't read the data, you can simply define a data structure to hold the data within your main() function that would have been read in by the program).

All functions should have a docstring and your program should have a program header.  Inline comments should be used where appropriate.

Reading from the Web Site:

The input data that you will use resides on a web page.  You will read a line of the web page (a command) and process the command, then read another line etc.     Here is some code to help get you started in reading the file:

import  urllib .request         #this  loads  a  library  you  will  need .    Put  this  line  at  the  top  of  your  file .

response  =  urllib .request .urlopen ("https://www .cs .queensu .ca/home/cords2/timHortons .txt" )

Note:  If you are working on a mac, you may experience a a certificate error.  If so, add the following to the top of your code:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

What to Submit

Upload your file  to the assignment dropbox.  Please check your file after uploading.   If you upload the wrong file, you get a mark of 0 -- it is YOUR responsibility to check to ensure that you have submitted the correct files.