1. Homepage
  2. Programming
  3. COMP1511 Programming Fundamentals - Assignment 2 - 1511 Climb

COMP1511 Programming Fundamentals - Assignment 2 - 1511 Climb

Engage in a Conversation
COMP1511Programming Fundamentals1511 ClimbC

Assignment 2 - 1511 Climb

Overview

Welcome to 1511 Climb! CourseNana.COM

In order to feed a growing climbing obsession, COMP1511 staff have decided to create a system to keep track of all the climbing routes they have attempted. The desired system is inspired by the existing website The Crag, which you can take a look at if you want to see where some of the ideas have come from :) CourseNana.COM

Assignment Structure

This assignment will test your ability to create, use, manipulate and solve problems using linked lists. To do this, you'll be implementing a climbing logbook with a linked list of climbing routes. CourseNana.COM

The following struct definition for the logbook is provided for you in the starter code: CourseNana.COM

CourseNana.COM

struct logbook {
    struct route *routes;
};

CourseNana.COM

struct logbook CourseNana.COM

  • Purpose:
    • Represents the climbing logbook, which will contain a linked list of climbing routes.
  • Contains:
    • struct route *routes
      • struct route pointer to the head of the linked list of climbing routes.

You may make other modifications to this struct, but you are not required to. CourseNana.COM

The following struct definition for a route is also provided for you. CourseNana.COM

CourseNana.COM

struct route {
    // The name of the climbing route
    char name[MAX_STR_LEN];
    // The difficulty of the route
    int difficulty;
    // The length of the route in metres
    int length;
    
    struct route *next;
};

CourseNana.COM

struct route CourseNana.COM

  • Purpose:
    • Represents a single climbing route being described in the logbook.
    • Stores details of a climbing route.
  • Contains:
    • char name[MAX_ROUTE_NAME]
      • The route's unique name, in the form of a null-terminated string of length 20.
    • int difficulty
      • The difficulty of the route.
      • Should always be between 1 and 39.
    • int length
      • The length of the route in metres.
      • Should always be between 1 and 60 metres.
    • struct route *next
      • The pointer to the next route in the logbook.

You may modify this struct if you wish, but you are not required to. CourseNana.COM

From Stage 3 onwards, you will need to use an additional struct type struct attempt and enum type enum attempt_type. This is further explained in Stage 3, and you won't need to worry about it until then. CourseNana.COM

How To Get Started

There are a few steps to getting started with 1511 Climb. CourseNana.COM

  1. Create a new folder for your assignment work and move into it.
mkdir ass2
cd ass2
  1. Download the starter code (cs_climb.c) here or use this command on your CSE account to copy the file into your current directory:
1511 fetch-activity cs_climb
  1. Run 1511 autotest cs_climb to make sure you have correctly downloaded the file.
1511 autotest cs_climb
  1. Read through Stage 1. CourseNana.COM

  2. Think about your solution, draw some diagrams to help you get started. CourseNana.COM

  3. Start coding! CourseNana.COM

Reference Implementation

To help you understand the proper behaviour of 1511 Climb, 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. CourseNana.COM

To run the reference implementation, use the following command: CourseNana.COM

 1511 cs_climb

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. CourseNana.COM

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

It also contains the completed create_logbook function, as well as an incomplete function implementation for create_route. You will need to complete the create_route function in Stage 1.1. CourseNana.COM

Finally, the main function contains some printf messages which run when the program starts and ends. CourseNana.COM

On program start: CourseNana.COM

Welcome to 1511 Climb!
Log all your climbing adventures here!

On program end: CourseNana.COM

Goodbye

Commands

Here is the list of commands to be implemented in this assignment: CourseNana.COM

StageCommandExampleMeaning
1.2??Display help message
1.3rr Pharoah 15 18Append route
1.4ppprint routes
2.1ff 15 18filter routes by difficulty
2.2ii Joseph 13 24 Eternityinsert route
2.3ll Joseph Pharoah 7Change route lengths
2.4ss Joseph Phantomswap routes
3.1aa Rory success 2 PharoahAdd attempt
3.2PPPrint logbook
3.3RR EternityRemove route
3.4DD RoryDelete climber attempts
3.5dd Jake Tammyduplicate attempts
4.1cc Joseph Pharoahcombine routes
4.2oo Eternityorder attempts by skill/alphabetical

