CS代写 COMP2017 9017 Assignment 2

COMP2017 9017 Assignment 2
Due: 23:59 28 March 2024

This assignment is worth 10% of your final assessment

Copyright By PowCoder代写 加微信 powcoder

Task Description

Your task is to create a multi-type linked list data structure and a program that interacts with it. Your
assignment is broken into three tasks that must be completed in order.

• The first part is the basic command syntax of the linked lists, creation, removal, viewing etc.

• The second part is modifying the lists in place, through insertion and deletion of elements.

• The third part is allowing lists to refer to each other in a nested pattern.

It is also recommended to read through the specification carefully. You should ensure that you create
test cases that cover a range of possible inputs before beginning to code.1 Make sure you identify and
test for edge cases.

Implementation Details

All commands are read through standard in, and all output is given through standard out.

Part 1: Basic Commands

For Part 1, your linked lists must support elements of the following types:

Your program should take in commands from stdin that will create and manage these multi-type
linked lists. The basic commands are:

1Even if you do it on pencil and paper, work through some examples to be sure you understand.

COMP2017 9017

• NEW – create a new list

• VIEW – view a specific list by its index

• TYPE – view a specific list by its index, printing out the types of each ele-

• VIEW ALL – print the number of lists and each list in order of creation

• REMOVE – remove a list

The index for each list should be 1 higher than the last created list’s index, starting from 0 for the first
list, regardless of how many lists have been removed.

Basic Examples

In the following examples, “> ” denotes the following line as input. Your program must not print it to
stdout or read it from stdin. It is included in the formatting only as an indicator, to differentiate
the input from the output of the program.

Global input restrictions

and must be an integer, have no sign character, and
no whitespace 2.

Command keywords are delimited by exactly one (1) space character and should have no leading
and trailing whitespaces3. Be sure to replicate the formatting of these examples exactly, character by
character.

The NEW Command

This command takes in a number as input for the initial size of the list. It then reads in an initial value
for each element to initialise the list. 0 is a valid size, negative numbers are not. Lists are labelled
starting at 0 when they begin to exist, and the label always increments, even if a list is removed.
Imagine in the following section that 4 lists have already been created.

List 4: hello -> 1 -> 2 -> 3.14 -> a

Lists will only be considered as “created” after all lines of the input have been parsed and no error

2element indices in INSERT may have an optional minus character
3except when INSERT ing, where the inserted value may contain whitespace. See type requirements

Systems Programming Page 2 of 15

COMP2017 9017

The VIEW Command

This command prints out the contents of the list at the given index.

hello -> 1 -> 2 -> 3.14 -> a

The TYPE Command

This command prints out the types of each element at the given list.

string -> int -> int -> float -> char

The VIEW ALL Command

This command prints out the current set of lists in index-increasing order.

> VIEW ALL
Number of lists: 3

The REMOVE Command

This command deletes a list, and prints out the current set of lists again in index-increasing order.

> REMOVE 3
List 3 has been removed.

Number of lists: 2

Invalid Commands

A command can be identified from a line if the line strictly begins with exactly the command keyword,
and is invalid if its invalid otherwise.

If a command is invalid in some way, print INVALID COMMAND: . For exam-
ple, when there is no List 4:

Systems Programming Page 3 of 15

COMP2017 9017

> REMOVE 4
INVALID COMMAND: REMOVE

If a command cannot be identified, use INPUT. For example:

> abracadabra
INVALID COMMAND: INPUT

It is up to you to find and prepare for edge cases.

Type Rules and Exceptions

There can be some ambiguity in certain cases for what a given input’s type is. The order for type
checking is as follows:

Requirements for types are as follows:

• int can be negative, positive or zero (tests will also not exceed the maximum and minimum
value for an int type).

• float is the same except it will always have a decimal point.4

• float should also be printed to 2 decimal places, though they can be read in to any precision.

• char is any printable5 character in ascii as long as it is singular.

• string covers all other cases.

• Empty lines in list creation should be considered as string.

• string can start with leading and trailing whitespace characters.

• Lines containing one int or float can have leading and trailing whitespaces. These will be
interpreted as numbers. (Note that this is the default behaviour of scanf).

• All inputs will have a maximum total line length of 128 bytes.

