question archive Assignment 2 - CS Pizzeria CS Pizzeria Current version: 1
Subject:Computer SciencePrice:28.99 Bought6
Current version: 1.0.0
Sasha, Tom and Shrey want to start a pizzeria together but they have no way to manage it. How will they keep track of their orders? How will they keep track of their finances? How will they ever convince Sasha that pineapple on pizza is a blessing on human kind? COMP1511 is requesting you to build a program which will help them manage their pizzeria.
Note: At time of release (Week 8), COMP1511 has not yet covered all of the techniques and topics necessary to complete the later stages of the assignment. At the end of Week 7, the course has covered enough content so you will be able to create and use a single linked list, and navigate a multi-file project. However, you have not yet seen deleting from a single linked list and two dimensional linked lists. We will be covering these topics in the lectures, tutorials and labs in Weeks 8 and 9. There will also be a livestream in Week 8 detailing the assignment and its structs. The link to this is in the Week 8 announcement.
The Assignment Livestream is scheduled for Thursday, Week 8 18:00-19:30. After that time, it will be available here.
For this assignment, you will be implementing a program which helps to manage a pizzeria. You do not need any prior knowledge regarding managing a restaurant or cooking pizzas to complete this assignment.
In Stage 1, you are required to manage a linked list of orders in the pizzeria. The following diagram provides a visual representation of what you are implementing
In Stage 2, these orders will now have a linked list of required ingredients. You do not need to understand the following diagram until you complete Stage 1.
In Stage 3, the pizzeria will now have a linked list of stocked ingredients. You do not need to understand the following diagram until you complete Stage 2.
In Stage 4, the pizzeria will be structured the same but orders can now be completed and ingredients can be saved/loaded to/from files.
This section details what is currently in the starter code. The images above are what your assignment's struct pizzeria
at the end of each stage.
You have been provided with the skeleton of three existing struct
data types to help you with your implementation of this simulation.
The structs and their purposes are shown below.
struct pizzeria
struct order *orders
- points to the head of the orders list or NULL
.struct order
struct order *next
- points to the next order in the linked list or NULL
.struct ingredient
struct ingredient *next
- points to the next ingredient in the linked list or NULL
.Remember that these are skeletons, so add to the contents of each struct to suit your implementation of the assignment.
In this assignment, you cannot use arrays, other than char
arrays, and cannot use the features explicitly banned in the Style Guide.
We strongly encourage you to complete the assessment using only features taught in lectures up to and including Week 8 and 9. The only C features you will need to get full marks in the assignment are:
int
, char
and double
variables.char
arrays/strings (you are not allowed to use arrays which are not char
arrays).stdio.h
, stdlib.h
and string.h
.#define
's), and whitespace and indentation.Using any other features will not increase your marks (and will make it more likely you make style mistakes that cost you marks).
If you choose to disregard this advice, you must still follow the Style Guide. You also may be unable to get help from course staff if you use features not taught in COMP1511.
Features that the Style Guide strongly discourages or bans will be penalised during marking.
To help you understand the proper behaviour of CS Pizzeria, we have provided a reference implementation. If you have any questions about the behaviour of CS Pizzeria, you can check them against this reference implementation.
To access the reference implementation, use the following command.
1511 cs_pizzeria
Stubs are functions which compile, but are incomplete. In your starter code pizzeria.c
, most functions only have one line in them, which is their return. This return is just so the code will compile, and you will need to update these as you work on your code.
This zip file contains the files that you need to get started with the assignment. It contains the following files:
pizzeria.h
.create_pizzeria
has been completed for the current definition of struct pizzeria
.
struct pizzeria
, you will need to update the function to match.print_order
and print_ingredient
, which you should use to print the orders and ingredients. These functions will print the orders and ingredients in the expected format.pizzeria.c
.mkdir ass2 cd ass2
Download the starter code above or use the commands below to copy the file into your current directory on your CSE account.
cp -n /web/cs1511/21T3/activities/cs_pizzeria/pizzeria.c . ln -s /web/cs1511/21T3/activities/cs_pizzeria/main.c . ln -s /web/cs1511/21T3/activities/cs_pizzeria/pizzeria.h .
The ln commands create symbolic links to a file in class account, so you are always using the latest version.
Run 1511 autotest
for the first stage to make sure you have correctly downloaded the files.
1511 autotest-stage 01 cs_pizzeria
If the tests do not run, you have not downloaded the correct files. If it says you have passed 1 test and failed 13 tests, you have downloaded the correct files.
1511 cs_pizzeria
pizzeria.h
.pizzeria.c
, using pizzeria.h
to check the details of any specific assumptions or edge cases. As you code, it is recommended to have pizzeria.h
open and easily accessible. Also, if there is anything you're unsure of, run the reference implementation!To compile a multi-file project, you will want to compile the .c
files together. For this assignment, you will want to use the following command.
dcc -o cs_pizzeria pizzeria.c main.c
This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.
You can run the autotests for Stage 1 by running the following command:
1511 autotest-stage 01 cs_pizzeria
Why does this stage exist?
This stage tests you on creating, inserting and iterating through a linked list. This is one of the key learning outcomes of COMP1511, and it will be tested in your Week 8 and 9 Lab Exercises, and during the final exam. We teach this skill because it is one of the fundamental ways that data can be stored and manipulated, and forms a basis for most algorithms.
Who do we expect to complete this stage?
While some students may struggle with it, we hope every student will complete this stage.
What help will tutors provide to students?
Tutors can give you a detailed theoretical explanation, and give lots of help with the lab exercises that lead to this assignment. Tutors will be happy to help you debug any issues with your code.
How many marks will I get?
Completing this stage, with good style, is worth around a 30% mark.
In this stage, you will implement:
add_order()
print_all_orders()
next_deadline()
Your first task is to implement the function: add_order()
. The details of the function can be found in pizzeria.h
.
An order is a customer's request to the pizzeria and needs to be stored. This will include:
A new order should be added to the end of the pizzeria's linked list of orders, emulating the first come, first serve way of thinking.
You should fill in the members of struct order
to ones that make the most sense to you.
Some fields you may want to add to struct order
include a character array for the customer name and a double for the price. The character array should be of length MAX_STR_LENGTH
as found in pizzeria.h
.
For example, if you wanted to add a customer name string to your struct, you could define it like this:
char customer[MAX_STR_LENGTH];
For this assignment, the exact specifics of how the function should operate will be in pizzeria.h
. Since this is the first function required to be implemented, the description in pizzeria.h
is displayed in the following toggle list. However, for future functions, we expect you to refer to pizzeria.h
.
1.1.1 Description of add_order in the .h file
//////////////////////////////////////////////////////////////////////// // INSERT ORDER INTO PIZZERIA - Command 'o' // // Add a new Order to the Pizzeria and return an int indicating the // resulting status of the new Order. // // The new Order should be added to the end of the Pizzeria's list of // Orders. This means that you should add the Order directly after the // most recent Order added. // // `add_order` will be given the parameters: // - `pizzeria` -- a pointer to a struct pizzeria created by // `create_pizzeria`. // - `customer` -- a string, which contains the name of the customer // for the order. // - `pizza_name` -- a string, which contains the name of the pizza for // the order. // - `price` -- a double, which indicates the cost of the order the // customer must pay. An invalid `price` may be passed in and an // invalid `price` is a double less than 0. // - `time_allowed` -- an int, which indicates the time when the // customer expects the order. If `time_allowed` is 15, this means // the customer expects the order in 15 minutes. An invalid // `time_allowed` may be passed in and an invalid `time_allowed` // is an int less than or equal to 0. // // `add_order` will return (in order of precedence): // - `INVALID_PRICE` -- if the price is invalid (negative). // - `INVALID_TIME` -- if the time_allowed is invalid (non-positive). // - `SUCCESS` -- if the Order has been successfully added to the Pizzeria. // // ASSUMPTIONS // - `pizzeria` will always be a valid pointer and never be NULL. // - `customer` will always be a valid string. // - `pizza_name` will always be a valid string. //
The following toggle lists contain diagrams which will help supplement your understanding of how the function affects the pizzeria.
1.1.2 Diagram of inserting first order into an empty list
Before adding an order
After adding an order with command o Joe Meat-Lovers 10.99 20
1.1.3 Diagram of inserting orders into a non-empty list
Potential fields in struct order
will be shown from now on but their type has been omitted as this is up to you to decide (if you take this path)!
Before accepting a new order
After accepting a new order when there are other orders already waiting. This uses the command o Betty Peri-Peri 14.00 15
.
Your second task is to implement the function: print_all_orders()
. The details of the function can be found in pizzeria.h
.
The owner of the pizzeria would like to have an overview of all the current orders in their restaurant. In this function, you will be printing all the orders in the desired format.
For this function, you should use the provided helper function print_order()
to print the orders in the expected format.
In print_all_orders()
, there is a function call to a function named print_selected_order()
. This function call should be at the very end of the function and should not be removed. print_selected_order()
is a function to be implemented in Stage 2.
1.2.1 Example printing two orders
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Tony Pepperoni 15 20 Added order successfully! 001: p 01: Tony ordered a Pepperoni pizza ($15.00) due in 20 minutes. No selected order. 002: o Rebecca Ham-n-Cheese 10.99 30 Added order successfully! 003: p 01: Tony ordered a Pepperoni pizza ($15.00) due in 20 minutes. 02: Rebecca ordered a Ham-n-Cheese pizza ($10.99) due in 30 minutes. No selected order. 004: q
1.2.2 Example printing six orders
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Harry Margarita 15 20 Added order successfully! 001: o Dumbledore Beef-n-Onion 10 30 Added order successfully! 002: o Molly Pepperoni 12.5 30 Added order successfully! 003: o Remus Nutella 18.99 50 Added order successfully! 004: o Percy Anchovies 19.99 10 Added order successfully! 005: o Hermione Grilled-Vegetable 14.49 60 Added order successfully! 006: p 01: Harry ordered a Margarita pizza ($15.00) due in 20 minutes. 02: Dumbledore ordered a Beef-n-Onion pizza ($10.00) due in 30 minutes. 03: Molly ordered a Pepperoni pizza ($12.50) due in 30 minutes. 04: Remus ordered a Nutella pizza ($18.99) due in 50 minutes. 05: Percy ordered a Anchovies pizza ($19.99) due in 10 minutes. 06: Hermione ordered a Grilled-Vegetable pizza ($14.49) due in 60 minutes. No selected order. 007: q
Your third task is to implement the function: next_deadline()
. The details of the function can be found in pizzeria.h
.
The chefs in the pizzeria would like to know how much time is left until their next deadline. You will need to tell the chefs what is the shortest time allowed among all orders in the pizzeria.
The following toggle list contains a diagram which will help supplement your understanding of how the function interprets the pizzeria.
1.3.1 Diagram to show the pizzeria
1.3.2 Example output of next_deadline()
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Harry Margarita 15 20 Added order successfully! 001: o Hermione Grilled-Vegetable 14.49 60 Added order successfully! 002: o Molly Pepperoni 12.5 30 Added order successfully! 003: o Percy Anchovies 19.99 50 Added order successfully! 004: o Dumbledore Beef-n-Onion 10 30 Added order successfully! 005: o Remus Nutella 18.99 50 Added order successfully! 006: ! The next deadline is in 20 minutes 007: q
You can run the autotests for Stage 2 by running the following command:
1511 autotest-stage 02 cs_pizzeria
Why does this stage exist?
This stage tests your ability to manipulate the fields of structs within a linked list, and to create, insert and iterate through a two-dimensional linked list.
Who do we expect to complete this stage?
Though it could be difficult for some, we hope that all students will be complete almost if not all of this stage.
What help will tutors provide to students?
Tutors can give you a detailed theoretical explanation, and give lots of help with the lab exercises that lead to this assignment. Tutors will be happy to help you debug any issues with your code.
How many marks will I get?
Completing this stage, with good style, is worth around a 65% mark.
In this stage, you will implement:
select_next_order()
print_selected_order()
select_previous_order()
add_ingredient()
calculate_total_profit()
Your first task is to implement the function: select_next_order()
. The details of the function can be found in pizzeria.h
.
By selecting an order, the pizzeria is then able to do something with that particular order. In the other functions in this stage and future stages, you will need to select the order which you want to make changes to.
An analogy to understand selection is to think about editing a word document. When you select some text, you can bolden it or italicise it. Similarly, in CS Pizzeria, when you select an order, you can add an ingredient to it or calculate its total profit.
The following toggle lists contains diagrams which will help supplement your understanding of how the function affects the pizzeria.
2.1.1 Diagram for no currently selected order
2.1.2 Diagram for cycling through the orders with select_next()
Your second task is to implement the function: print_selected_order()
. The details of the function can be found in pizzeria.h
.
print_selected_order()
prints the number of the selected order and the ingredients within the selected order.
In Stage 1, when implementing print_all_orders()
, there was a function call at the end to print_selected_order()
. In the starter code, print_selected_order()
simply prints "There is no selected order." This is correct if selection hasn't been implemented yet, which was true in Stage 1. However, since you have now implemented the selection functions in 2.1 and 2.3, allowing you to select an order, you will now extend this to print out the selected order in this function.
For this function, you should use the provided helper function print_ingredient()
to print the ingredients in the expected format.
To print a double to two decimal places, we use printf("%.2lf", price);
.
You don't have to print the ingredients if you do not intend on completing the rest of Stage 2. You will still pass autotests to do with selection if you ignore printing ingredients.
2.2.1 Example output of print_selected_order()
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Shrey Pineapple 20.99 25 Added order successfully! 001: p 01: Shrey ordered a Pineapple pizza ($20.99) due in 25 minutes. No selected order. 002: > 003: p 01: Shrey ordered a Pineapple pizza ($20.99) due in 25 minutes. The selected order is Shrey's Pineapple pizza ($20.99) due in 25 minutes. 004: q
Your third task is to implement the function: select_previous_order()
. The details of the function can be found in pizzeria.h
.
For example, if the selected order is the third order in the list, after this function call, the selected order should become the second order in the list.
2.3.1 Example output of using select_previous_order()
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Shrey Pineapple 20.40 10 Added order successfully! 001: o Sasha Not-Pineapple 15.00 15 Added order successfully! 002: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. No selected order. 003: > 004: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. The selected order is Shrey's Pineapple pizza ($20.40) due in 10 minutes. 005: > 006: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. The selected order is Sasha's Not-Pineapple pizza ($15.00) due in 15 minutes. 007: > 008: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. No selected order. 009: < 010: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. The selected order is Sasha's Not-Pineapple pizza ($15.00) due in 15 minutes. 011: < 012: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. The selected order is Shrey's Pineapple pizza ($20.40) due in 10 minutes. 013: < 014: p 01: Shrey ordered a Pineapple pizza ($20.40) due in 10 minutes. 02: Sasha ordered a Not-Pineapple pizza ($15.00) due in 15 minutes. No selected order. 015: q
Your fourth task is to implement the function: add_ingredient()
. The details of the function can be found in pizzeria.h
.
When called, add_ingredient()
will add an ingredient to the selected order.
2.4.1 Diagram for inserting ingredients into an empty list
Before
After adding a new ingredient to the selected order, using command i Base 1 3.00
2.4.2 Diagram for inserting ingredients into a non-empty list
Before
After entering the command i Green-Pepper 3 1.5
2.4.3 Diagram for inserting existing ingredient
Before
After adding 4 more units of Mozarella to Joe's order
To order ingredients, use the function strcmp()
found in string.h
. You may find the lab exercise from Week 8: Find Element with a Given String useful.
Also, if you are finding it difficult to find a while condition, consider using a sentinel variable.
If you want to attempt Stage 3, a useful function to implement now would be:
// Insert ingredient `new` into linked list of ingredients and returns the new head as // a result struct ingredient *add_ingredient_ordered(struct ingredient *new, struct ingredient *head);
2.4.4 Example output with one ingredient
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Betty Margherita 10.99 10 Added order successfully! 001: > 002: p 01: Betty ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Betty's Margherita pizza ($10.99) due in 10 minutes. 003: i Tomato-Paste 1 1.0 Ingredient added successfully! 004: p 01: Betty ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Betty's Margherita pizza ($10.99) due in 10 minutes. Tomato-Paste: 1 @ $1.00 005: q
2.4.5 Example output with multiple ingredients
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Betty Margherita 10.99 10 Added order successfully! 001: > 002: p 01: Betty ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Betty's Margherita pizza ($10.99) due in 10 minutes. 003: i Regular-Base 1 2.0 Ingredient added successfully! 004: i Tomato-Paste 1 1.0 Ingredient added successfully! 005: i Mozzarella-Cheese 7 0.3 Ingredient added successfully! 006: i Basil-Leaf 7 0.15 Ingredient added successfully! 007: p 01: Betty ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Betty's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 7 @ $0.15 Mozzarella-Cheese: 7 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 008: i Tomato-Paste 4 1.0 Ingredient added successfully! 009: p 01: Betty ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Betty's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 7 @ $0.15 Mozzarella-Cheese: 7 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 5 @ $1.00 010: q
Your fifth task is to implement the function: calculate_total_profit()
. The details of the function can be found in pizzeria.h
.
When called, calculate_total_profit()
will calculate the total profit of the selected order by calculating the expenses of the ingredients and subtracting it from the price the customer is paying.
2.5.1 Example output of calculate_total_profit()
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Betty Margherita 10.99 10 Added order successfully! 001: > 002: i Regular-Base 1 2.0 Ingredient added successfully! 003: i Tomato-Paste 1 1.0 Ingredient added successfully! 004: i Mozzarella-Cheese 7 0.3 Ingredient added successfully! 005: i Basil-Leaf 7 0.15 Ingredient added successfully! 006: t The total profit from this order is $4.84 007: q
You can run the autotests for Stage 3 by running the following command:
1511 autotest-stage 03 cs_pizzeria
Why does this stage exist?
This stage tests your ability to manage memory, and delete from linked lists. These skills are more advanced applications of what you have achieved in Stage 1 and Stage 2, and help to advance your understanding of the linked list data structure. Whilst these skills are not essential to pass COMP1511, they are needed to succeed in the more difficult parts of the exam, and are essential in COMP2521 and COMP1521.
Who do we expect to complete this stage?
Students who want to be prepared for COMP1521 and COMP2521 should attempt this stage. If you are struggling with COMP1511, you may find that doing this stage helps, though you may also get some benefit from working through lab exercises.
What help will tutors provide to students?
Tutors can give you a theoretical explaination, and give lots of help with the lab exercises that lead to this assignment. Tutors will be happy to help you debug issues with code, though they may prioritise Stage 1 and Stage 2 help over giving help to people in Stage 3. Some of the help given will be less specific than it would have been in Stage 1 and 2.
How many marks will I get?
Completing this stage, with good style, is worth around a 90% mark.
In this stage, you will implement:
cancel_order()
free_pizzeria()
refill_stock()
print_stock()
can_complete_order()
In this stage, autotests will start to check for memory leaks in your program.
Your first task is to implement the function: cancel_order()
. The details of the function can be found in pizzeria.h
.
This function will free the selected order and its associated memory. Once this occurs, you will need to change the selected order to the next order in the list, which would be the order after the order that has just been freed. All function calls should still behave as expected.
3.1.1 Diagram of a cancelled order
Before
After command c
is used when Sophia's order is selected
3.1.2 Example output cancelling one order
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Percy Anchovies 19.99 50 Added order successfully! 001: o Dumbledore Beef-n-Onion 10 30 Added order successfully! 002: o Remus Nutella 18.99 50 Added order successfully! 003: > 004: > 005: p 01: Percy ordered a Anchovies pizza ($19.99) due in 50 minutes. 02: Dumbledore ordered a Beef-n-Onion pizza ($10.00) due in 30 minutes. 03: Remus ordered a Nutella pizza ($18.99) due in 50 minutes. The selected order is Dumbledore's Beef-n-Onion pizza ($10.00) due in 30 minutes. 006: c Selected order has been cancelled! 007: p 01: Percy ordered a Anchovies pizza ($19.99) due in 50 minutes. 02: Remus ordered a Nutella pizza ($18.99) due in 50 minutes. The selected order is Remus's Nutella pizza ($18.99) due in 50 minutes. 008: q
3.1.3 Example output cancelling multiple orders
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Betty Margherita 10.99 10 Added order successfully! 001: o Joseph Pepperoni 13.99 10 Added order successfully! 002: o John Peri-Peri 12.99 30 Added order successfully! 003: o Sophia Meat-Lovers 12.99 20 Added order successfully! 004: > 005: i Regular-Base 1 2.0 Ingredient added successfully! 006: i Tomato-Paste 1 1.0 Ingredient added successfully! 007: i Basil-Leaf 7 0.15 Ingredient added successfully! 008: i Mozzarella-Cheese 7 0.3 Ingredient added successfully! 009: > 010: i Gluten-Free-Base 1 3.5 Ingredient added successfully! 011: i Mozzarella-Cheese 7 0.3 Ingredient added successfully! 012: i Tomato-Paste 1 1.0 Ingredient added successfully! 013: i Pepperoni-Slice 15 0.2 Ingredient added successfully! 014: > 015: > 016: i Regular-Base 1 2.0 Ingredient added successfully! 017: i Tomato-Paste 1 1.0 Ingredient added successfully! 018: i Pepperoni-Slice 4 0.2 Ingredient added successfully! 019: i Mozzarella-Cheese 5 0.3 Ingredient added successfully! 020: i Sliced-Beef-Sausage 3 0.4 Ingredient added successfully! 021: i Ham 4 0.2 Ingredient added successfully! 022: i Bacon-Piece 5 0.2 Ingredient added successfully! 023: > 024: > 025: p 01: Betty ordered a Margherita pizza ($10.99) due in 10 minutes. 02: Joseph ordered a Pepperoni pizza ($13.99) due in 10 minutes. 03: John ordered a Peri-Peri pizza ($12.99) due in 30 minutes. 04: Sophia ordered a Meat-Lovers pizza ($12.99) due in 20 minutes. The selected order is Betty's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 7 @ $0.15 Mozzarella-Cheese: 7 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 026:c Selected order has been cancelled! 027: p 01: Joseph ordered a Pepperoni pizza ($13.99) due in 10 minutes. 02: John ordered a Peri-Peri pizza ($12.99) due in 30 minutes. 03: Sophia ordered a Meat-Lovers pizza ($12.99) due in 20 minutes. The selected order is Joseph's Pepperoni pizza ($13.99) due in 10 minutes. Gluten-Free-Base: 1 @ $3.50 Mozzarella-Cheese: 7 @ $0.30 Pepperoni-Slice: 15 @ $0.20 Tomato-Paste: 1 @ $1.00 028: c Selected order has been cancelled! 029: p 01: John ordered a Peri-Peri pizza ($12.99) due in 30 minutes. 02: Sophia ordered a Meat-Lovers pizza ($12.99) due in 20 minutes. The selected order is John's Peri-Peri pizza ($12.99) due in 30 minutes. 030: c Selected order has been cancelled! 031: p 01: Sophia ordered a Meat-Lovers pizza ($12.99) due in 20 minutes. The selected order is Sophia's Meat-Lovers pizza ($12.99) due in 20 minutes. Bacon-Piece: 5 @ $0.20 Ham: 4 @ $0.20 Mozzarella-Cheese: 5 @ $0.30 Pepperoni-Slice: 4 @ $0.20 Regular-Base: 1 @ $2.00 Sliced-Beef-Sausage: 3 @ $0.40 Tomato-Paste: 1 @ $1.00 032: c Selected order has been cancelled! 033: p No selected order. 034: q
Your second task is to implement the function: free_pizzeria()
. The details of the function can be found in pizzeria.h
.
Once called,free_pizzeria
will free the pizzeria passed in and its associated memory.
If you are leaking memory and completely convinced your free_pizzeria()
function is correct, you may have prematurely called malloc()
in your add_order()
or add_ingredient()
implementations.
Your third task is to implement the function: refill_stock()
. The details of the function can be found in pizzeria.h
.
This function is how we insert ingredients into the stock. The stock is a one dimensional linked list of ingredients which keeps track of how many ingredients there are in the pizzeria.
3.3.1 Diagram refilling an ingredient for the first time
Refilling the stock with the following commands
r Base 100 3.00
r Ham 500 0.2
r Chicken 20 4.00
3.3.2 Diagram refilling the same ingredient again
Before
After using the command r Base 50 3.00
Remember to free the stock in free_pizzeria()
!
Your fourth task is to implement the function: print_stock()
. The details of the function can be found in pizzeria.h
.
This function is how we print all the in-stock ingredients in the pizzeria. You should use the provided helper function print_ingredient()
to print the ingredients in the expected format.
3.4.1 Example output of print_stock()
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: r Regular-Base 600 2.0 Ingredient added successfully! 001: s The stock contains: Regular-Base: 600 @ $2.00 002: r Tomato-Paste 100 1.0 Ingredient added successfully! 003: s The stock contains: Regular-Base: 600 @ $2.00 Tomato-Paste: 100 @ $1.00 004: r Mozzarella-Cheese 1000 0.3 Ingredient added successfully! 005: s The stock contains: Mozzarella-Cheese: 1000 @ $0.30 Regular-Base: 600 @ $2.00 Tomato-Paste: 100 @ $1.00 006: r Basil-Leaf 400 0.15 Ingredient added successfully! 007: s The stock contains: Basil-Leaf: 400 @ $0.15 Mozzarella-Cheese: 1000 @ $0.30 Regular-Base: 600 @ $2.00 Tomato-Paste: 100 @ $1.00 008: r Tomato-Paste 10 1.0 Ingredient added successfully 009: s The stock contains: Basil-Leaf: 400 @ $0.15 Mozzarella-Cheese: 1000 @ $0.30 Regular-Base: 600 @ $2.00 Tomato-Paste: 110 @ $1.00 010: q
Your fifth task is to implement the function: can_complete_order()
. The details of the function can be found in pizzeria.h
.
The chefs of the pizzeria need to know if they can complete the order with their current stock. can_complete_order()
will compare the selected order's required ingredients with the pizzeria's stock of ingredients.
3.5.1 Example output can_complete_order()
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: r Regular-Base 100 2.0 Ingredient added successfully! 001: r Tomato-Paste 200 1.0 Ingredient added successfully! 002: r Mozzarella-Cheese 3 0.3 Ingredient added successfully! 003: r Basil-Leaf 10 0.15 Ingredient added successfully! 004: s The stock contains: Basil-Leaf: 10 @ $0.15 Mozzarella-Cheese: 3 @ $0.30 Regular-Base: 100 @ $2.00 Tomato-Paste: 200 @ $1.00 005: o Stanley Margherita 10.99 10 Added order successfully! 006: > 007: i Regular-Base 1 2.0 Ingredient added successfully! 008: i Tomato-Paste 1 1.0 Ingredient added successfully! 009: i Mozzarella-Cheese 4 0.3 Ingredient added successfully! 010: i Basil-Leaf 2 0.15 Ingredient added successfully! 011: p 01: Stanley ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Stanley's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 2 @ $0.15 Mozzarella-Cheese: 4 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 012: ? There are not enough items in the stock for this order to be completed! 013: q
You can run the autotests for Stage 4 by running the following command:
1511 autotest-stage 04 cs_pizzeria
Why does this stage exist?
This stage tests your ability to perform more complex linked list operations and manipulate strings in more advanced ways. These skills are not essential to pass COMP1511 but provide a challenge for those looking for it.
Who do we expect to complete this stage?
Students who are looking for a greater challenge from the course. It is not expected for a majority of the cohort to attempt this stage.
What help will tutors provide to students?
Tutors can give you a theoretical explanation to understand this stage. They will not be able to give specific advice on what code is needed nor will they be able to help with specific bugs you encounter.
How many marks will I get?
Completing this stage, with good style, is worth around a 100% mark.
In this stage, you will implement:
complete_order()
save_ingredients()
load_ingredients()
Your first task is to implement the function: complete_order()
. The details of the function can be found in pizzeria.h
.
This function will complete the selected order if it is possible and adjust the stock based on this completion. This will involve using free on an entire order and removing certain elements from the stock given the condition outlined in pizzeria.h
You will need to rely heavily on the reference solution to ensure your solution is correct.
4.1.1 Simple Completion
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== ... Other commands appeared before here ... 010: p 01: Stanley ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Stanley's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 2 @ $0.15 Mozzarella-Cheese: 4 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 011: s The stock contains: Basil-Leaf: 10 @ $0.15 Mozzarella-Cheese: 4 @ $0.30 Regular-Base: 100 @ $2.00 Tomato-Paste: 200 @ $1.00 012: # The selected order has been completed! 013: p No selected order. 014: s The stock contains: Basil-Leaf: 8 @ $0.15 Regular-Base: 99 @ $2.00 Tomato-Paste: 199 @ $1.00 015: q
4.2.1 Simple Non-Completion
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== ... Other commands appeared before here ... 010: p 01: Stanley ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Stanley's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 2 @ $0.15 Mozzarella-Cheese: 4 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 011: s The stock contains: Basil-Leaf: 10 @ $0.15 Mozzarella-Cheese: 3 @ $0.30 Regular-Base: 100 @ $2.00 Tomato-Paste: 200 @ $1.00 012: # There are not enough items in the stock for this order to be completed! 013: p 01: Stanley ordered a Margherita pizza ($10.99) due in 10 minutes. The selected order is Stanley's Margherita pizza ($10.99) due in 10 minutes. Basil-Leaf: 2 @ $0.15 Mozzarella-Cheese: 4 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 014: s The stock contains: Basil-Leaf: 10 @ $0.15 Mozzarella-Cheese: 3 @ $0.30 Regular-Base: 100 @ $2.00 Tomato-Paste: 200 @ $1.00 015: q
For the next two sections, you have been provided a small library to save and load strings into files:
To download these files, run the following commands in your terminal:
ln -s /web/cs1511/21T3/activities/cs_pizzeria/save_string.c . ln -s /web/cs1511/21T3/activities/cs_pizzeria/save_string.h .
To compile your program now, you will need to run:
dcc -o pizzeria save_string.c main.c pizzeria.c
You will need to #include "save_string.h"
in your pizzeria.c
to use the provided functions.
Your second task is to implement the function: save_ingredients()
. The details of the function can be found in pizzeria.h
.
Once called,save_ingredients
will save the ingredients of the selected ordered as a string to a file. A function save_string()
has been provided to save a given string into a file.
You may find the function sprintf()
to be useful.
Your third task is to implement the function: load_ingredients()
. The details of the function can be found in pizzeria.h
.
Once called,load_ingredients
will add the ingredients of the file with the given name to the currently selected order. A function load_string()
has been provided to load the file of the given name into a string which it returns.
4.3.1 Simple Save and Load
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Stanley Margherita 10.99 10 Added order successfully! 001: o Sophia Margerita 10.99 20 Added order successfully! 002: > 003: i Regular-Base 1 2.0 Ingredient added successfully! 004: i Tomato-Paste 1 1.0 Ingredient added successfully! 005: i Mozzarella-Cheese 4 0.3 Ingredient added successfully! 006: i Basil-Leaf 2 0.15 Ingredient added successfully! 007: S Margherita Order has successfully been saved into file 'Margherita.txt' 008: > 009: p 01: Stanley ordered a Margherita pizza ($10.99) due in 10 minutes. 02: Sophia ordered a Margerita pizza ($10.99) due in 20 minutes. The selected order is Sophia's Margerita pizza ($10.99) due in 20 minutes. 010: L Margherita Order has successfully been loaded from file 'Margherita.txt' 011: p 01: Stanley ordered a Margherita pizza ($10.99) due in 10 minutes. 02: Sophia ordered a Margerita pizza ($10.99) due in 20 minutes. The selected order is Sophia's Margerita pizza ($10.99) due in 20 minutes. Basil-Leaf: 2 @ $0.15 Mozzarella-Cheese: 4 @ $0.30 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 012: q
4.3.2 Save Load Merge Ingredients
dcc -o cs_pizzeria main.c pizzeria.c ./cs_pizzeria ===========================[ CS Pizzeria ]========================== Welcome to CS Pizzeria! Type 'h' to see help. ==================================================================== 000: o Stanley Pepperoni 10.99 10 Added order successfully! 001: o Sophia Margerita 10.99 20 Added order successfully! 002: > 003: i Regular-Base 1 2.0 Ingredient added successfully! 004: i Tomato-Paste 1 1.0 Ingredient added successfully! 005: i Mozzarella-Cheese 4 0.3 Ingredient added successfully! 006: i Pepperoni 10 0.15 Ingredient added successfully! 007: S Pepperoni Order has successfully been saved into file 'Pepperoni.txt' 008: > 009: i Mozzarella-Cheese 5 0.3 Ingredient added successfully! 010: i Pepperoni 7 0.15 Ingredient added successfully! 011: p 01: Stanley ordered a Pepperoni pizza ($10.99) due in 10 minutes. 02: Sophia ordered a Margerita pizza ($10.99) due in 20 minutes. The selected order is Sophia's Margerita pizza ($10.99) due in 20 minutes. Mozzarella-Cheese: 5 @ $0.30 Pepperoni: 7 @ $0.15 012: L Pepperoni Order has successfully been loaded from file 'Pepperoni.txt' 013: p 01: Stanley ordered a Pepperoni pizza ($10.99) due in 10 minutes. 02: Sophia ordered a Margerita pizza ($10.99) due in 20 minutes. The selected order is Sophia's Margerita pizza ($10.99) due in 20 minutes. Mozzarella-Cheese: 9 @ $0.30 Pepperoni: 17 @ $0.15 Regular-Base: 1 @ $2.00 Tomato-Paste: 1 @ $1.00 014: q
You may find the function sscanf()
to be useful.
Joint work is not permitted on this assignment.
This is an individual assignment.
The work you submit must be entirely your own work. Submission of any work even partly written by any other person is not permitted.
The only exception being if you use small amounts (< 10 lines) of general purpose code (not specific to the assignment) obtained from a site such as Stack Overflow or other publicly available resources. You should attribute the source of this code clearly in an accompanying comment.
Assignment submissions will be examined, both automatically and manually for work written by others.
Do not request help from anyone other than the teaching staff of COMP1511.
Do not post your assignment code to the course forum - the teaching staff can view assignment code you have recently autotested or submitted with give.
Rationale: this assignment is an individual piece of work. It is designed to develop the skills needed to produce an entire working program. Using code written by or taken from other people will stop you learning these skills.
The use of code-synthesis tools, such as GitHub Copilot, is not permitted on this assignment.
Rationale: this assignment is intended to develop your understanding of basic concepts. Using synthesis tools will stop you learning these fundamental concepts.
Sharing, publishing, distributing your assignment work is not permitted.
Do not provide or show your assignment work to any other person, other than the teaching staff of COMP1511. For example, do not share your work with friends.
Do not publish your assignment code via the internet. For example, do not place your assignment in a public GitHub repository.
Rationale: by publishing or sharing your work you are facilitating other students to use your work, which is not permitted. If they submit your work, you may become involved in an academic integrity investigation.
Sharing, publishing, distributing your assignment work after the completion of COMP1511 is not permitted.
For example, do not place your assignment in a public GitHub repository after COMP1511 is over.
Rationale:COMP1511 sometimes reuses assignment themes, using similar concepts and content. If students in future terms can find your code and use it, which is not permitted, you may become involved in an academic integrity investigation.
Violation of the above conditions may result in an academic integrity investigation with possible penalties, up to and including a mark of 0 in COMP1511 and exclusion from UNSW.
Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other misconduct. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted - you may be penalised, even if the work was submitted without your knowledge or consent. This may apply even if your work is submitted by a third party unknown to you.
If you have not shared your assignment, you will not be penalised if your work is taken without your consent or knowledge.
For more information, read the UNSW Student Code , or contact the course account.
You should submit intermediate versions of your assignment. Every time you autotest or submit, a copy will be saved as a backup. You can find those backups here , by logging in, and choosing the yellow button next to ass2_cs_pizzeria
.
Every time you work on the assignment and make some progress, you should copy your work to your CSE account and submit it using the give
command below.
It is fine if intermediate versions do not compile or otherwise fail submission tests.
Only the final submitted version of your assignment will be marked.
You submit your work like this:
give cs1511 ass2_cs_pizzeria pizzeria.c
The only file you should modify is pizzeria.c
. It is not possible to add new files, or modify the other files we have given you. If you believe you need to modify those files, you have misunderstood the specification. You should not modify your copies of those files in any way.
This assignment will contribute 25% to your final mark.
80% of the marks for this assignment will be based on the performance of the code you write in pizzeria.c
.
20% of the marks for this assignment will come from manually marking of the readability of the code you have written in C. These marks will be awarded on the basis of clarity, commenting, elegance and style. In other words, your tutor will assess how easy it is for a human to read and understand your program.
Marks for your performance will be allocated according to the below scheme:
Marks for your performance will be allocated roughly according to the below scheme.
100% for Performance | Completely working implementation, which exactly follows the spec. |
90% for Performance | Completely working implementation of Stage 1, 2, and 3. |
65% for Performance | Completely working implementation of Stage 1 and 2. |
50% for Performance | Partially working implementation of Stage 1 and Stage 2's functions: Select Next, Select Previous and Print Selected Order. |
30% for Performance | Completely working implementation of Stage 1 |
20% for Performance | Completely working implementation of Stage 1 functions: Add Order and Print All Orders. |
Marks for your style will be allocated roughly according to the scheme below.
100% for Style | Perfect style |
90% for Style | Great style, almost all style characteristics perfect. |
80% for Style | Good style, one or two style characteristics not well done. |
70% for Style | Good style, a few style characteristics not well done. |
60% for Style | OK style, an attempt at most style characteristics. |
<= 50% for Style | An attempt at style. |
The following is a list of items that will be considered when your program is assessed for style:
Note that the following penalties apply to your total mark for plagiarism:
0 for the assignment | Knowingly providing your work to anyone and it is subsequently submitted (by anyone). |
0 for the assignment | Submitting any other person's work. This includes joint work. |
0 FL for COMP1511 | Paying another person to complete work. Submitting another person's work without their consent. |
This assignment is due 19 November 2021 20:00:00. For each hour after that time, the maximum mark it can achieve will be reduced by 3%.
For instance, at 30 minutes past the due date, the maximum mark you can get is 97%.
For instance, at 20 hours and 30 minutes past the due date, the maximum mark you can get is 37%.
Purchased 6 times