1. Homepage
  2. Coding
  3. DPST1091/CPTG1391 Programming Fundamentals! - Assignment 2 - CS Pet Salon

DPST1091/CPTG1391 Programming Fundamentals! - Assignment 2 - CS Pet Salon

Get in Touch with Our Experts
UNSWDPST1091CPTG1391Programming FundamentalsCS Pet Salon

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

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! Assignment Writing Service

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. Assignment Writing Service

struct salon Assignment Writing Service

  • 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 Assignment Writing Service

  • 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 CATDOGRABBIT 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 Assignment Writing Service

  • 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. Assignment Writing Service

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. Assignment Writing Service

To run the reference implementation, use the following command: Assignment Writing Service

 1091 cs_pet_salon

How to get started

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

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

    Download cs_pet_salon.c here Assignment Writing Service

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

    1091 fetch-activity cs_pet_salon
    

    Assignment Writing Service

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

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. Assignment Writing Service

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. Assignment Writing Service

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

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. Assignment Writing Service

These printf messages are: Assignment Writing Service

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. Assignment Writing Service

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: Assignment Writing Service

  • 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). Assignment Writing Service

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). Assignment Writing Service

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

FAQ

Assignment Writing Service

Assignment Writing Service

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. Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

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. Assignment Writing Service

Specifically, this will include: Assignment Writing Service

  • 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: Assignment Writing Service

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. Assignment Writing Service

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

Assignment Writing Service

// 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;
}

Assignment Writing Service

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

  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: Assignment Writing Service

  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. Assignment Writing Service

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. Assignment Writing Service

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. Assignment Writing Service

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

Assignment Writing Service

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

Assignment Writing Service

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

If you run it, it should print out something like: Assignment Writing Service

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. Assignment Writing Service

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. Assignment Writing Service

On each iteration of the loop, your program should: Assignment Writing Service

  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. Assignment Writing Service

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

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. Assignment Writing Service

This salon will start out empty - with no rooms. Assignment Writing Service

It should look something like this: Assignment Writing Service

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. Assignment Writing Service

Command: Add room

a [room_name] [pet_type]

Description

The a command takes in 2 arguments: Assignment Writing Service

  • 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: Assignment Writing Service

  • 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. Assignment Writing Service

When the a command is entered, your program should create a new room containing the room_namepet_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). Assignment Writing Service

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

"Room: '[room_name]' added!\n" Assignment Writing Service

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

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

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

Our linked list should now look like this: Assignment Writing Service

Assignment Writing Service

A salon with one room.

Assignment Writing Service

If we then run the a command again: Assignment Writing Service

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

then our linked list should now look like: Assignment Writing Service

Assignment Writing Service

A salon with two rooms.

Assignment Writing Service

Assignment Writing Service

Provided helper functions

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

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

enum pet_type scan_pet_type(): Assignment Writing Service

  • 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. Assignment Writing Service

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

Assignment Writing Service

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

Assignment Writing Service

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 stringenum pet_type
"cat"CAT
"dog"DOG
"rabbit"RABBIT
"parrot"PARROT
any invalid stringINVALID_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. Assignment Writing Service

Examples

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Stage 1.3 - Printing rooms in the salon

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

Command: Print rooms

p

Description

The p command takes no arguments. Assignment Writing Service

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

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: Assignment Writing Service

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

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

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

There are no pet rooms in this salon! Assignment Writing Service

Provided helper functions

One helper function has been provided for this stage: Assignment Writing Service

void print_one_room(int position, struct pet_room *room) Assignment Writing Service

  • 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. Assignment Writing Service

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. Assignment Writing Service

Error Conditions

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

Examples

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

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! Assignment Writing Service

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

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. Assignment Writing Service

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. Assignment Writing Service

Error Conditions

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

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: Assignment Writing Service

  • 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! Assignment Writing Service

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

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

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. Assignment Writing Service

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. Assignment Writing Service

It should create a new struct pet_room containing room_namepet_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. Assignment Writing Service

For example if we ran the following commands: Assignment Writing Service

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

Then used our new command: Assignment Writing Service

  • 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: Assignment Writing Service

Room: '[room_name]' inserted! Assignment Writing Service

Provided helper functions

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

Error Conditions

Just like command aadd 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. Assignment Writing Service

Examples

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Testing and Submission

Remember to do your own testing Assignment Writing Service

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

  • 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

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

Assignment Writing Service

联系辅导老师!
私密保护
WeChat 微信
UNSW代写,DPST1091代写,CPTG1391代写,Programming Fundamentals代写,CS Pet Salon代写,UNSW代编,DPST1091代编,CPTG1391代编,Programming Fundamentals代编,CS Pet Salon代编,UNSW代考,DPST1091代考,CPTG1391代考,Programming Fundamentals代考,CS Pet Salon代考,UNSW代做,DPST1091代做,CPTG1391代做,Programming Fundamentals代做,CS Pet Salon代做,UNSWhelp,DPST1091help,CPTG1391help,Programming Fundamentalshelp,CS Pet Salonhelp,UNSW作业代写,DPST1091作业代写,CPTG1391作业代写,Programming Fundamentals作业代写,CS Pet Salon作业代写,UNSW编程代写,DPST1091编程代写,CPTG1391编程代写,Programming Fundamentals编程代写,CS Pet Salon编程代写,UNSW作业答案,DPST1091作业答案,CPTG1391作业答案,Programming Fundamentals作业答案,CS Pet Salon作业答案,