4The exception being scientific notation which should also be accepted, i.e. 2e-4 = 0.0002. Note that
scanf accepts this type of input by default. Other number formats accepted by scanf may or may not be
undefined behaviour, and will be clarified in a later date.

5isprint() returns true

Systems Programming Page 4 of 15

COMP2017 9017

> baguette
List 4: 1.00 -> -> baguette -> 5

Note the empty line that was interpreted as an empty string, as well as the extra space in ” baguette”.
There will be no test cases that do not fit this description.

Note: Curly brackets {} are used in Part 3, and are considered invalid input if they appear in any form
other than specified there. 6

> baguette
INVALID COMMAND: NEW
> wordswords } words
INVALID COMMAND: NEW

Exiting the program

Upon EOF, the program should free all used dynamic memory, then exit.

Part 2: Dynamic Lists

In this part you are to implement two extra commands: INSERT and DELETE.

The INSERT Command

This command takes input of the form INSERT , and inserts
the value at the given index of the given list. It should then print out the new list in the same format
as VIEW, but with the string “List : ” before it. For example:

a -> b -> c -> d
> INSERT 1 0 Baguettes
List 1: Baguettes -> a -> b -> c -> d

6For completion of Parts 1 and 2, it is sufficient to raise an error whenever curly brackets are detected. Part
3 introduces a single exceptional use which is not an error.

Systems Programming Page 5 of 15

COMP2017 9017

Negative indices should insert from the end of the list. Indices outside the range are invalid:

a -> b -> c -> d
> INSERT 1 -1 Baguettes
List 1: a -> b -> c -> d -> Baguettes
> INSERT 1 97 Croissants
INVALID COMMAND: INSERT

The DELETE COMMAND

This command takes input of the form DELETE and removes the given
index from the list. It should then print out the new list in the same format as INSERT. The same
conditions on indices apply. For example:

a -> b -> c -> d
> DELETE 1 0
List 1: b -> c -> d
> DELETE 1 -1
List 1: b -> c
> DELETE 1 4
INVALID COMMAND: DELETE

Part 3: Nested Lists

For this section, you are to modify your previous code to accept a new type: other lists. This is to a
maximum depth of one. This means every list is either a simple list (contains only regular types), or
a nested list (contains regular types and simple lists). Nested lists cannot contain other nested lists.

Nested lists contain only references to simple list(s). Thus, changes to the simple list should also be
reflected in the nested list.

To insert a simple list into a nested list, it should be specified with curly brackets. When nested lists
are printed, they should be labelled as Nested, like so:

a -> b -> c -> d
Nested 2: first -> {List 1} -> last
> VIEW ALL
Number of lists: 2

Systems Programming Page 6 of 15

COMP2017 9017

Any command that refers to a non-existent list, or would result in any list having depth greater than 1
should give an INVALID COMMAND:

a -> b -> c -> d
List 1: first -> last
> INSERT 1 1 {0}
Nested 1: first -> {List 0} -> last
INVALID COMMAND: NEW

If all references are deleted from a nested list with DELETE, then it becomes a simple list. The TYPE
command should print reference as the type of any references to other lists.

a -> b -> c -> d
first -> {List 0} -> last
string -> reference -> string

Removal of a simple list while it is referenced by any other list should give an
INVALID COMMAND: REMOVE.

The VIEW-NESTED Command

This command can print any list, but when it prints a nested list, it will also print its sub-lists, contained
in curly brackets. Like so:

a -> b -> c -> d
first -> {List 1} -> last
> VIEW-NESTED 1
a -> b -> c -> d
> VIEW-NESTED 2
first -> {a -> b -> c -> d} -> last

Systems Programming Page 7 of 15

COMP2017 9017

Restrictions

To successfully complete this assignment you must:

• Use dynamic memory.

• Use linked list structures,7 they must be your own implementation.8

• Store values of the linked list as their actual types such as int or string.

• Free all dynamic memory that is used.

• NOT use any external libraries, other than those in glibc.

• Other restricted functions may come at a later date.

Any submission breaking these restrictions will receive a deduction of up to 5 marks per breach.

All texts within your submission that may be read by a reviewer (marker), including code comments,
git commit messages, README files, and so on, should be written in English. Any readable text that
is not written in English will receive a deduction of 1 mark per line.

Working on Your Assignment