Allowed C Features

In this assignment, you cannot use arrays, other than char arrays, and cannot use the features explicitly banned in the Style Guide. CourseNana.COM

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: CourseNana.COM

  • intchar, and double variables.
  • Enums.
  • Structs.
  • If statements.
  • While and/or for loops.
  • Your own functions.
  • Pointers.
  • char arrays/strings (you are not allowed to use arrays that are not char arrays).
  • Linked lists.
  • Standard libraries: stdio.hstdlib.h, and string.h.
  • 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). CourseNana.COM

If you choose to disregard this advice, you must still follow the Style Guide. You also may be unable to get help from course staff if you use features not taught in COMP1511. CourseNana.COM

Features that the Style Guide strongly discourages or bans will be penalised during marking. CourseNana.COM

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. CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Stage 1

In Stage 1 of this assignment, you will be initialising the climbing logbook, implementing the command loop, and implementing commands for adding climbing routes. This will include: CourseNana.COM

  • Implementing the create_route function.
  • Implementing the command loop that will scan in commands until CTRL+D.
  • Adding climbing routes to the end of the logbook.
  • Printing out all the climbing routes in the logbook.
  • Checking that each climbing route is valid.

By the end of this stage, your program should be able to create a logbook with a linked list of routes that looks like this: CourseNana.COM

CourseNana.COM

diagram of linked list insertion positions
Stage 1: A logbook with a linked list of routes

CourseNana.COM

Stage 1.1 - Creating a route

For Stage 1.1, you will be implementing a function to create a climbing route. It's very helpful to have functions like this that handle mallocing, initialising and returning a single node of a linked list, as they make your code more readable and reduce the chance of bugs popping up later on. CourseNana.COM

In the starter code, you'll find the unimplemented create_route function: CourseNana.COM

CourseNana.COM

struct route *create_route(
    char name[MAX_ROUTE_NAME], 
    int difficulty, 
    int length
) {
    // STAGE 1.1
    // TODO: malloc, initialise and return a new route

    // hint: you will have to replace NULL in this return statement.
    return NULL;
}

CourseNana.COM

Your task for Stage 1.1 is to complete this function so that it: CourseNana.COM

  1. malloc's a new struct route.
  2. Copies the name , difficulty and length into the corresponding struct fields.
  3. Initialises all other fields to some reasonable value.
  4. Returns the newly created struct route.

Assumptions

  • You will never be given a route name that is 20 characters or longer.
  • No error handling is required for this stage.

Testing

There are no autotests for Stage 1.1. CourseNana.COM

Instead, you may want to double check your work by compiling your code using dcc and make sure there are no warnings or errors. CourseNana.COM

You could also write some temporary testing code to check that your create_route function works properly when it runs. CourseNana.COM

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

CourseNana.COM

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

// Create a struct route with
//  name:   Eternity
//  difficulty:  18
//  length: 22
struct route *test_route = create_route("Eternity", 18, 22);

// Print out all it's fields.
printf("name: %s\n", test_route->name);
printf("difficulty: %d\n", test_route->difficulty);
printf("length: %d\n", test_route->length);
if (test_route->next == NULL) {
    printf("next field: (nil)\n");
}

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

CourseNana.COM

This code just calls create_route to malloc and initialise a struct route, and then prints out all of its fields. CourseNana.COM

If you run it, it should print out something like: CourseNana.COM

name: Eternity
difficulty: 18
length: 22
next field: (nil)

Stage 1.2 - The command loop

In this stage you will implement the command loop that will allow your program to continue scanning commands and performing different operations with the logbook. CourseNana.COM

From this stage onwards, your program should run in a loop so you can continuously scan in and execute commands until the user presses CTRL+D. CourseNana.COM

You should implement this command loop between the welcome and goodbye messages, so that your program runs in the following order: CourseNana.COM

  1. First, print out the welcome message (the printf statement is included in the starter code). CourseNana.COM

  2. Then run in a loop until CTRL+D: CourseNana.COM

    1. Print out the prompt Enter command:;
    2. Scan in a command character;
    3. Scan in any arguments following the command character and execute the command.
  3. After CTRL+D is pressed, the goodbye message should be printed (the printf statement is included in the starter code), and then your program should end. CourseNana.COM

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. CourseNana.COM

