COMP 2150

Assignment 2

编程homework代写 Remember to follow the “Programming Standards” for all work you submit, in addition to the guidelines provided here. Marks can be…

Notes

  • Remember to follow the “Programming Standards” for all work you submit, in addition to the guidelines provided here. Marks can be deducted for not following the programming standards and the guidelines described in this document.
  • Any question about the assignment must be posted on the discussion forum on UMLearn, in the “Assignment 2” thread. You are also responsible for reading the answers and clarifications posted in the discussion forum. Please try to avoid duplicate posts by keeping track of what has been posted and answered already (the search tool in the forum can also be useful).
  • As usual, hand-in will be via the submission folder on UMLearn. Make sure you leave enough time before the deadline to ensure your hand-in works properly. The assignments are submitted using UMLearn’s time (not the time on your computer). Assignments that are late will be marked according to the late policy in the ROASS.
  • Official test data will be provided a few days before the assignment due date. Until then, work with the provided example at the end of the document and your own test data.

  • Before you start, you must watch the “Event-Driven Simulation” video posted in the Assignment 2 folder. Then, please take the time to read the entire document before you start planning / coding. Some ideas will make more sense once you have read the entire guidelines.
  • The guidelines will explicitly ask you to implement some classes / hierarchies. But be aware that some other necessary classes are only implicitly referred to in these guidelines. It is a good idea to compartmentalize your code into many different objects. You might create up to 15 (or more) different short classes to complete this assignment, and that is ok. Don’t forget to use class hierarchies and polymorphism as much as possible, and minimize code duplication.
  • Please test your code often as you build it; not just at the very end. For example, you should test your data structures before you start using them inside other classes. Assignment 2: Event-Driven Simulation (Restaurant chef) in C++

General description 编程homework代写

To begin working in C++, you will write a program that will use a discrete-event simulation to simulate a restaurant chef handling food orders. Customers have a limited amount of patience: food orders will expire after a certain time limit and the chef will lose the opportunity to fulfill them. You will implement three different simulations to handle these food orders:

(1) First-come first-served Simulation: the chef will always work on preparing the first order that came in, as long as it has not expired;

(2) Last-come first-served Simulation: the chef will aim to prepare the last order that came in (the most recent one), as long as it has not expired;

(3) Maximize revenue Simulation: the chef will always look at all unexpired orders and prepare the one that costs the most first.

Your program must use two command-line arguments: the first argument will be a filename (the file will contain a list of food orders – described below) and the second argument will be an int (either 1, 2 or 3) which will determine which version of the simulation to run (run like this for e.g.: a2.exe test.txt 1). 编程homework代写

You should be making use of all the facilities for doing OO in C++ that we have covered, including appropriate use of abstract classes and methods, and safe dynamic casting. For example, the three different versions of the restaurant simulation should be subclasses of an abstract class that contains all the code that is shared between the subclasses. Correctly freeing the allocated memory is recommended but not required (not evaluated) for this C++ assignment.

Each class you define must separate the interface from the implementation. As seen in class, place the interface of your classes in .h files and the implementation in .cpp files. You may also use the make utility if you are familiar with it, but there’s nothing forcing you to do that here. Simply provide clear compilation instructions to the markers in a README.txt file.

Details

An input file is used to drive the simulation and will contain only arrival events (arrival of a food order). The input file will be ordered by time, so you must have only one event read from the file in the event queue at any time (you must not read the full file all at once). The processing of one arrival event must cause the next event to be read from the file. Each food order will get a unique ID number (starting at 1), and each new food order will have an ID of one higher than the one before.

There are three events that can happen in this system: 编程homework代写

An Arrival event occurs when a food order is received by the kitchen. This event will be handled differently depending on the type of simulation (1, 2 or 3):

(1) First-come first-served Simulation: The food order should be placed in a queue that keeps track of the proper ordering for this simulation.

(2) Last-come first-served Simulation: The food order should be placed in a stack that keeps track of the proper ordering for this simulation.

(3) Maximize revenue Simulation: The food order should be placed in a priority queue that keeps track of the proper ordering for this simulation (higher prices have more priority; in case of a tie, order following a first-come first-served approach).

In all three types of simulations, if the chef is not currently preparing an order when you process an Arrival event, you should schedule a Prepare event (see below). Also, every time you process an Arrival  event, you also must read the next event from the input file. If there is another one, and add it to the event queue (see below for more details on the event queue).

A Prepare event means that the chef is starting to prepare an order. The length of time it takes to prepare the order depends on the meal that is ordered and its ingredients. These preparation times are fixed (see the table in the “Data file” section below), so it is possible to calculate how long a food order will take to prepare. You must schedule a CompleteService event for that time (i.e., for the time the Prepare event began + the time to prepare the food).

A CompleteService event occurs when the food order has been prepared and served. At this time, you should display the revenue that was gained from completing it (which is also fixed, see the table below). 编程homework代写