You are encouraged to submit your assignment on Ed while you are in the process of completing it.
By submitting you will obtain some feedback of your progress on the sample test cases provided.

If you have any questions about C functions, then refer to the corresponding man pages. You can and
should ask questions about this assignment on Ed. As with any assignment, make sure that your work
is your own, and that you do not share your code or solutions with other students.

Getting Started

The most important factor for success is your choice of data structures. We recommend:

1. Read the specification and write test cases.

2. Design your data structures.

3. Part 1 Commands

4. Part 2 Commands

5. Part 3 Commands
7There are no requirements on what kind of data structure is used to keep track of all the created lists, as

long as it is dynamic and the lists themselves are linked lists of any kind.
8This means you mustn’t cite or borrow code from any other source. Design and implement the structure

Systems Programming Page 8 of 15

COMP2017 9017

Writing even a few simple test cases of your own will ensure you understand the details of what
you’ve been asked to do. Even on pen and paper, this is incredibly beneficial.

Data structure design will have the largest impact on the quality of your code (both in terms of style
and correctness). The scaffold has a few suggestions on the function prototypes you should use, but
does not cover every instance. Be considerate of how your linked-list will function.

Debugging and Avoiding Leaks

It is recommended that you use tools such as gdb, valgrind and ASAN
(the -fsanitize=address,leaks compilation flags).

These will assist in finding basic errors (gdb) and monitoring memory leaks (valgrind, ASAN).
However, they cannot automatically prevent memory errors and leaks. You should be conscious of
where leaks may occur and verify them yourself.9

Note: Mac users may need to use a full virtual machine (VM) to make use of these tools. We have had
reports of both valgrind and ASAN being unusable on Macs. Please refer to Ed for more details.

Compilation and Testing

Your program should be compiled by the default rule, which is the first defined rule of the Makefile.
You should name this make rule build. After compilation, your program should be a single binary
file called mtll which is used to run your program.

# compile the program
# alternatively
# make build

# run the program

You should implement your program in multiple C source and header files. This is required for full
style marks.10 They must all compile together into one single binary when the program is built.

You should also do your own testing. If you need to compile/create your tests before running them,
please implement a make rule called tests for this and then a separate one for running your tests.
Please also store your tests in the tests directory provided.

After the assignment is released, a small number of test files will be made available. Correctness tests
will be provided to ensure that your code can execute fundamental examples. These tests will not be
the complete set of tests run against your code.

Any attempt to deceive the marking system (such as hard coding test cases) will receive a zero.

9This is helped by having a plan for what data structures you will use, and how your code will manage them.
10It is recommended to break up your code into suitable sections, i.e. the main source file handles input, a

separate source file for list management functions, etc.

Systems Programming Page 9 of 15

COMP2017 9017

# compile the tests if necessary
make tests
# run the tests
make run_tests

Submission

Submissions for this assignment will be through git.

The general process of writing and submitting is the same:

git add
git commit -m “fix memory leak in function x”

If you have any questions about git usage, feel free to check the Git Lesson, the relevant manual
pages, or ask on Ed.

Do NOT push binaries, including executables and object files. Either add your source files manually,
or create a .gitignore file that includes the names of all your binaries.

None of your git commits should contain a binary file. Any submission breaking this restriction will
receive a deduction of 1 mark per commit.

Marking Details

The assignment is worth 10% of your final grade. This is marked out of 20, and breaks down as

Marks Item Notes
3/20 Code Style Manual marking
2/20 Test Case Coverage Manual marking
6/20 Part 1 Correctness Automatic tests
6/20 Part 2 Correctness Automatic tests
3/20 Part 3 Correctness Automatic tests

For style, refer to the style guide on ed: https://edstem.org/au/courses/14786/lessons/
49533/slides/334765. You will also be marked based on the modularity and organisation of
your code. For full marks, code should be organised in multiple source files, and use modular, task-
specific functions. Organised data structures are essential here.

The scaffold provides some suggestions on what this looks like, but more will be necessary.

For test case coverage: This first mark is for coverage of basic command syntax. Full marks will be
awarded for consideration of at least 3 edge cases. These may be for sections of the assignment you
have not completed.11

11Feel free to look for edge cases in Part 3 even if you do not manage to code it.

Systems Programming Page 10 of 15