The first command you have to implement is the Help command, which is described below. CourseNana.COM

Command: Help

?

Description

When the character '?' is entered into your program, it should run the Help command. This command doesn't read in any arguments following the initial command and should display a message which lists the different commands and their arguments. CourseNana.COM

The purpose of this command is to allow anyone using our program to easily look up the different commands. CourseNana.COM

A helper function: void print_usage(void) has been provided to help you print and format this message.
You can find more information about it here: Provided helper function. CourseNana.COM

This is what it should look like when you run the Help command: CourseNana.COM

CourseNana.COM

CourseNana.COM

Because of the command loop, after the Help command has finished running, your program should print out CourseNana.COM

Enter command: 

and then wait for the user to either enter another command, or press CTRL+D to end the program. CourseNana.COM

CourseNana.COM

Provided helper functions

A procedure,print_usage, has been provided for you in the starter code which prints out the help message. CourseNana.COM

So all you need to do for this command is call the print_usage procedure when the ? character is scanned in. CourseNana.COM

Assumptions

  • All commands will begin with a single unique character.
    Some will be followed by a number of arguments, depending on the command.
  • You can assume that commands will always be given the correct number of arguments, so you do NOT need to check for this.
  • You do not need to handle unknown commands.
  • No error handling is required for this stage.

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Stage 1.3 - Appending routes

Now that you have the command loop running, you can start adding climbing routes to the logbook! CourseNana.COM

Your struct logbook contains a struct route pointer called routes. This will be the pointer to the start of a linked list of struct routes, which will contain the information on the climbing routes you add to the logbook. At first, this linked list will be empty, so the routes pointer will just be pointing to NULL. CourseNana.COM

In this stage you will be adding routes to the logbook by appending them to the end of the routes list. CourseNana.COM

Before you add any routes to the logbook, your struct logbook should look something like this: CourseNana.COM

CourseNana.COM

diagram of linked list insertion positions
An empty logbook

CourseNana.COM

The first command you be implementing will be the command to append a route to the end of the routes list inside your struct logbook. CourseNana.COM

Command: Append route to end of logbook

r [name] [difficulty] [length]

Description

The r command takes in 3 arguments: name (a string), difficulty (an integer) and length (an integer). CourseNana.COM

A helper function has been provided to help you scan in name: CourseNana.COM

  • void scan_string(char string[MAX_STR_LEN])

You can find more about this function here: Provided helper functions. CourseNana.COM

When the r command is entered, your program should create a new route containing the namedifficulty and length, then append it to the end of the routes list in the logbook. CourseNana.COM

It should then print out a message to confirm that the route was added successfully:
Route '[name]' added successfully!
(You should replace [name] with the name that you scanned in). CourseNana.COM

For example, if you start the program and then use the r command once, it would look like: CourseNana.COM

Welcome to 1511 Climb!
Log all of your climbing adventures here!
Enter command: r Eternity 18 22
Route 'Eternity' added successfully!

Your logbook should now look like this: CourseNana.COM

CourseNana.COM

diagram of linked list insertion positions
A logbook with one route

CourseNana.COM

If you then ran the r command again: CourseNana.COM

Enter command: r Pharoah 15 18
Route 'Pharoah' added successfully!

Your logbook should now have 2 struct routes in its routes list: CourseNana.COM

CourseNana.COM

diagram of linked list insertion positions
A logbook with two route

CourseNana.COM

Because of the command loop, after the Append Route command has finished running, your program should print out: CourseNana.COM

Enter command: 

and then wait for the user to either enter another command, or press CTRL+D to end the program. CourseNana.COM

CourseNana.COM

Provided helper functions

One helper function has been provided for this stage: CourseNana.COM

  • void scan_string(char string[MAX_STR_LEN]):
    • Scans a string input into char string[MAX_STR_LEN].

Assumptions

  • All commands will begin with a single unique character.
    Some will be followed by a number of arguments, depending on the command.
  • You can assume that commands will always be given the correct number of arguments, so you do NOT need to check for this.
  • You do not need to handle unknown commands.
  • You will never be given a route name that is 20 characters or longer.
  • No error handling is required for this stage (this will be part of Stage 1.5).

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Stage 1.4 Print Routes