The chef is now ready to prepare the next food order: you must see if another unexpired food order is available. And schedule a Prepare event for the next food order if there is one. Note that the chef will always be working on an order if one is available (no breaks!).

You will need to maintain a list of future events in order of time (event queue). During the simulation process, at any point where the time unit is the same for two events, the food order that arrived earlier should be handled first. This means that as the simulation goes on you will be maintaining a list of pending events that is ordered by primarily by time, but within time, ordered by food order ID.

As mentioned earlier, use a command-line argument to accept the name of the data file. And another argument to determine which version of the simulation to run (either 1, 2 or 3). Your program should then open that file and perform the simulation. This method will allow the markers to easily run your program on several different data files whose names you do not know ahead of time. Your program should write to standard (console) output, not to an output file (again this makes things easy on the markers because they can just read output in a terminal window).

Data file: 编程homework代写

The data file contains information on Arrival events (of food orders) only. Each event is on one line of the file and each token on a line is separated by a single space. You can safely assume that each line has the following structure:

[time] [expiry] [meal] [list of ingredients separated by a space]

Each line begins with two positive integers, which represent the time of the arrival event followed by the time that it will expire (an order can be prepared by the chef as long as the current time in the simulation is <= expiry time). Next is the name of the meal, followed by (at least) one or more additional entries, representing the names of the ingredients to be included in the meal.

To help you, an example of a program that gets the necessary command-line arguments, opens the file and extracts the necessary information from one line is given to you (FileReadingExample.cpp). Of course, in your assignment, you should not have the file-reading code directly in the main function, so you can place this parsing code in the right class(es). Your main function should only process the command-line arguments, create an instance of the corresponding simulation and start the simulation.

The following table lists the possible meals that can be part of a food order, the base amount of time required to prepare the meal. And the base price of the meal. For simplicity, each ingredient (no matter what it is) that is added to the meal will contribute to adding 1 unit of time to the preparation and $1 to the base price.

编程homework代写
编程homework代写

For example, the following food order:

1 25 Pizza Pepperoni Peppers Sausage

would take 9 units of time to prepare (6 + 3 ingredients) and would cost $15.99 ($12.99 + $3).

Data Structures

Your data structures must be your own, and you cannot use the C++ standard template library: you must make generic data structures (for example, a Queue, a Stack and a PriorityQueue would be useful) using your own linked structures and making use of C++’s object-orientation features. Remember that you might need to store several different types of data in these data structures. In particular, you should have a polymorphic hierarchy of data items to go into generic data structures, and a polymorphic hierarchy of Events. IF YOU USE C++ ARRAYS, TEMPLATES OR STL DATA STRUCTURES, YOU WILL LOSE MARKS.

Input and output: 编程homework代写

Here is a simple example of an input data file:

1 10 Pizza Pepperoni Peppers Sausage

5 20 Stew Onions Cabbage Carrots Beef

10 30 Burger Beef Tomatoes Onions Cheese

11 40 Pizza Peppers Onions Pineapple BananaPeppers Garlic Feta

12 32 Stew Chicken Corn Carrots Celery Tomatoes Beans Potatoes

15 47 Salad Lettuce Tomatoes Cucumbers Dressing

You should use this simple example to test your program, along with your own additional tests, before the official test data is uploaded on UMLearn.

Your program should produce output that indicates the sequence of events processed and when they occurred (ordered by time). At the end of the simulation you will produce a simple summary of the total number of orders completed and the total revenue. The output of the above example is shown below, for the three types of simulations.

Output of First-come first-served Simulation: 编程homework代写

Simulation begins...

TIME: 1, FoodOrder 1 arrives -> Expiry:10 - Meal:Pizza - Ingredients:3 - Prep.time:9 - Price:$15.99

TIME: 1, FoodOrder 1 is getting prepared by the chef!

TIME: 5, FoodOrder 2 arrives -> Expiry:20 - Meal:Stew - Ingredients:4 - Prep.time:11 - Price:$18.99

TIME: 10, FoodOrder 1 has been served! Revenue grew by: $15.99

TIME: 10, FoodOrder 2 is getting prepared by the chef!

TIME: 10, FoodOrder 3 arrives -> Expiry:30 - Meal:Burger - Ingredients:4 - Prep.time:8 - Price:$12.99

TIME: 11, FoodOrder 4 arrives -> Expiry:40 - Meal:Pizza - Ingredients:6 - Prep.time:12 - Price:$18.99

TIME: 12, FoodOrder 5 arrives -> Expiry:32 - Meal:Stew - Ingredients:7 - Prep.time:14 - Price:$21.99

TIME: 15, FoodOrder 6 arrives -> Expiry:47 - Meal:Salad - Ingredients:4 - Prep.time:7 - Price:$10.99

TIME: 21, FoodOrder 2 has been served! Revenue grew by: $18.99