https://edstem.org/au/courses/14786/lessons/49533/slides/334765
https://edstem.org/au/courses/14786/lessons/49533/slides/334765

COMP2017 9017

The below table gives an indication of what is expected. Note this is not a set marking scheme, more
a guideline. Refer to the above table for clearer ideas.

Expected Award Level of Completion
Pass Good code style, good test coverage and completion of Part 1.

(Style misses one or two things: not modular, not multiple source files, etc.)
Credit Excellent style and tests, most of Part 2.

Good style and tests, completion of Part 2.
Distinction Excellent style and tests, completion of Part 2

High Distinction Excellent style and tests, completion of Part 3

Further Examples

All Basic Commands:

List 0: hello -> 2 -> 1
List 1: 3.14 -> world -> a
> VIEW ALL
Number of lists: 2
3.14 -> world -> a
> REMOVE 0
List 0 has been removed.

Number of lists: 1
List 2: foo -> bar -> 5
> VIEW ALL
Number of lists: 2

Systems Programming Page 11 of 15

COMP2017 9017

Insert and Delete Commands:

List 0: hello -> 6 -> 0.02
> DELETE 0 2
List 0: hello -> 6
> INSERT 0 -2 goodbye
List 0: hello -> goodbye -> 6
> DELETE 0 -1
List 0: hello -> goodbye
> DELETE 0 -1
List 0: hello
> DELETE 0 -1
> REMOVE 0
List 0 has been removed.

Number of lists: 0

Note the leading space in ’ goodbye’.

Nested Lists

List 0: this -> is -> simple
> is-nested
Nested 1: this -> is-nested -> {List 0} -> 4.0 h
> VIEW-NESTED 1
this -> is-nested -> {this -> is -> simple} -> 4.0 h
List 2: other
> INSERT 0 2 {2}
INVALID COMMAND: INSERT
> REMOVE 0

Systems Programming Page 12 of 15

COMP2017 9017

INVALID COMMAND: REMOVE
> DELETE 1 2
List 1: this -> is-nested -> 4.0 h
> INSERT 0 2 {1}
Nested 0: this -> is -> {List 1} -> simple
> INSERT 0 0 {1}
Nested 0: {List 1} -> this -> is -> {List 1} -> simple
> DELETE 0 0
Nested 0: this -> is -> {List 1} -> simple
> VIEW-NESTED 0
this -> is -> {this -> is-nested -> 4.0 h} -> simple

Note “4.0 h” is a string, not a float.

Systems Programming Page 13 of 15

COMP2017 9017

Academic Declaration

By submitting this assignment you declare the following: I declare that I have read and understood
the University of Plagiarism: Coursework Policy and Procedure, and except where
specifically acknowledged, the work contained in this assignment/project is my own work, and has
not been copied from other sources or been previously submitted for award or assessment.

I understand that failure to comply with the Student Plagiarism: Coursework Policy and Procedure
can lead to severe penalties as outlined under Chapter 8 of the University of -Law 1999 (as
amended). These penalties may be imposed in cases where any significant portion of my submitted
work has been copied without proper acknowledgment from other sources, including published works,
the Internet, existing programs, the work of other students, or work previously submitted for other
awards or assessments.

I realise that I may be asked to identify those portions of the work contributed by me and required to
demonstrate my knowledge of the relevant material by answering oral questions or by undertaking
supplementary work, either written or in the laboratory, in order to arrive at the final assessment

I acknowledge that the School of Computer Science, in assessing this assignment, may reproduce
it entirely, may provide a copy to another member of faculty, and/or communicate a copy of this
assignment to a plagiarism checking service or in-house computer program, and that a copy of the
assignment may be maintained by the service or the School of Computer Science for the purpose of
future plagiarism checking.

Systems Programming Page 14 of 15

COMP2017 9017

Any changes made to this document will be updated here.
23/03/2024-09:45 – further clarified allowed whitespace and input for elements and index. Added
placeholder for further type parsing.
22/03/2024-13:06 – clarified list types, again
19/03/2024-23:00 – New restriction and deduction rules will apply to non-English readable texts.
18/03/2024-20:45 – Made NEW, VIEW, and TYPE examples share the same context. Clarify list cre-
ation time, clarify invalid input conditions, ad

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com