Now that you have added climbing routes to your logbook, it would be great for us to be able to see them all! CourseNana.COM

The Print Routes command will allow to display the information about each route that has been added to your logbook. CourseNana.COM

Command: Print Routes

p

Description

The p command takes no arguments. CourseNana.COM

When the p command is run, your program should print out all of the routes in the logbook in order from head to tail. Each route should be printed with a number showing its position in the logbook (the first route appended will be number 1, the second will be number 2, and so on). CourseNana.COM

A function has been provided to format and print a single route: CourseNana.COM

  • void print_one_route(int position, struct route *route)

You can find more about this function here: Provided helper functions. CourseNana.COM

If there are no routes in the logbook, the following message should be printed instead: There are no routes in this logbook! CourseNana.COM

CourseNana.COM

Provided helper functions

One helper function has been provided for this stage: CourseNana.COM

  • void print_one_route(int position, struct route *route)
    • Takes the position of a route and a pointer to that struct route and prints it in the correct format

Errors/Assumptions: None

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Stage 1.5 - Handling Errors

Once you've reached this stage, you should be able to add climbing routes to your logbook and display them. Good job! CourseNana.COM

However, the people using your logbook can still make mistakes! What if someone were to input a command like r Phantom 50 0: CourseNana.COM

Enter command: r Phantom 50 0
Route added successfully!
Enter command: p
/--------- \/ ---------\
|       Route #1       |
|       Phantom        |
|    Difficulty: 50    |
|    Length (m):  0    |
\--------- || ---------/

There's a couple problems with this route.
A difficulty grade of 50 is far too difficult for any regular human to climb - the climbing grade system only goes from 1 to 39!
And how can you have a route that is 0m long? You will only be adding routes that are 1m to 60m in length.
There's also another issue at the moment - you can add many routes with the same name to the logbook, which would be horribly confusing and could cause someone to mistakenly climb the wrong route! You will need to make sure that each route name in your logbook is unique. CourseNana.COM

In this stage, you'll be modifying the code you wrote in Stage 1.3, so that only valid routes are added to your logbook. CourseNana.COM

CourseNana.COM

Error conditions

When running the r command, you scanned in the namedifficulty and length of the route to be added to the logbook. CourseNana.COM

Now, if any one of the following conditions are met, then you should not append the new route to the end of the routes list. You should check for errors in the below order, and only print out the error message for the first error found: CourseNana.COM

  • If difficulty <= 0 or difficulty > 39, the following error should be printed:
    ERROR: Route difficulty must be between 1 and 39
  • If length <= 0 or length > 60, the following error should be printed:
    ERROR: Route length must be between 1m and 60m
  • If there is already a route in the logbook with this name, the following error should be printed:
    ERROR: A route with the name '[name]' already exists in this logbook

Clarifications

  • If more than one error occurs, only the first error should be addressed by printing an error message, i.e. the first type of error that is specified in the Error conditions list. This is the same for all future commands.

Examples

CourseNana.COM

CourseNana.COM

CourseNana.COM

CourseNana.COM

Testing and Submission

Remember to do your own testing CourseNana.COM

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

  • Run 1511 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?
1511 style cs_climb.c
1511 autotest-stage 01 cs_climb
give cs1511 ass2_cs_climb cs_climb.c

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
COMP1511代写,Programming Fundamentals代写,1511 Climb代写,C代写,COMP1511代编,Programming Fundamentals代编,1511 Climb代编,C代编,COMP1511代考,Programming Fundamentals代考,1511 Climb代考,C代考,COMP1511help,Programming Fundamentalshelp,1511 Climbhelp,Chelp,COMP1511作业代写,Programming Fundamentals作业代写,1511 Climb作业代写,C作业代写,COMP1511编程代写,Programming Fundamentals编程代写,1511 Climb编程代写,C编程代写,COMP1511programming help,Programming Fundamentalsprogramming help,1511 Climbprogramming help,Cprogramming help,COMP1511assignment help,Programming Fundamentalsassignment help,1511 Climbassignment help,Cassignment help,COMP1511solution,Programming Fundamentalssolution,1511 Climbsolution,Csolution,