CS Pet Salon

Overview

Welcome to CS Pet Salon! Your task is to implement a pet salon manager involving several salons which have rooms for different types of pets. A pet salon is where pets get cared for and pampered. You will track the details of the pets being looked after in each salon!

Assignment Structure

This assignment will test your ability to create, manipulate, and use linked lists to solve a variety of problems. To do this, you will be implementing a system to keep track of pet salons!

We have defined some structs in the provided code to get you started. You may modify any of the structs if you wish, but you should not need to.

struct salon

  • Purpose:
    • To store all the information of a salon
  • Fields:
    • char salon_name[MAX_NAME_LEN]
      • The name of the salon
    • struct financial_summary summary
      • A struct for all the finances relating to the salon
    • double base_cost
      • A double to keep track of the base cost of the salon
    • struct pet_room *rooms
      • A pointer to the start of the list of pet rooms
    • struct salon *next
      • A pointer to the next salon

struct pet_room

  • Purpose:
    • To store all the information of a single room within the salon and the pets within the room
  • Fields:
    • char room_name[MAX_NAME_LEN]
      • The name of the room
    • enum pet_type pet_type
      • The type of pet as an enum
      • Can be either CAT, DOG, RABBIT or PARROT
    • int num_pets
      • Number of pets to be cared for in a room
    • struct pet_room *next
      • The next room in the pet salon

struct financial_summary

  • Purpose:
    • To store all the financial information of the salon
  • Fields:
    • int total_cared
      • The number of pets that have been cared for
    • double total_profit
      • Total profit from the number of pets being cared for

Additionally, you can create your own enums if you would like, but you should not modify the provided pet_type enum.

Reference Implementation

To help you understand the proper behaviour of the CS Pet Salon, we have provided a reference implementation. If you have any questions about the behaviour of your assignment, you can check and compare it to the reference implementation.

To run the reference implementation, use the following command:

 1091 cs_pet_salon

How to get started

There are a few steps to getting started with CS Pet Salon.

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

    Or, copy these file(s) to your CSE account using the following command:

    1091 fetch-activity cs_pet_salon
    

  2. Run 1091 autotest cs_pet_salon to make sure you have correctly downloaded the file.

1091 autotest cs_pet_salon
  1. Read through Stage 1.

About the starter code

The starter code contains some provided functions to help simplify some stages of the assignment. These functions have been fully implemented for you and should not need to be modified to complete the assignment.

These provided functions will be explained in the relevant stages of the assignment. 
Please read the comments and the assignment specification as we will suggest certain provided functions for you to use.

It also contains two function stubs, create_salon and create_room, which you will need to complete in Stage 1.1.

Finally, the main function contains some comments to help guide you through Stage 1.1, as well as some printf messages which run when the program starts and ends.

These printf messages are:

Welcome to 1091 CS Pet Salon manager! =^.^=
All pet salons closed! =^.^=

Allowed C Features

In this assignment, you cannot use arrays, other than char arrays for strings, 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 weeks 8 and 9. The only C features you will need to get full marks in the assignment are:

  • intchar, and double variables.
  • Enums.
  • Structs.
  • If statements.
  • While and for loops.
  • Your own functions.
  • Pointers.
  • char arrays/strings (you are not allowed to use arrays that are not char arrays).
  • Linked lists.
  • Good Code 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 (DPST1091|ADMN0112).

Features that the Style Guide labeled as illegal will be penalized during marking.

FAQ

Q: Can I edit the given starter code functions/structs/enums?

Yes. You can edit any of the functions/structs/enums given in the starter code. You can delete the whole starter code and start from scratch if you really want to (not recommended).

Q: Can I use X other C feature

A: For everything not taught in the course, check the style guide. If it says "Avoid", then we may take style marks off if its not used correctly. If it says "Don't Use" then we will take style marks off (see the style marking rubric).

Your Tasks

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

For Stage 1 of this assignment, you will be implementing the command loop, as well as the commands to add pet rooms to a pet salon.

Specifically, this will include:

  • Implementing the create_salon and create_room functions.
  • Implementing the command loop, to scan commands until CTRL-D.
  • Adding rooms to the end of the salon.
  • Printing out all rooms in the salon.
  • Handling errors.
  • Inserting adjacent room.

By the end of this stage, your linked list of pet rooms will look something like:

Stage 1: A linked list of rooms.

Stage 1.1 - Creating a salon and room

As you might have found by now, it can be really useful to have a function that takes the input for a linked list node, calls malloc and initialises all the fields of the node. So, in Stage 1.1, we will be implementing functions that do exactly that for a struct salon, and for a struct pet_room.

You'll find the following unimplemented functions in the starter code:

// TODO: what does this function do?
//
// Paramters:
//      TODO: explain what your parameters are here!
// Returns:
//      TODO: explain what your function returns here!
struct salon *create_salon(char salon_name[MAX_NAME_LEN], double base_cost) {

    // STAGE 1.1
    // TODO: malloc, initialise, and return a new salon.
    
    // hint: you will have to replace NULL in this return statement.

    return NULL;
}

// TODO: what does this function do?
//
// Paramters:
//      TODO: explain what your parameters are here!
// Returns:
//      TODO: explain what your function returns here!
struct pet_room *create_room(char room_name[MAX_NAME_LEN], enum pet_type pet_type) {

    // STAGE 1.1
    // TODO: malloc, initialise, and return a new room.
    
    // hint: you will have to replace NULL in this return statement.

    return NULL;
}

Your task is to complete the create_salon function, so that it:

  1. Malloc's a new struct salon.
  2. Copies the salon_name and base_cost into the corresponding struct field.
  3. Initialise the nested struct financial_summary such that total_cared and total_profit are zero.
  4. Assign next and rooms to NULL.
  5. Returns a pointer to the malloc'd struct.