TIME: 21, FoodOrder 3 is getting prepared by the chef!

TIME: 29, FoodOrder 3 has been served! Revenue grew by: $12.99

TIME: 29, FoodOrder 4 is getting prepared by the chef!

TIME: 41, FoodOrder 4 has been served! Revenue grew by: $18.99

TIME: 41, FoodOrder 6 is getting prepared by the chef!

TIME: 48, FoodOrder 6 has been served! Revenue grew by: $10.99

... simulation ended.

- Total number of orders completed: 5

- Total revenue: $77.95

Output of Last-come first-served Simulation: 编程homework代写

Simulation begins...

TIME: 1, FoodOrder 1 arrives -> Expiry:10 - Meal:Pizza - Ingredients:3 - Prep.time:9 - Price:$15.99

TIME: 1, FoodOrder 1 is getting prepared by the chef!

TIME: 5, FoodOrder 2 arrives -> Expiry:20 - Meal:Stew - Ingredients:4 - Prep.time:11 - Price:$18.99

TIME: 10, FoodOrder 1 has been served! Revenue grew by: $15.99

TIME: 10, FoodOrder 2 is getting prepared by the chef!

TIME: 10, FoodOrder 3 arrives -> Expiry:30 - Meal:Burger - Ingredients:4 - Prep.time:8 - Price:$12.99

TIME: 11, FoodOrder 4 arrives -> Expiry:40 - Meal:Pizza - Ingredients:6 - Prep.time:12 - Price:$18.99

TIME: 12, FoodOrder 5 arrives -> Expiry:32 - Meal:Stew - Ingredients:7 - Prep.time:14 - Price:$21.99

TIME: 15, FoodOrder 6 arrives -> Expiry:47 - Meal:Salad - Ingredients:4 - Prep.time:7 - Price:$10.99

TIME: 21, FoodOrder 2 has been served! Revenue grew by: $18.99

TIME: 21, FoodOrder 6 is getting prepared by the chef!

TIME: 28, FoodOrder 6 has been served! Revenue grew by: $10.99

TIME: 28, FoodOrder 5 is getting prepared by the chef!

TIME: 42, FoodOrder 5 has been served! Revenue grew by: $21.99

... simulation ended.

- Total number of orders completed: 4

- Total revenue: $67.96

Output of Maximize revenue Simulation: 编程homework代写

Simulation begins...

TIME: 1, FoodOrder 1 arrives -> Expiry:10 - Meal:Pizza - Ingredients:3 - Prep.time:9 - Price:$15.99

TIME: 1, FoodOrder 1 is getting prepared by the chef!

TIME: 5, FoodOrder 2 arrives -> Expiry:20 - Meal:Stew - Ingredients:4 - Prep.time:11 - Price:$18.99

TIME: 10, FoodOrder 1 has been served! Revenue grew by: $15.99

TIME: 10, FoodOrder 2 is getting prepared by the chef!

TIME: 10, FoodOrder 3 arrives -> Expiry:30 - Meal:Burger - Ingredients:4 - Prep.time:8 - Price:$12.99

TIME: 11, FoodOrder 4 arrives -> Expiry:40 - Meal:Pizza - Ingredients:6 - Prep.time:12 - Price:$18.99

TIME: 12, FoodOrder 5 arrives -> Expiry:32 - Meal:Stew - Ingredients:7 - Prep.time:14 - Price:$21.99

TIME: 15, FoodOrder 6 arrives -> Expiry:47 - Meal:Salad - Ingredients:4 - Prep.time:7 - Price:$10.99

TIME: 21, FoodOrder 2 has been served! Revenue grew by: $18.99

TIME: 21, FoodOrder 5 is getting prepared by the chef!

TIME: 35, FoodOrder 5 has been served! Revenue grew by: $21.99

TIME: 35, FoodOrder 4 is getting prepared by the chef!

TIME: 47, FoodOrder 4 has been served! Revenue grew by: $18.99

TIME: 47, FoodOrder 6 is getting prepared by the chef!

TIME: 54, FoodOrder 6 has been served! Revenue grew by: $10.99

... simulation ended.

- Total number of orders completed: 5

- Total revenue: $86.95

Hand-in

Submit all your source code for all classes (executable files cannot be graded and will not receive any marks). You should also submit four text documents:

  • The output of the official test data for the First-come first-served Simulation.
  • The output of the official test data for the Last-come first-served Simulation.
  • The output of the official test data for the Maximize revenue Simulation.
  • Include a README.txt file that describes exactly how to compile and run your code from the command line. The markers will be using these instructions exactly to compile your code on the aviary server. If your code does not compile directly, you will lose marks.

You MUST submit all of your files in a zip file on UMLearn in the Assignment 2 folder.

Remember: the easier it is to mark your assignment, the more marks you are likely to get. Do yourself a favour.