# CS Pizzeria

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.

## Overview

### Assignment Livestream

The Assignment Livestream is scheduled for Thursday, Week 8 18:00-19:30. After that time, it will be available here.

### What is CS Pizzeria?

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.

### Provided Structs

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
• Purpose: To store the state of the pizzeria.
• Contains:
• struct order *orders - points to the head of the orders list or NULL.
• struct order
• Purpose: To store information about a single order.
• Contains:
• struct order *next - points to the next order in the linked list or NULL.
• struct ingredient
• Purpose: To store information about a single ingredient.
• Contains:
• struct ingredient *next - points to the next ingredient in the linked list or NULL.
• Hint: You should not use this struct until Stage 2.

Remember that these are skeletons, so add to the contents of each struct to suit your implementation of the assignment.

## Allowed C Features

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.
• Structs.
• If statements.
• While loops.
• Pointers.
• char arrays/strings (you are not allowed to use arrays which are not char arrays).
• Standard libraries: stdio.h, stdlib.h and string.h.
• Style: Header comments, function comments, constants (#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.

## Reference Implementation

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

## Starter Code

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
• Do not change this file.
• Contains declarations for all the functions that you need to implement for this assignment.
• Contains extensive documentation for each function that you need to implement, including examples of invalid input, any assumptions and the purpose of each function.
• We may need to update this file from time to time (in the case of typos, or missing statements). The most up-to-date version number of the file will be mentioned at the very top of this page.
 pizzeria.c
• This is the only file you will be submitting. All of your code will be in this file.
• Contains stubs for each function in pizzeria.h.
• The function create_pizzeria has been completed for the current definition of struct pizzeria.
• When you change the contents of struct pizzeria, you will need to update the function to match.
• Contains the helper functions 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.
 main.c
• Do not change this file.
• Contains a main and other functions, which allow you to interact and test the functions you implement in pizzeria.c.

## How To Get Started

1. Create a new folder for your assignment work and move into it.
mkdir ass2
cd ass2

2. 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.

3. 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.

4. Spend a few minutes playing with the reference solution -- get a feel for how the assignment works.
1511 cs_pizzeria

5. Read through Stage 1 on the webpage, then read through Stage 1 in pizzeria.h.
7. Start coding in 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!
8. Repeat steps 5-8 with each following stage you want to complete.

## How To Compile

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.

## Stage 1

You can run the autotests for Stage 1 by running the following command:

1511 autotest-stage 01 cs_pizzeria

In this stage, you will implement:

1. add_order()
2. print_all_orders()
3. 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:

• The customer's name,
• The pizza's name,
• The price they will pay for the pizza and
• The time allowed to cook the pizza in.

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.

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.

////////////////////////////////////////////////////////////////////////
// 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
//
// 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.

After adding an order with command o Joe Meat-Lovers 10.99 20

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.

### 1.2 Print All Orders

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.

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
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  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  ### 1.3 Next Deadline 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. 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  ## Stage 2 You can run the autotests for Stage 2 by running the following command: 1511 autotest-stage 02 cs_pizzeria In this stage, you will implement: 1. select_next_order() 2. print_selected_order() 3. select_previous_order() 4. add_ingredient() 5. calculate_total_profit() ### 2.1 Select Next Order 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.2 Print Selected Order 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. 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


### 2.3 Select Previous Order

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.

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
001: o Sasha Not-Pineapple 15.00 15
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.

Before

After adding a new ingredient to the selected order, using command i Base 1 3.00

Before

After entering the command i Green-Pepper 3 1.5

Before

After adding 4 more units of Mozarella to Joe's order

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
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
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  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
007: q


## Stage 3

You can run the autotests for Stage 3 by running the following command:

1511 autotest-stage 03 cs_pizzeria

In this stage, you will implement:

1. cancel_order()
2. free_pizzeria()
3. refill_stock()
4. print_stock()
5. can_complete_order()

In this stage, autotests will start to check for memory leaks in your program.

### 3.1 Cancel Order

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.

Before

After command c is used when Sophia's order is selected

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
001: o Dumbledore Beef-n-Onion 10 30
002: o Remus Nutella 18.99 50
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  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


### 3.2 Free Pizzeria

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.

### 3.3 Refill Stock

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.

Refilling the stock with the following commands

• r Base 100 3.00
• r Ham 500 0.2
• r Chicken 20 4.00

Before

After using the command r Base 50 3.00

### 3.4 Print Stock

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.

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
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
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
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


### 3.5 Can Complete Order

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.

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
001: r Tomato-Paste 200 1.0
002: r Mozzarella-Cheese 3 0.3
003: r Basil-Leaf 10 0.15
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
006: >
007: i Regular-Base 1 2.0
008: i Tomato-Paste 1 1.0
009: i Mozzarella-Cheese 4 0.3
010: i Basil-Leaf 2 0.15
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


## Stage 4

You can run the autotests for Stage 4 by running the following command:

1511 autotest-stage 04 cs_pizzeria

In this stage, you will implement:

1. complete_order()
2. save_ingredients()
3. load_ingredients()

### 4.1 Complete order

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.

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  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  ### 4.2/4.3 Preamble For the next two sections, you have been provided a small library to save and load strings into files:  save_string.h • Do not change this file. • Contains declarations for functions to be used for file handling. • We may need to update this file from time to time (in the case of typos, or missing statements). The most up-to-date version number of the file will be mentioned at the very top of this page.  save_string.c • Do not change this file. • Contains implementations for functions to be used for file handling. • You do not need to understand what is going on here but if you are interested in implementation, feel free to read this! • We may need to update this file from time to time (in the case of typos, or missing statements). The most up-to-date version number of the file will be mentioned at the very top of this page. 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 cs_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. ### 4.2 Save Ingredients 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. ### 4.3 Load Ingredients 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. 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  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


# Assessment

## Assignment Conditions

• 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.

## Submission of Work

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.

## Assessment Scheme

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:

• Header commenting (including your zID, the date and a short description of the program).
• Consistent, sensible indenting.
• Using blank lines and whitespace.
• Using constants.
• Using functions effectively.
• Using comments effectively (at least at the top of functions, and not containing irrelevant information).

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.

### Due Date

This assignment is due 20 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%.