Your also then need to complete the create_room function, so that it:

  1. Malloc's a new struct pet_room.
  2. Copies the room_name and pet_type into the corresponding struct fields.
  3. Initialises all other fields to some either zero equivalent or NULL.
  4. Returns a pointer to the malloc'd struct.

Error Conditions

  • There is no error handling required for this stage. You'll be adding this later in Stage 1.4 - Handle Errors.

Testing

There are no autotests for Stage 1.1.

Instead, you may want to double check your work by compiling your code using dcc and making sure there are no warnings or errors. If you manually tested ./cs_pet_salon, it would only print the lines in main.

As you can tell, this does not test the functions you just implemented. You could also write some temporary testing code to check your create_salon and create_room functions work properly.

For example, you could copy the following testing code into your main function:

///////////////////////////// TESTING CODE /////////////////////////////

    // name of pet room
    char name[MAX_NAME_LEN] = "blue";

    // create a struct room with 
    //      room_name   : "blue"
    //      pet_type    : CAT
    struct pet_room *test_room = create_room(name, CAT);

    // print out all of its fields.
    printf("room name: %s\n", test_room->room_name);
    printf("number of pets: %d\n", test_room->num_pets);

    if (test_room->pet_type == CAT) {
        printf("pet type: cat\n");
    } else {
        printf("pet type: not a cat\n");
    }

    if (test_room->next == NULL) {
        printf("next field: NULL");
    }

///////////////////////////// TESTING CODE /////////////////////////////

This code just calls create_room to malloc and initialise a struct pet_room, and then prints out all of its fields.

If you run it, it should print out something like:

room name: blue
number of pets: 0
pet type: cat
next field: NULL

Stage 1.2 - Add room

Now we'll be implementing the command loop, allowing your program to take in and perform different operations on the salon.

From this stage onwards, your program should run in a loop, scanning in and executing commands until CTRL-D. You should implement this command loop between the existing welcome and goodbye messages in the starter code.

On each iteration of the loop, your program should:

  1. Print the prompt Enter command: .
  2. Scan in a command character.
  3. Scan in any arguments following the command character and execute the command.

Each command will start with a single unique character, and may be followed by a variable number of arguments depending on the command.
The unique character for each different command and the number and type of the command arguments are specified in the relevant stages of this assignment.

The first command you have to implement is the ADD ROOMS command, which is described below.

When you run your program, a new salon should be created in main with the name "cs_salon" and base cost of 10.2. The name has been already given to you in main with the variable salon_name so you can pass it through the create_salon function.

This salon will start out empty - with no rooms.

It should look something like this:

Visual representation of an empty linked list.

To make your salon more useful, we need a way of adding a room to the end of the list of rooms.

Command: Add room

a [room_name] [pet_type]

Description

The a command takes in 2 arguments:

  • a string called room_name,
  • an enum pet_type called pet_type.

Some helper functions have been provided to help you scan in these arguments:

  • void scan_name(char string[MAX_NAME_LEN])
  • enum pet_type scan_pet_type()

You can find more information on these here: Provided helper functions.

When the a command is entered, your program should create a new room containing the room_name, pet_type, and num_pets, then append it to the end of the list of rooms inside the salon (in other words, insert the new room at the end of the salon's rooms linked list).

Finally, it should out a message to confirm the command was successful:

"Room: '[room_name]' added!\n"

You should replace [room_name] with the room_name you scanned in.

For example, if we have just started the program and we use the a command once, it would look like:

Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!

Our linked list should now look like this:

A salon with one room.

If we then run the a command again:

Enter command: a happy dog
Room: 'happy' added!

then our linked list should now look like:

A salon with two rooms.

Provided helper functions

Two helper functions have been provided for this stage: void scan_name(char string[MAX_NAME_LEN]):

  • char string[MAX_NAME_LEN]: used to scan the room_name.

enum pet_type scan_pet_type():

  • Scans the pet_type and returns it as an enum pet_type.
  • Returns INVALID_PET_TYPE if the pet_type did not correspond to one of the valid pet types.

You should use these functions to help you scan in the room_name and pet_type arguments.

Remember that the arguments must be scanned in the correct order, so your code to scan arguments will look something like the following:

// Create variables to scan arguments into
char room_name[MAX_NAME_LEN];
enum pet_type type;

// Arguments are in order: [room_name] [pet_type]

// 1. Scan room_name first
scan_name(room_name);
// 2. Then scan the pet_type
type = scan_pet_type();

// We've scanned in all the arguments! Now we can use them in our code

Error Conditions

  • There is no error handling required for this stage. You'll be adding this later in Stage 1.4 - Handle Errors.

Assumptions

  • salon_name will always be less than MAX_NAME_LEN including their null terminator at the end.
  • salon_name will not contain any whitespace. For example my_salon is a valid title but my salon is not. We will not test any invalid salon_name or room_name inputs so you do not need to account for this in your program.
  • salon_name will not contain any quotations. For example bobs is a valid title but bob's is not. We will not test any invalid salon_name or room_name inputs so you do not need to account for this in your program.
  • All input will be in lowercase. Uppercase characters will not be tested.
  • pet_type will be entered as a lowercase string and automatically converted to the correct enum pet_type for you by the scan_pet_type function, when the function is used.
Corresponding string enum pet_type
"cat" CAT
"dog" DOG
"rabbit" RABBIT
"parrot" PARROT
any invalid string INVALID_PET_TYPE

Note that you don't need to worry about INVALID_PET_TYPE until Stage 1.4.
Until then, you can assume that the returned enum pet_type will never be INVALID_PET_TYPE.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a happy dog
Room: 'happy' added!
Enter command: a quiet parrot
Room: 'quiet' added!
Enter command: 
All pet salons closed! =^.^=

Stage 1.3 - Printing rooms in the salon

Now we want a way to display the salon and all its rooms.

Command: Print rooms

p

Description

The p command takes no arguments.

When the p command is run, your program should print out all rooms in the current salon, from head to tail.

The print_one_room function has been provided for you to format and print a single room. More information on its usage can be found below. After all the rooms are printed, the following line should be printed:

All the rooms listed above are in salon '[salon_name]'.

where [salon_name] is the name of salon containing the rooms being printed.

If there are no rooms in the salon, you should print the following message instead:

There are no pet rooms in this salon!

Provided helper functions

One helper function has been provided for this stage:

void print_one_room(int position, struct pet_room *room)

  • int position: the position of where the room is in the salon. (In other words, if this room was the first in the linked list, the position would be 1).
  • struct pet_room *room: a pointer to a pet room.

This function will print out the required information for the pet room in the correct format. Your job is to determine the correct values to pass to this function.

This means you don't need to worry about copying the exact output format for the p command. To match the autotests exactly, you should loop through the list of pet rooms and call this function for each of them.

Error Conditions

  • There is no error handling required for this stage. You'll be adding this later in Stage 1.4 - Handle Errors.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: p
There are no pet rooms in this salon!
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: a happy dog
Room: 'happy' added!
Enter command: a quiet parrot
Room: 'quiet' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 2
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: quiet
    Room position: 3
    Pet type: parrot
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Stage 1.4 - Handle Errors

Once you've reached this stage, you should be able to add rooms to your salon and print them! Nice work!

However, the people using your salon system can still make mistakes! Let's consider this example:

Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a blue cat
Room: 'blue' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: blue
    Room position: 2
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

It does not make sense to have two rooms with the same name - this can be confusing for the owner! We need to ensure that the room names are unique. Also, there are only a few types of pets that the salon can look after, so we want to make sure that the input for the type of pet is actually valid for the salon.

In this stage you will be modifying your code from Stage 1.3 so we make sure only valid rooms can be added to your salon.

Error Conditions

When running the a command, you scanned in the room_name and pet_type for the new room.

If any one of the following conditions are met, then you should not append a new room to the linked list. You should instead print out an error message:

  • If there is already a room in the linked list that contains the same room_name, the following error should be printed:
    Error: This room name already exists!
  • If pet_type (returned by the scan_pet_type function) is INVALID_PET_TYPE, the following error should be printed:
    Error: Unfortunately, this salon does not cater for this pet type!

Using the strcmp function in string.h might be useful for this step!

Clarifications

  • If more than one error occurs, only the first error should be addressed by printing an error message. For example, if there is already a room name that exists and the pet type does not exist - only the room name error should be printed out.
  • As before, you can assume there is no whitespace within a room_name and do not need to do any error handling for this.
  • As before, uppercase characters are not being tested.
  • This is the same for all future commands with error checking.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a blue cat
Error: This room name already exists!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command:   
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat 
Room: 'blue' added!
Enter command: a blue mouse 
Error: This room name already exists!
Enter command: p 
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command:  
All pet salons closed! =^.^=

Stage 1.5 - Insert adjacent room

We want to make sure all pets are comfortable at their stay at the salon. We noticed that putting some pets adjacent to pets of the same type helps with this! For example when making a new room and we already see that there's a room existing for cats, we want to place this new room next to that existing room. This is similar to Stage 1.2 - Add room, however position matters for this command.

Command: Insert adjacent room

i [room_name] [pet_type]

Description

The i command is similar to the a command, except the position of the room matters.

It should create a new struct pet_room containing room_name, pet_type and num_pets. If a room exists of the same pet_type, then the new room should be inserted after that existing room. If the same pet_type is not found, then the room should be inserted at the end.

For example if we ran the following commands:

  • a blue cat
  • a happy parrot resulting in the following.
Stage 1: Adding rooms.
A salon with rooms

Then used our new command:

  • i quiet cat the room would be inserted after the same pet_type is found as seen below.
Stage 1: Inserting room into a certain position.
A salon after using the insert command

After successful insertion, your program should print the following message:

Room: '[room_name]' inserted!

Provided helper functions

See Stage 1.2 - Add room for information on how to scan the room_name and pet_type.

Error Conditions

Just like command a: add room, there are restrictions on the rooms that can be inserted into the salon.
Specifically, if any of the previous mentioned error conditions are met, then the room should not be inserted, and an error message should be printed out instead. Please refer to Error Conditions in Stage 1.4 - Handle Errors for more information.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a happy parrot
Room: 'happy' added!
Enter command: p   
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 2
    Pet type: parrot
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: i quiet cat
Room: 'quiet' inserted!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: quiet
    Room position: 2
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 3
    Pet type: parrot
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a happy dog
Room: 'happy' added!
Enter command: i messy rabbit
Room: 'messy' inserted!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 2
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 3
    Pet type: rabbit
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a happy dog
Room: 'happy' added!
Enter command: i quiet cat
Room: 'quiet' inserted!
Enter command: i loud cat
Room: 'loud' inserted!
Enter command: i red cat
Room: 'red' inserted!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: red
    Room position: 2
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: loud
    Room position: 3
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: quiet
    Room position: 4
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 5
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: i blue cat
Room: 'blue' inserted!
Enter command: i blue parrot
Error: This room name already exists!
Enter command: i happy mouse
Error: Unfortunately, this salon does not cater for this pet type!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Testing and Submission

Remember to do your own testing

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1091 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style and readability!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1091 style cs_pet_salon.c
1091 autotest-stage 01 cs_pet_salon
give dp1091 ass2_cs_pet_salon cs_pet_salon.c

Stage 2

For Stage 2 of this assignment, you will use some more advanced linked list knowledge to modify linked list nodes, and more specifically will perform calculations based on information stored over several rooms.

This will include:

  • Adding pets to the rooms.
  • Filling up all the rooms with pets.
  • Splitting a room according to room_name.
  • Caring for the pets and removing them from the room.

Stage 2.1 - Add pets

We have a salon that we can add rooms to, it is time to start adding pets to those rooms! You will need to complete the m command for this stage.

Command: Add pets

m [pet_type] [amount]

Description

The m command takes in an enum pet_type and an integer number of how many pets to be added amount.

This command should attempt to find a room with matching pet_type, and then increase the num_pets by amount.

However, a room has a CAPACITY of 10. If there is not enough space in one room, make sure there is another room that can take the leftover amount of pets.

To successfully add pets, the entire amount of pets must be able to be put in a single room, or be distributed across multiple available rooms of the correct pet type. In the case that the amount of pets is to be split across multiple rooms, the remainder of pets after a room is filled are to be added to the next available room of the correct pet type.

If there is not enough space across all rooms of the required pet type, then we cannot add any pets and need to print the following error message:

Error: There is not enough space to add that many pets!

If there is enough space, then add the pet amount and print the following:

Success! Pets have been added to room(s)!

Error Conditions

If one of the following errors occur, then the num_pets should not be changed, and an error message should be printed instead.

  • If pet_type is INVALID_PET_TYPE then print:
    Error: Unfortunately, this salon does not cater for this pet type!
  • If there is not enough space and amount is greater than availability, then print:
    Error: There is not enough space to add that many pets!
  • If the amount is less than or equal to 0, then print:
    Error: Amount of pets must be greater than zero!

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 5/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a happy parrot
Room: 'happy' added!
Enter command: m cat 5
Error: There is not enough space to add that many pets!
Enter command: m mouse 5
Error: Unfortunately, this salon does not cater for this pet type!
Enter command: m cat -3
Error: Amount of pets must be greater than zero!
Enter command: m mouse -3
Error: Unfortunately, this salon does not cater for this pet type!
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a happy dog
Room: 'happy' added!
Enter command: a neat cat
Room: 'neat' added!
Enter command: a messy rabbit
Room: 'messy' added!
Enter command: a red cat  
Room: 'red' added!
Enter command: m cat 21
Success! Pets have been added to room(s)!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 10/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 2
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: neat
    Room position: 3
    Pet type: cat
    Num of pets in room: 10/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 4
    Pet type: rabbit
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: red
    Room position: 5
    Pet type: cat
    Num of pets in room: 1/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Stage 2.2 - Fill rooms

We want to fill all the rooms with pets! This means that we want to go through every room and fill the rooms with pets, whilst keeping track of how many pets are being added for each pet type.

Command: Fill rooms

h

Description

The h command goes through every room from the salon and adds pets to the CAPACITY, which is 10.

You should then print the number of each pet added, this is provided by the help function void print_added_pets(int num_cats, int num_dogs, int num_rabbits, int num_parrots). This will print all the information required for this stage.

Provided helper function

  • void print_added_pets(int num_cats, int num_dogs, int num_rabbits, int num_parrots)
    • Takes integers; num_cats, num_dogs, num_rabbits and num_parrots which are the amounts of pets of each pet_type added to the rooms of the salon.
    • Prints the amounts of each pet_type in the correct format.

Error Conditions

  • There is no error handling required for this stage.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: h
/-------------------------------\
    Cats added: 10
    Dogs added: 0
    Rabbits added: 0
    Parrots added: 0
\-------------------------------/
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 10/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: h
/-------------------------------\
    Cats added: 5
    Dogs added: 0
    Rabbits added: 0
    Parrots added: 0
\-------------------------------/
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 10/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a happy dog
Room: 'happy' added!
Enter command: a quiet parrot
Room: 'quiet' added!
Enter command: a red rabbit
Room: 'red' added!
Enter command: a messy cat
Room: 'messy' added!
Enter command: h
/-------------------------------\
    Cats added: 20
    Dogs added: 10
    Rabbits added: 10
    Parrots added: 10
\-------------------------------/
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 10/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: happy
    Room position: 2
    Pet type: dog
    Num of pets in room: 10/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: quiet
    Room position: 3
    Pet type: parrot
    Num of pets in room: 10/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: red
    Room position: 4
    Pet type: rabbit
    Num of pets in room: 10/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 5
    Pet type: cat
    Num of pets in room: 10/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Stage 2.3 - Split room

Some pets are not getting along in the rooms! We need to split them up into two separate rooms, the original room and a new room!

For example, this is a salon with several rooms. All the rooms are full of pets!

visual representation of a linked list with several rooms

Now, if we ran the command s blue loud, we would have the following:

visual representation of a linked list with several rooms after split command

Command: Split room

s [existing_room_name] [new_room_name]

Description

The s command takes in a string existing_room_name and string new_room_name.

This command should find the room, existing_room_name, in the salon. Then split the num_pets putting the other half in a new room, new_room_name. The new room will be inserted after the existing room and will have the same pet_type.

If it's an odd number, the larger number of the split should remain in the existing_room_name room.

If you can split the existing_room_name amount of pets successfully, you should print the following message:

Success! Pet amount has been split across two rooms!

Provided helper functions

See Stage 1.2 - Add room for information on how to scan the existing_room_name and new_room_name.

Error Conditions

If one of the following errors occur, then no split should occur, and an error message should be printed instead.

  • If existing_room_name does not exist as a name of a room in the salon, the following error should be printed:
    Error: This room does not exist!
  • If the new_room_name already exists as a name of a room in the salon, the following error should be printed:
    Error: Cannot create room as room with given name already exists!
  • If the num_pets in room is less or equal to 1, the following error should be printed:
    Error: Not enough pets in room to split across two rooms!

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 6
Success! Pets have been added to room(s)!
Enter command: s blue messy
Success! Pet amount has been split across two rooms!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 3/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 2
    Pet type: cat
    Num of pets in room: 3/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: s blue messy
Success! Pet amount has been split across two rooms!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 3/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 2
    Pet type: cat
    Num of pets in room: 2/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: s blue messy
Error: Not enough pets in room to split across two rooms!
Enter command: s blue blue
Error: Cannot create room as room with given name already exists!
Enter command: s red blue
Error: This room does not exist!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Stage 2.4 - Care for pets

The pets are now in their rooms waiting to be cared for! We want to implement a command that will care for the pets. Looking after pets requires money to be spent for them to get the right amount of care! We will remove an amount of pets from num_pets and update the salon's financial_summary.

Command: Care for pets

f [room_name] [amount]

Description

The f command takes in a string room_name and an integer number of pets to be cared for amount.

This command should attempt to find the room with matching room_name, and then decreases num_pets by the amount.

You should also update the financial_summary of the salon, increasing total_cared by the amount of pets cared for (adding amount to the existing total_cared), as well as adding to the total_profit by following the below calculation.

If you can update the financial_summary and num_pets successfully, you should print the following message:

Success! [amount] pets have been cared for!

Calculating cost

You will use this formula to calculate the total cost:
total_profit = amount * (base_cost + pet_cost),
where amount comes from struct pet_room and base_cost comes from the struct salon.

The pet_cost can be found corresponding to the pet_type:

Corresponding cost ($) enum pet_type
11.5 CAT
15.5 DOG
5.5 RABBIT
7.6 PARROT

Provided helper functions

See Stage 1.2 - Add room for information on how to scan the room_name.

Error Conditions

If one of the following errors occur, then there should not any change, and an error message should be printed instead.

  • If no room with room_name exists, the following error should be printed:
    Error: This room does not exist!
  • If the amount of pets is greater than the amount of pets in the corresponding room, or less than or equal to 0, the following error should be printed:
    Error: Invalid amount!

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: f blue 4
Success! 4 pets have been cared for!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 1/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: f red 2
Error: This room does not exist!
Enter command: f blue 6
Error: Invalid amount!
Enter command: f blue -3
Error: Invalid amount!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 5/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Testing and Submission

Remember to do your own testing

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1091 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style and readability!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1091 style cs_pet_salon.c
1091 autotest-stage 02 cs_pet_salon
give dp1091 ass2_cs_pet_salon cs_pet_salon.c

Stage 3

For Stage 3 of this assignment, you will be manipulating 2D linked lists in the form of a list of salons, each of which contain a list of rooms. You will also be managing your memory usage by freeing memory and preventing memory leaks.

This will include:

  • Modifying your existing code to:
    • Keep track of a selected salon as well as the head of the list of salons.
    • Account for rooms globally in all salons. All room names have to be unique.
    • Account for salon names to be unique.
  • Adding commands to create new empty salons and switch between salons.
  • Removing and freeing rooms and salons.

By the end of this stage, your linked list of pet salons will look something like:

Multiple salons.

Stage 3.1 - Create multiple salons

In Stage 1.1 we introduced the struct salon and now we will make use of the next field in this struct to have a list of salons.

Since we are now working with a list of salons, we need to maintain a pointer to the head salon in this list, but we also want a way to navigate between salons on the list. To do this, we will introduce the idea of the currently selected salon, which is a pointer to the salon we are currently 'looking at' and is what all the commands from previous stages will apply to. You will need to make sure all commands from previous stages use the currently selected salon pointer.

Command: Create a new salon

c [salon_name] [base_cost]

Description

The c command is used to add a new empty salon in alphabetical order and takes the parameters string salon_name and double base_cost.

Use the create_salon function from Stage 1.1 to create a new salon with salon_name and base_cost.
This salon should be inserted into the list of salons so the list is in alphabetical order of salon_name in which all salon names are unique.
The currently selected salon should remain the same.
Once the salon is successfully created and added to the list of salons, the following should be printed: Success! The salon: [salon_name] has been created!

Provided helper functions

See Stage 1.2 - Add room for information on how to scan the salon_name.

Error Conditions

  • If a salon with the same salon_name already exists, the following error message should be printed:
    Error: Salon name already exists!
  • If base_cost is below $0 or greater than $40, the following error message should be printed:
    Error: Cost needs to within $0-$40!

Assumptions

  • You can assume that the salon_name does not contain any whitespace and do not need to do any error checking for this.
  • A salon and room could have the same name. Only room names need to be unique to other room names. Only salon names need to be unique to other salon names.
  • All commands from the previous stages should be applied to the currently selected salon.
  • Remember that room names must still be unique globally. You will need to modify code from previous stages, especially from Stage 1.4 - Handle Errors to account that all salons' rooms are checked to make sure that no room_name is the same as another.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c bobs 3.2
Success! The salon: bobs has been created!
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c cs_salon 2
Error: Salon name already exists!
Enter command: c bobs -1
Error: Cost needs to within $0-$40!
Enter command: 
All pet salons closed! =^.^=

Stage 3.2 - Select salon

Commands: Select next/previous salon

  • >: Select next salon

    Description:
    Set the selected salon to be the next salon in the linked list. All commands from previous stages should now apply to the newly selected salon. If there is no salon after the selected salon, then the selected salon should wrap around and be set to the head salon.

  • <: Select previous salon

    Description:
    Set the selected salon to be the previous salon in the linked list. All commands from previous stages should now use the newly selected salon. If there is no salon before the selected salon, then the selected salon should wrap around and be set to the last salon in the list (tail).

Once the selected salon has been updated, you will print the following:
You have now selected salon: [salon_name]!
where salon_name is the name of the new selected salon.

For example, this is a diagram showing many salons.

Visual representation of many salon.

Now, if we ran the command >, we would have the following:

Visual representation of selected pointer pointing to the next salon.

Error Conditions

  • There is no error handling required for this stage.

Assumptions

  • There will always be at least one salon in the list of salons.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c laras 5.4
Success! The salon: laras has been created!
Enter command: a blue cat
Room: 'blue' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: >
You have now selected salon: laras!
Enter command: a messy cat
Room: 'messy' added!
Enter command: p
/-------------------------------\
Room name: messy
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'laras'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c bobs 3.4
Success! The salon: bobs has been created!
Enter command: a blue cat
Room: 'blue' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: <
You have now selected salon: bobs!
Enter command: a messy cat
Room: 'messy' added!
Enter command: p
/-------------------------------\
Room name: messy
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'bobs'.
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c bobs 3.4
Success! The salon: bobs has been created!
Enter command: a blue cat
Room: 'blue' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: <
You have now selected salon: bobs!
Enter command: a blue parrot
Error: This room name already exists!
Enter command: a messy cat
Room: 'messy' added!
Enter command: p
/-------------------------------\
Room name: messy
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'bobs'.
Enter command: 
All pet salons closed! =^.^=

Stage 3.3 - Print salon details

Command: Print salon details

d

Description

We want to overlook all the salons we are managing including their finances and how many pets have been cared for. The d command will print the financial_summary of all the salons as well as the combined total profit and total number of pets that have been cared for.

The command will go through all salons and use void print_salon_stats(struct salon *salon, int selected) to print the salon's information.

Then using void print_total_stats(double profit, int pets), will print in the correct format.

Provided helper functions

Two functions have been provided for this stage. void print_salon_stats(struct salon *salon, int selected):

  • struct salon *salon: pointer to the struct salon, where the relevant information will be printed.
  • int selected: an integer determining if the salon is selected or not. If the integer is set to 1, then the salon is 'selected', any other number would indicate that the salon is not selected.

void print_total_stats(double profit, int pets):

  • double profit: the accumulated total profit from all the salons.
  • int pets: the accumulated total amount of pets that have been cared for across all the salons.

These functions will print out the required information in the correct format. Your job is to determine the correct values to pass to this function.

Assumptions

  • There will always be at least one salon in the list of salons.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: d
/-------------------------------\
Stats from salon: cs_salon (selected)
    Salon's base cost: 10.20
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------------------------/
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: f blue 4
Success! 4 pets have been cared for!
Enter command: d
/-------------------------------\
Stats from salon: cs_salon (selected)
    Salon's base cost: 10.20
    Total pets cared for: 4
    Total profit from cared pets: 86.80
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 4
    Total profit from cared pets: 86.80
\-------------------------------/
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: m cat 5
Success! Pets have been added to room(s)!
Enter command: f blue 4
Success! 4 pets have been cared for!
Enter command: c bobs 4.3
Success! The salon: bobs has been created!
Enter command: >
You have now selected salon: bobs!
Enter command: a messy parrot
Room: 'messy' added!
Enter command: m parrot 4
Success! Pets have been added to room(s)!
Enter command: f messy 2
Success! 2 pets have been cared for!
Enter command: d
/-------------------------------\
Stats from salon: bobs (selected)
    Salon's base cost: 4.30
    Total pets cared for: 2
    Total profit from cared pets: 23.80
\-------------- | --------------/
                V
/-------------------------------\
Stats from salon: cs_salon
    Salon's base cost: 10.20
    Total pets cared for: 4
    Total profit from cared pets: 86.80
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 6
    Total profit from cared pets: 110.60
\-------------------------------/
Enter command: 
All pet salons closed! =^.^=

Stage 3.4 - Remove room

Sometimes a salon can take up too much work and cannot maintain all the rooms. The salon might remove a room because of this. Unfortunately this also means if there are pets in the room that is to be removed, they will be sent back to their owners without being cared for.

Command: Remove room

r [room_name]

Description

The r command should attempt to find room_name by going through the currently selected salon and delete it, freeing all associated memory. If successful, the following should be printed:
Success! Room has been removed!

Provided helper function

See Stage 1.2 - Add room for information on how to scan the salon_name.

Error Conditions

  • If no room with room_name exists, the following error should be printed:
    Error: This room does not exist!

Assumptions

  • You will only need to go through the selected salon to find the room_name.
  • If there are pets in the room, they will be removed but not be cared for.

Examples

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: r blue
Success! Room has been removed!
Enter command: p
There are no pet rooms in this salon!
Enter command: 
All pet salons closed! =^.^=

dcc cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: r blue    
Error: This room does not exist!
Enter command: 
All pet salons closed! =^.^=

Stage 3.5 - Remove salon

Unfortunately, salons can be overworked and need to shutdown. This means all the rooms need to be closed first in the salon, before the salon is closed.

Command: Remove salon

q

Description

The q command should delete and free the currently selected salon and all its rooms.

You must update the selected salon to the previous salon in the list of salons. This should also wrap around. For example if the old selected salon is the first salon, the new selected salon will be the last of the linked list.

Additionally, when the program ends, all malloc'd memory should be freed, and there should be no memory leaks.

Assumptions

  • You cannot remove the salon if there is only one salon.
  • From now on, you should check for memory leaks by compiling with --leak-check as can be seen by the below examples.
  • Autotests and marking tests from this stage onwards onwards will check for memory leaks.

Errors Conditions

  • If there is only one salon, the following should be printed:
    Error: Cannot remove when there is only one salon!

Examples

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c bobs 4.3
Success! The salon: bobs has been created!
Enter command: q
Enter command: d         
/-------------------------------\
Stats from salon: bobs (selected)
    Salon's base cost: 4.30
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------------------------/
Enter command: 
All pet salons closed! =^.^=

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: q
Error: Cannot remove when there is only one salon!
Enter command: d
/-------------------------------\
Stats from salon: cs_salon (selected)
    Salon's base cost: 10.20
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------------------------/
Enter command: 
All pet salons closed! =^.^=

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: c laras 4.3
Success! The salon: laras has been created!
Enter command: c johns 7.2
Success! The salon: johns has been created!
Enter command: d
/-------------------------------\
Stats from salon: cs_salon (selected)
    Salon's base cost: 10.20
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Stats from salon: johns
    Salon's base cost: 7.20
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Stats from salon: laras
    Salon's base cost: 4.30
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------------------------/
Enter command: q
Enter command: a messy cat
Room: 'messy' added!
Enter command: p
/-------------------------------\
Room name: messy
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'laras'.
Enter command: 
All pet salons closed! =^.^=

Testing and Submission

Remember to do your own testing

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1091 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1091 style cs_pet_salon.c
1091 autotest-stage 03 cs_pet_salon
give dp1091 ass2_cs_pet_salon cs_pet_salon.c

Stage 4

This stage is for students who want to challenge themselves, and solve more complicated linked lists and programming problems, such as:

  • Order the rooms alphabetically in the currently selected salon.
  • Creating a new salon and merge two salons into a new salon.

Stage 4.1 - Order rooms

The owner of the salon has decided that they want the rooms to be alphabetically ordered to make it easier to navigate through the salon to see the pet rooms. This command will order the rooms!

Command: Order rooms

o

Description

Order alphabetically the existing rooms of the currently selected salon.

For example, if we had the below rooms:

Visual representation of list of rooms before ordered.

Then after executing the command o, we would have:

Visual representation of list of rooms after ordered.

Error Conditions

  • There is no error handling required for this stage.

Assumptions

  • There are no rooms with the same name.

Examples

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a awesome dog
Room: 'awesome' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: awesome
    Room position: 2
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: o
Enter command: p
/-------------------------------\
Room name: awesome
    Room position: 1
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: blue
    Room position: 2
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a blue cat
Room: 'blue' added!
Enter command: a messy dog
Room: 'messy' added!
Enter command: a neat parrot
Room: 'neat' added!
Enter command: a cool cat
Room: 'cool' added!
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 2
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: neat
    Room position: 3
    Pet type: parrot
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: cool
    Room position: 4
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: o
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: cool
    Room position: 2
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: messy
    Room position: 3
    Pet type: dog
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: neat
    Room position: 4
    Pet type: parrot
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'cs_salon'.
Enter command: 
All pet salons closed! =^.^=

Stage 4.2 - Merge pet salons

In this stage you will be merging two existing salons into a new salon including rooms. The new salon will be added in alphabetical order and the rooms in the new salon will all be in alphabetical order too. The alphabetical ordering is calculated the same as previous stages.

Command: Merge pet salons

x [new_salon_name] [old_salon_name_1] [old_salon_name_2]

Description

The x command is used to merge two salons, old_salon_name_1 and old_salon_name_2 into a new salon new_salon_name.

You will be adding all the rooms from both old_salon_name_1 and old_salon_name_2 to the salon with new_salon_name. The base_cost for the new salon is calculated as the average of the base_cost from old_salon_name_1 and old_salon_name_2. You will also remove the old two salons, old_salon_name_1 and old_salon_name_2, and all the rooms within.

The rooms in the new salon need to be ordered alphabetically.

The currently selected salon will update to the new salon created. The new salon's financial_summary should also have both old_salon_name_1 and old_salon_name_2 financials combined.

Provided helper functions

See Stage 1.2 - Add room for information on how to scan the old_salon_name_1 and old_salon_name_2.

Error Conditions

  • If new_salon_name already exists and is not old_salon_name_1 or old_salon_name_2, the following error should be printed:
    Error: Salon name already exists!
  • If old_salon_name_1 or old_salon_name_2 do not exist, the following error should be printed:
    Error: Salon name(s) do not exist to be merged!
  • If old_salon_name_1 and old_salon_name_2 are the same, the following error should be printed:
    Error: Cannot merge a salon with itself!

Assumptions

  • The new_salon_name must be unique, however, it can also have the name from old_salon_name_1 and old_salon_name_2.

Examples

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: a red parrot
Room: 'red' added!
Enter command: c bobs 4.3
Success! The salon: bobs has been created!
Enter command: >
You have now selected salon: bobs!
Enter command: a blue cat
Room: 'blue' added!
Enter command: d
/-------------------------------\
Stats from salon: bobs (selected)
    Salon's base cost: 4.30
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Stats from salon: cs_salon
    Salon's base cost: 10.20
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------------------------/
Enter command: x laras cs_salon bobs
Enter command: d
/-------------------------------\
Stats from salon: laras (selected)
    Salon's base cost: 7.25
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------- | --------------/
                V
/-------------------------------\
Combined stats from all salons!
    Total pets cared for: 0
    Total profit from cared pets: 0.00
\-------------------------------/
Enter command: p
/-------------------------------\
Room name: blue
    Room position: 1
    Pet type: cat
    Num of pets in room: 0/10
\-------------- | --------------/
                V
/-------------------------------\
Room name: red
    Room position: 2
    Pet type: parrot
    Num of pets in room: 0/10
\-------------- | --------------/
                V
All the rooms listed above are in salon 'laras'.
Enter command: 
All pet salons closed! =^.^=

dcc --leak-check cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon
Welcome to 1091 CS Pet Salon manager! =^.^=
Enter command: x laras cs_salon bobs
Error: Salon name(s) do not exist to be merged!
Enter command: x cs_salon cs_salon cs_salon
Error: Cannot merge a salon with itself!
Enter command: c bobs 4.3
Success! The salon: bobs has been created!
Enter command: x bobs cs_salon cs_salon
Error: Salon name already exists!
Enter command: 
All pet salons closed! =^.^=

Testing and Submission

Remember to do your own testing

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1091 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1091 style cs_pet_salon.c
1091 autotest-stage 04 cs_pet_salon
give dp1091 ass2_cs_pet_salon cs_pet_salon.c

Extension

As an extension, we have set up a starting point to add a texture pack to your game via splashkit.

Extension activities are not work any marks, nor are there any autotests.

Installing Splashkit

To install splashkit, run the following command:

1091 setup-splashkit cs_pet_salon

Next, open a new terminal to use the updated environment.

Check that Splashkit Works

Lets check that splashkit works by running a test file. It should display a white square with a grid inside.

The previous command should have added splashkit_example.c to your current directory. If you can't find it, run: cp -n /web/dp1091/24T3/activities/cs_pet_salon/splashkit_example.c ..

skm clang++ splashkit_example.c -o splashkit_example
./splashkit_example

Running your code with splashkit

The last two commands are a bit like your new dcc cs_pet_salon.c -o cs_pet_salon and ./cs_pet_salon but for splashkit. So it will look a bit like:

skm clang++ cs_pet_salon.c -o cs_pet_salon
./cs_pet_salon

Starting Points for Splashkit

Have a look inside of splashkit_example.c to see what they have added. A couple things to note are:

  • #include "splashkit.h" is needed at the top of the file.
  • Line 48, window w = open_window("Splashkit Example", 600, 400); needs to be run when you decide to open your viewable window.
  • The loop in main allows us to update the screen according to any user events, and refreshes the screen after anything is drawn on the frame.




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

    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.

    The use of Generative AI to generate code solutions 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 DPST1091. 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 DPST1091 is not permitted.

    For example, do not place your assignment in a public GitHub repository after DPST1091 is over.

    Rationale:DPST1091 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 DPST1091 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. 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 DPST1091 Paying another person to complete work. Submitting another person's work without their consent.

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

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 dp1091 ass2_cs_pet_salon cs_pet_salon.c

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 cs_pet_salon.c.

20% of the marks for this assignment will come from manual marking of the readability of the C you have written. The manual marking will involve checking your code for clarity, and readability, which includes the use of functions and efficient use of loops and if statements.

Marks for your performance will be allocated roughly according to the below scheme.

100% for Performance Completely Working Implementation, which exactly follows the spec (Stage 1, 2, 3 and 4).
85% for Performance Completely working implementation of Stage 1, 2 and 3.
65% for Performance Completely working implementation of Stage 1 and Stage 2.
35% for Performance Completely working implementation of Stage 1.

Marks for your style will be allocated roughly according to the scheme below.

Style Marking Rubric

0 1 2 3 4
Formatting (/5)
Indentation (/2) - Should use a consistent indentation scheme. Multiple instances throughout code of inconsistent/bad indentation Code is mostly correctly indented Code is consistently indented throughout the program
Whitespace (/1) - Should use consistent whitespace (for example, 3 + 3 not 3+ 3) Many whitespace errors No whitespace errors
Vertical Whitespace (/1) - Should use consistent whitespace (for example, vertical whitespace between sections of code) Code has no consideration for use of vertical whitespace Code consistently uses reasonable vertical whitespace
Line Length (/1) - Lines should be max. 80 characters long Many lines over 80 characters No lines over 80 characters
Documentation (/5)
Comments (incl. header comment) (/3) - Comments have been used throughout the code above code sections and functions to explain their purpose. A header comment (with name, zID and a program description) has been included No comments provided throughout code Few comments provided throughout code Comments are provided as needed, but some details or explanations may be missing causing the code to be difficult to follow Comments have been used throughout the code above code sections and functions to explain their purpose. A header comment (with name, zID and a program description) has been included
Function/variable/constant naming (/2) - Functions/variables/constants names all follow naming conventions in style guide and help in understanding the code Functions/variables/constants names do not follow naming conventions in style guide and help in understanding the code Functions/variables/constants names somewhat follow naming conventions in style guide and help in understanding the code Functions/variables/constants names all follow naming conventions in style guide and help in understanding the code
Organisation (/5)
Function Usage (/4) - Code has been decomposed into appropriate functions separating functionalities No functions are present, code is one main function Some functions are present, but functions are all more than 50 lines Some functions are present, and all functions are approximately 50 lines long Most code has been moved to sensible/thought out functions, but they are mostly more than 50 lines All code has been meaningfully decomposed into functions of approx 50 lines
Function Prototypes (/1) - Function Prototypes have been used to declare functions above main Functions are used but have not been prototyped All functions have a prototype above the main function or no functions are used
Elegance (/5)
Overdeep nesting (/2) - You should not have too many levels of nesting in your code (nesting which is 5 or more levels deep) Many instances of overdeep nesting <= 3 instances of overdeep nesting No instances of overdeep nesting
Code Repetition (/2) - Potential repetition of code has been dealt with via the use of functions or loops Many instances of repeated code sections <= 3 instances of repeated code sections Potential repetition of code has been dealt with via the use of functions or loops
Constant Usage (/1) - Any magic numbers are #defined None of the constants used throughout program are #defined All constants used are #defined and are used consistently in the code
Illegal elements
Illegal elements - Presence of any illegal elements indicated in the style guide CAP MARK AT 16/20

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 DPST1091 Paying another person to complete work. Submitting another person's work without their consent.

Allowed C Features

In this assignment, there are no restrictions on C Features, except for those in the style guide. 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 DPST1091. Features that the Style Guide identifies as illegal will result in a penalty during marking. You can find the style marking rubric above. Please note that this assignment must be completed using only Linked Lists . Do not use arrays in this assignment.

Due Date

This assignment is due Week 12 Friday 09:00am (2024-11-15 09:00:00). After each entire day late, the maximum mark it can achieve will be reduced by 5% (off the ceiling).
  • For instance, after 1 day past the due date, the maximum mark you can get is 95%.
  • For instance, after 2 days past the due date, the maximum mark you can get is 90%.
  • For instance, after 3 days past the due date, the maximum mark you can get is 85%.
  • No submissions will be accepted after 5 days late, unless you have special provisions in place.