You are on page 1of 20

FinalExam

ExamFormat
MultipleChoice:10marks
ShortAnswer:45marks
ProgrammingQuestions:45marks
Pastpapersandpastsampleexams

ExamTipsandFeedbackfromPractests
Forthefinalexamyoumustbefamiliarwiththeassignment2specandbe
abletostateexactlywhichverticesadetectivewouldvisit,givenaparticular
mapifthedetectivewasfollowingaparticularstrategyetc.
Forprogrammingquestions:
Donotchangethestructswegiveyouunlessitsaysyoucaninthe
instructions
Donotfreethingswehavepassedintoyourfunctionsunlessittells
youto
Youwillnotgetmanymarksforcodethatdoesnotcompile.You
willmostlikelyget0.
Ifyouhavetimegobackandmakeupyourownteststothoroughly
testyourfunctionsyouwillbegiventhetestcodeinthefinalexam
sothiswillhelp.
Inthepracquiz2youhadtodiscusshowyoucoulddifferentiate
betweenparticularsortingalgorithms.
Youcan'tjustsaysomethinggenerallikeIwouldtimehowlong
differentdatasetstooktorunonthem.Whatdata?Whatdoesthat
showus?Bespecific.Forexample:ordereddatasetsofincreasing
size.Andthenyoumustexplainhowthathelpsusdifferentiate
betweenthespecificsortsinthequestion.

Donotsaythingslikemergesortisfasterorselectionsortisslower.
Usetheexacttimecomplexities.ForexampleBubblesortwithearly
exitisadaptiveandhasatimecomplexityofO(n)onordereddata,
whereasquicksorthasatimecomplexityofO(n^2)forordereddata
etc.

ExamContent
Notintheexam
Makefiles
ThingsyouwillNOThavetocodeintheexam
Note:thesearethingsyouneedtounderstand,youmayhavetotrace
throughorunderstandthetimecomplexityof,knowwhentouseetcbutwill
notbeaskedtowritethecodefor.Youshouldunderstandhowthecode
worksthoughtothoroughlyunderstandtheconcepts.Youcouldbegiven
thecodeforitandaskedtouseitforagivenproblem.
Shellsort
Splaytrees
Kruskal'salgorithm

Practest2
ExamFormat
1and1/2hours
4ProgrammingQuestionsworth10markseach.2Shortanswer
questionsworth5markseach

ExamContent
Contentuptoandincludingweek6lectures.
Possibleprogrammingquestions

programmingquestion/sonlinkedlists/sortinglinkedlists
programmingquestion/sonabinarysearchtrees
programmingquestion/songraphs
Shortanswerquestions
sorting
heaps

Practest1
ExamFormat
1and1/2hours
5ProgrammingQuestionsofequalweight

ExamContent
Thingsintheexam
programmingquestionsonlinkedlists
programmingquestionsonabinarysearchtrees

ExamInstructionsforPracTest1
Thepracexamconsistsoffivequestionsandyouhave1hourand30
minutestosolvethequestions.Eachquestionisworth10marks.
Asalways,itisagoodideatostartwiththesimplestquestionbemindful
ofthetime,ifyougetstuck,trytomovetothenextquestionandcomeback
totheproblemlater.
Thesubmissioninstructionsaredetailedinthefileforeachquestion.When
submittingyourprogram,thesystemwillrunacoupleofsimpletests.The
testcodeisnotavailable,butifatestfails,youcanusegdb,setabreak
pointatthefunctionyouimplemented,andstepthroughtheexecutiontosee
wherethingsaregoingwrong.

Eachquestionisdescribedinthecorresponding.cfile

ExamTipsforPracTest1
Donotmodifythe.hfiles.
Youmayalwayswriteadditionalstatichelperfunctionsinyourcfile.
Donotchangethestructswegiveyouunlessitsaysyoucaninthe
instructions
Donotfreethingswehavepassedintoyourfunctionsunlessittells
youto
Youwillnotgetmanymarksforcodethatdoesnotcompile
Youwillbegivena.ofilefortheteststhatwerunforsubmission.
Youwillnothaveaccesstothe.ctestfiles.Ifyouhavetimemakeup
yourownteststothoroughlytestyourfunctionsaswetestthings
morethoroughlywhenwemarkthem.

Resources
DuringtheexamyouwillhaveaccesstothefollowingReferenceCard(pdf)
Assignment 1 (COMP1927, 15x1): Textbuffers
Due: Monday 23:59:59 22nd December 2014
Your task is to implement an abstract textbuffer data type that meets the given
interface. In addition, you will have to write wrapper code to test your
implementation. Ensure that you also test for boundary conditions and for
memory management bugs.
You will submit the C code implementing the textbuffer ADT and your testing
code. Click here for the interface specification.
There is also a FAQ (frequenlty asked questions page) FAQ
Marking
The assignment is worth 10 marks. The marks breakdown is as follows:
Component
Marks
Autotesting of functionality

Testing Code

Subjective evaluation of style


Style

Style marks include marks for choosing an appropriate representation for your
ADT and for efficiency of the algorithms you choose. For example, you will
lose marks if your implementation of a function has work complexity of O(n^2)
when there is a solution with O(n) or O(n * log n).
Submission deadline
Unless otherwise stated if you wish to submit an assignment late, you may do
so, but a late penalty reducing the maximum available mark applies to every
late assignment. The maximum available mark is reduced by 10% each day it
is late and can be submitted a maximum of 5 days late. Assignment
extensions are only awarded for serious and unforeseeable events. Having
the flu for a few days, deleting your assignment by mistake, going on holiday,
work commitments, etc do not qualify. Therefore aim to complete your
assignments well before the due date in case of last minute illness, and make
regular backups of your work.
Submission details
To submit the assignment execute the following command on a CSE machine:
1927classrun15x1giveassn1textbuffer.c
testTextBuffer.c
You can check you submission with
1927classruncheck
The system permits you to submit multiple versions of your code. We will
grade the last submission. Please already submit partial solutions and submit
early. The system may be heavily loaded close to the deadline. We will not
grant special considerations for late submissions due to delays of
submissions close to the deadline.
Plagiarism
This is an individual assignment. Each student will have to develop their own
solution without help from other people. In particular, it is not permitted to
exchange code or pseudocode. You are not allowed to use code developed
by persons other than yourself. If you have questions about the assignment,
ask your tutor Before submitting any work you should read and understand
the following very useful guide by the Learning Centre How Not To Plagiarise.
All work submitted for assessment must be entirely your own work. We regard
unacknowledged copying of material, in whole or part, as an extremely
serious offence. For further information, see the Course Information.
Modifications and Clarifications
For the least turn paths for stage 3:
If there are 2 paths that would take equal turns and would result in the
agent having the same resulting stamina, either path is valid. (We will
not autotest this situation).

In Graph.h there's a function prototype for an edges function but it


hasn't been included in the .c file. This function needs to be written and
have assert based tests. Sorry for any confusion.

Also for the unit tests you hand in, we only want you using functions
from the original Graph.h, so it can compile with our version of
Graph.h.
The edges in the edges function should be in ascending order and not
contain duplicates.
Also you do not have to write unit tests for getVertexLabel as in the
original Graph.h there are no functions to actually set this information.
Assignment 2
Due: 23:59:59 Wednesday 11th February 2015
ASSIGNMENTS can not be submitted at all after Fri February 13th
2015 23:59:59
Marks: 13
Learning Objectives

Practise implementing graph ADTs

Practise problem solving using graph ADTs

Background
In this assignment you will control 4 detectives as they travel through a
network of cities trying to catch a thief. The aim of the detectives is for one of
the 4 detectives to catch the thief before he/she escapes to the getaway city
and before the time runs out. The aim of the thief is to reach the getaway
destination before time runs out and before being caught.
In our simulation, the detectives have a map of the city, but do not know
where the thief is or where he is trying to get to. The thief also has a map but
does not really know how to use it and wanders randomly through the cities
trying to reach the goal destination. The detectives employ different strategies
depending on what they have been assigned to.
Assignment 2 Files
Here are the files supplied for assignment 2. You can change into your
assignment 2 directory and run the following command:
cp
/home/cs1927/public_html/15x1/assignments/assn2/assn2
Files/*.
The provided files are:
1. Makefile: This controls compilation of the program. You only need to
modify this if you create additional files for your implementation.
It mustproduce and executable called assn2
2. Graph.h: Graph ADT Interface

Provides an interface for basic graph functionality. May be extended to


incorporate more functionality. We assume all graphs in this
assignment are undirected, weighted graphs and are connected.
3. Graph.c: This is just a stub file that you need to implement yourself.
You can use any of the code or adapt any of the code from lectures to
do this.
4. Agent.h : Agent ADT Interface
This is an interface that represents an 'agent' in the game. An 'agent'
represents a detective or a thief. This interface includes functions to
allow the agents to interact with the client program.
5. Agent.c : Agent ADT Implementation
This partially implements the Agent ADT and supplies the
implementation for the RANDOM movement strategy. This will need to
be completed by you. Make sure you understand what has already
been supplied.
6. main.c : The client program that runs the game.
This program reads in the data and creates a graph that represents a
map of the city. The 5 agents are also created and a game starts. This
will need to be completed by you.
7. cities.data files
Sample test files to use as a starting point for your testing. Some test
files have graphs with small numbers of cities/vertices some with more.
Some have informants, some don't etc. You should also create your
own test files.
8. agentsS0.data, agentsS1.data...agentsS3.data
Sample test files that you can use once you have completed the
different stages of the assignment. agents1.data should work if you
have implemented stage 1 and above, agents2.data should work if you
have implemented stage 2 and above etc. Note: stage 4 must be
tested by using one of the cities data files with informants
You should create your own agents.data files for testing.
NOTE: For this assignment, all files are given to you as a starting point. You
may modify them in anyway you like. However you must, of course, make
sure your finished implementation follows the behaviour of the model output.
Cities data

This is a sample data file that represents the map of cities. The first line
shows how many cities are in the graph. Then for every city there will be a line
of data listing its edges with weights. This is an undirected graph, so if there is
an edge from 0 to 5 with weight 29 there should be an edge from 5 to 0 with a
weight 29. After the edges are listed each vertex will have data segment with
a value of either 'n' or 'i' and then its actual string representation. The 'n'
indicates that it is a normal city. The 'i' indicates the city has an informant
there.
100529141660750840nsydney1251529n
adelaide2nmelbourne3530436nperth43369
20ndarwin5129029330610nhobart6n
auckland7nmadrid8nnewyork9nbrisbane
Agents data
The first line of data represents information about the thief. The first number
represents the amount of stamina the thief starts with. The second number
indicates where the starting location of the thief is. The third number
represents the goal city of the thief. This is followed by a string representation
of the thief.
The next four lines represent the 4 detectives. Each detective is also given a
starting stamina and a starting location. However the third integer represents
the strategy that the detective is assigned. This is followed by a string
representation of the detective.
1056T120D1131D2512D3542D4
Command Line Arguments
The program requires 3 command line options with an optional fourth. The
command line arguments are as follows:
1. The name of the city data file
2. The name of the agent data file
3. The maximum number of cycles in the game
4. A random seed value
Assignment 3 Tasks
1. Task 0: Graph blackbox unit testing - 2 Marks
You must create a file called testGraph that tests the functions defined
in the given Graph.h file. You must create assert based tests. We will
run your testGraph.c code with our own working and broken graph
implementations to check they pass and fail the implementations

accordingly. You do not need assert based tests for the functions show
or destroyGraph.
You do not need to submit tests for any additional functions you add to
your graph when you complete the other tasks of the assignment.
2. Task 1: Assignment Diary - 1 Marks
You must maintain and design an implementation diary. As you
complete your work on this assignment you must maintain an
assignment diary where you will reflect on what you have done. In a
text file called assn2Diary.txt place the date and time of your work
together with some brief comments of the work you have completed
such as what you worked on, what you accomplished and what bugs
you fixed. You should discuss your choices of data structures and
additional ADTs you have used in your implementation. It should also
discuss how you have tested your implementation.
3. Task 2: Implementation
The implementation is divided into 4 stages as outlined below
1. Stage 0: RANDOM strategy - 2 automarks
For stage 0 we will test detectives using the random strategy
only. The random strategy has been implemented, however you
will need to modify the provided code in these ways to pass
stage 0:

The data for each vertex including whether there is an


informant in the city and the name of the city is read in by
the program, but is never stored in the graph or displayed
when printing out the stats. You must implement this.

You must complete the implementation of a weighted


graph in Graph.c. You should decide which
implementation will make it easiest to implement the rest
of the assignment!
Make sure all the information shown in stats and map
have all the correct details.
Stamina limitations must also be implemented. To do this,
each time an agent makes a move, the weight of the
edge followed is deducted from the stamina. Edges that
the agent does not have enough stamina for, are not
considered legal moves. This means there may be no
legal moves for the agent to randomly select. If the
detective does not have any legal moves left, due to not
having enough stamina, he must remain in the same city

for another cycle. Remaining in the same city for a cycle


resets the agents stamina back to the original level.

You must also implement winning or losing the game. The


supplied implementation finishes the game, only when
time runs out. You need to implement the other winning
conditions

The detectives win the game if at the end of the


turn, they are located in the same city as the thief.

The thief wins the game if at the end of a turn he is


located in the goal city and there are no detectives
there.

If the thief reaches the goal location at the same


time as one of the detectives, the detective
catches the thief and wins.

Note: If one of the detectives starts in the same city as


the thief, the thief is caught immediately. However
throughout the game, the thief is caught only if one of the
detectives is in the same city as the thief at the end of the
cycle .
2. Stage 1: CHEAPEST_LEAST_VISITED strategy - 2
automarks
If a detective is assigned this strategy, it means that at every
opportunity he has to move, he will move to the city he has
visited the least number of times, out of the legal options that
are available. This means the detective must work out what
cities are actually adjacent to the current city and pick from
those the one that has been visited the least. In situations where
there are more than one location with the same number of visits,
the one with the smallest weight is chosen. If there is more than
one location with the same number of visits AND the same
weight, the one with the lowest Vertex Id should be chosen.
The stamina limitations described in stage 0 should also be
enforced for this stage and all stages of the assignment, so
cities that the agent does not have enough stamina to visit are
not considered legal moves
This stage will be tested by supplying agent files with only this or
the random strategy being used.
3. Stage 2: DFS - 2 automarks

In this stage a DFS strategy must be implemented. When


following this strategy, the agent maps out an entire route that
will take him through every city on the map using the DFS
algorithm. At every cycle, the agent attempts to move to the next
city on the plan. If the agent does not have enough stamina he
will wait in the same ciy to recover. When the agent has visited
all cities at least once, a new dfs path from the final location is
mapped out and is followed.
4. Stage 3: Least Turns Path - 2 automarks
In this stage we will test your implementation using city data with
informants. Thus at any cycle during the game a detective might
go to a city where there is an informant. In this situation the
detective finds out where the thief is currently located. The
detective must then find the path to that location that will take
the least number of turns. Of course the thief may be gone by
the time the detective gets there and the detective must restart
his original strategy from his new location. Any cities the
detective passes through on the shortest path are counted as
being visited if the detective returns to the
CHEAPEST_LEAST_VISITED strategy. The detective may also
pass through a city with another informant in which the detective
would find a new least turns path from the current location.
You must take into account the stamina of the agent. For
example, if one path requires the agent to travel through 3
vertices, but would have to rest twice ( 5 turns), that is more
turns that an agent travelling through 4 vertices but not having to
rest ( 4 turns).
If there are 2 paths that would take equal turns, choose the one
that results in the agent having the most stamina when he
reaches his goal.
If there are 2 paths that would take equal turns and would result
in the agent having the same resulting stamina, either path is
valid. (We will not autotest this situation).
NOTE: You may create additional .h and .c files to use in your
implementation for all/any of the stages
Running the sample Assignment 2 program
A sample solution is available at ~cs1927/bin/assn2Model on CSE machines.
The program takes 3 command line arguments as outlined above. These are
the filename with the city data, the filename with the agent data, the maximum
number of cycles and it optionally takes a fourth command line argument that
is used to seed the random number generator that is used for random
movement. This is provided to facilitate automarking and testing. By using the

same seed, you can produce the same ordering of 'random' moves and
repeat exactly the same situation.
Available Commands
Once the program has started the user will be prompted for input. The
available commands are listed below:
1. run
This will run an entire simulation, printing out a trace of the agents
location for each cycle of the game. It will print out how the game
finished ie with the thief being caught, getting away, time running out.
2. step
This command will run just one cycle of the game, printing out the new
location of the agents for the next cycle. If the game finished in that
cycle, it will also print out how the game finished. This allows the user
to step through the game one cycle at a time.
3. stats
This prints out statistics about the agent. This includes the name of the
agents' current location, the name of the agent's goal location if it is the
thief or was given the thief's location, and the agents' stamina.
4. display
This will display the current locations of all agents
5. map
This prints out the graph connectivity information that represents the
map of the city.
6. quit
Quits the game!
Stage 0:
In this example all detectives are following the RANDOM strategy (strategy 0).
The thief uses the random strategy.
./assn2citiesSmall.dataagentsS0.data106
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D431111Enter

command:mapV=4,E=301:4102:90010:41
20:90023:3032:30Entercommand:stats
Hour0T1000california(3)melbourne(0)D1100000
perth(1)D25000perth(1)D350perth(1)D4500
perth(1)Entercommand:stepHour1TD1D2D3
D420000Entercommand:statsHour1
T970darwin(2)melbourne(0)D199959melbourne(0)
D24959melbourne(0)D39melbourne(0)D4459
melbourne(0)Entercommand:stepHour2TD1D2
D3D431201Entercommand:stats
Hour2T940california(3)melbourne(0)D199918
perth(1)D24059darwin(2)D350melbourne(0)D4
418perth(1)Entercommand:displayHour2TD1
D2D3D431201Entercommand:run
Hour3TD1D2D3D420310Hour
4TD1D2D3D401211Tgot
awaytomelbourne(0)GAMEOVER:YOULOSETHIEFGOT
TOGETAWAY
Stage 1:
In this example all detectives are using the CHEAPEST_LEAST_VISITED
strategy and the thief is following the usual random strategy.
./assn2citiesMedium.dataagentsS1.data104
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D498762Enter
command:runHour1TD1D2D3D4400
51Hour2TD1D2D3D49550
5Hour3TD1D2D3D446686
Hour4TD1D2D3D435500Hour
5TD1D2D3D456118Hour6
TD1D2D3D416220Hour7T
D1D2D3D400117D1caughtthe
thiefinsydney(0)YOUWINTHIEFCAUGHT!
Stage 2:
In this example detectives 3 and 4 use the DFS strategy. In this strategy they
do a depth first traversal from their starting points and follow this at each
cycle. If they do not have the stamina to go to the next city on their route, they
remain at the same location to regain their stamina and continue on the set
path. (This happens even if there were other options they did have the
stamina for.) In this example detective 1 and 2 are sill following the
CHEAPEST_LEAST_VISITED strategy and the thief is of course using the
RANDOM strategy.
./assn2citiesMedium.dataagentsS2.data102

POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D492812Enter
command:runHour1TD1D2D3D4410
01Hour2TD1D2D3D49555
0Hour3TD1D2D3D446630
Hour4TD1D2D3D495545Hour
5TD1D2D3D445193Hour6
TD1D2D3D440244D3caughtthe
thiefindarwin(4)YOUWINTHIEFCAUGHT!
Stage 3:
In this example detective D1 and D2 start with CHEAPEST LEAST_VISITED
strategy and detective 3 and 4 start with the DFS strategy. However detective
1 and 4 starts off in a city with an informant (this is indicated by the * character
on the display), so straight away switch to the strategy of going along the
shortest path to the thiefs currentLocation (city 9). Detective 4 reaches the
destination by hour 5 but the thief is no longer there. However the other
detectives have found the thief by this stage anyway. Detective 1 is following
the shortest path from 8 to 9, but has to stop at Hour 4 to regain stamina.
Detective 2 finds an informant in city 1 in hour 1 and goes via the shortest
path from vertex 1 to 4. In hour 3 detective 3 finds an informant and goes via
the shortest path to vertex 4.
So D1 calculated that the path that takes the least number of turns to get from
8 to 9 (taking into account his/her stamina) is 8,0,5,3 (rest) ,4,9 (cost 6 turns).
D1 calculates the path to be 8,0,5,3,4,9 so it costs 5 turns.
In Hour 1, D2 runs into an informant and calculates the path from 1 to 4. (1,5
(rest),3,4)
In Hour 3 D3 runs into an informant and calculates the path from 1 to 4.
./assn2citiesInformants.dataagentsS3.data202
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D498*268*Enter
command:runHour1TD1D2D3D4401*
00Hour2TD1D2D3D49550
5Hour3TD1D2D3D44351*3
Hour4TD1D2D3D493354Hour
5TD1D2D3D444439D1caught
thethiefindarwin(4)YOUWINTHIEFCAUGHT!
Assessment
Assignment 2 is worth 13 Marks. Your Assignment 2 submission will be
assessed in the following way:

Automarking of Stage 0: 2

Automarking of Stage 1: 2

Automarking of Stage 2: 2

Automarking of stage 3: 2

Graph unit testing: 2

Assignment diary: 1

Programming style: 2

Program Failures
If the ~cs1927/bin/assn2Model program fails (e.g., segmentation fault, bus
error) or behaves incorrectly according to the specification, please email
angf@cse.unsw.edu.au and attach the test file or a description of the input
that caused the failure/bug.
Late Penalty
A late penalty of 10% per day applies to the maximum mark.
ASSIGNMENTS can not be submitted at all after Fri February 13th 2015
23:59:59
Originality of Work
ALL work submitted for this assignment MUST BE YOUR OWN WORK and it
MUST BE COMPLETED INDIVIDUALLY. DO NOT COPY FROM OTHERS;
DO NOT ALLOW ANYONE TO SEE YOUR CODE. We regard copying of
assignments, in whole or part, as a serious offence. We use plagiarism
detection software to search for multiply-submitted work and work that is
similar to programs found on the internet and other sources. Be warned that:

the submission of work derived from another person, or jointly written


with someone else will, at the very least, result in automatic failure for
COMP1927 with a mark of zero. allowing another student to copy from
you will, at the very least, result in a mark of zero for your own
assignment; and

severe or second offences will result in automatic failure, exclusion


from the University, and possibly other academic discipline.

Group submissions will not be allowed. Your program must be entirely


your own work.

If you require further clarification on this matter please refer to:

Learning Centre: Plagiarism and Academic Integrity

MyUNSW: Plagiarism and Academic Misconduct

CSE: Addendum to UNSW Plagiarism Guidelines

CSE: Yellow Form (whose terms you have agreed to)

Submission
You need to submit your assignment using the give command on a CSE
machine
1927classrun15x1giveassn2*.c*.hassn2Diary.txt
Makefile
Assignment 2 Bonus: Master Thief
Due: 23:59:59 Thursday 12th February 2015 No Late Submissions accepted
Worth: 2 marks
Assignment 2 Bonus Challenge Tasks
1. Task 0: Makefile - 0 Marks (but mandatory - you will receive 0 for
automarking if it is missing)
Complete a Makefile for the bonus component of the assignment.
It should be capable of producing:
File name

Comment

assn2Bonus

Client program

We will be using your makefile to compile your assignment for


automarking, so if you do not provide one you will receive 0 for the
automarking. Also make sure your Makefile produces executables with
the same name as given above. eg assn2Bonus
2. Task 1: Thief Strategy Implementation - 2 Marks
You must modify the assn2 program and implement a strategy for the
thief.
Assume the thief has a map of the cities and knows where the getaway
location is. Also assume that the thief knows the location of each
detective, but does not know the strategy or stamina of the agent. Also
assume that for this part of the assignment no detectives will be using
random strategy. The thief does not know where the informants for the
detectives are.
The aim is to implement a clever strategy for the thief that increases
the liklihood of getting away, or at least holding off being caught for as
long as possible.

3. Diary: 0 Marks (but you lose 1 mark if it is missing)You must


maintain an assn2Diary.txt file. You will need to provide an entry in an
assn2BonusDiary to explain your strategy and the basics of how it
works.
Assessment of assn2Bonus
This will be run as a competition.
All entries, along with the original random thief from the assn2Model will be
run in different situations.
Different situations will include different maps, different starting locations,
different seeds, different detective strategies etc.
Any submissions that do not follow the rules of the game will be disqualified. If
they seem like a serious attempt that unintentionally broke the rules, they will
get 0.5 marks, but will not be run during the competition.
During the competition, the number of times the thief gets away will be
recorded. The number of times the thief is caught will also be recorded, along
with as the number of hours the thief can resist being caught by the detectives
in situations when the thief gets caught or time runs out..
The score is calculated by the number of getaways minus the number of times
the thief is caught.
The person with the highest score wins. In cases of ties, the total number of
hours the thief resisted being caught will be taken into account.
Marks
Marks will be given as follows:
1. Winner 2/2
2. Second 1.9/2
3. Third 1.8/2
4. Fourth 1.6/2
5. Fifth 1.5/2

Any other entries that can beat the Random Thief will be given a score
of 1

Any other serious attempts that do not beat the Random Thief will get
0.5

Originality of Work

ALL work submitted for this assignment MUST BE YOUR OWN WORK and it
MUST BE COMPLETED INDIVIDUALLY. DO NOT COPY FROM OTHERS;
DO NOT ALLOW ANYONE TO SEE YOUR CODE. We regard copying of
assignments, in whole or part, as a serious offence. We use plagiarism
detection software to search for multiply-submitted work and work that is
similar to programs found on the internet and other sources. Be warned that:

the submission of work derived from another person, or jointly written


with someone else will, at the very least, result in automatic failure for
COMP1927 with a mark of zero. allowing another student to copy from
you will, at the very least, result in a mark of zero for your own
assignment; and

severe or second offences will result in automatic failure, exclusion


from the University, and possibly other academic discipline.

Group submissions will not be allowed. Your program must be entirely


your own work.

If you require further clarification on this matter please refer to:

Learning Centre: Plagiarism and Academic Integrity

MyUNSW: Plagiarism and Academic Misconduct

CSE: Addendum to UNSW Plagiarism Guidelines

CSE: Yellow Form (whose terms you have agreed to)

Submission
You need to submit your assignment using the give command on a CSE
machine
1927classrun15x1giveassn2Bonus*.c*.hMakefile
assn2BonusDiary.txt

Lab Exercises Week 1


Objectives

To practise programming linked lists

To practise programming doubly linked lists

To practise using tools such as gdb and valgrind

Assessment
Deadline: 11:59pm Tue 9 December 2014

Total Marks: 3
You must get your tutor in your lab to mark the exercises during the allocated
lab time or the following week if you submitted your lab on time using give. Try
to get them to mark each exercise as you complete it in your lab time if
possible. In addition to the code that the exercise calls for, you will of course
have to write some additional code to test the correctness of your
implementation. Your tutor may want to see this testing code, too. Good style
requires good tests!
Exercise 1 - Linked Lists (0.5 mark)
Copy the files lists.h , lists.c and testLists.c into your working directory. The
file lists.ccontains a printList function and stubs for other functions you
need to implement to complete the lab. You can use testLists.cto write
your tests, but do not edit lists.h
Implement the function
intsumListItems(linkls);
which adds all the items in a list and returns the resulting integer value, and
and tests to testLists.c. Test it for lists with zero, one, and some more
elements.
Compile your program with the command
gccWallWerrorgotestListstestLists.c
lists.c
The g option makes sure that debug information is generated.
Execute your program in gdb or ddd and show your tutor that you can:
1. set a breakpoint at the beginning of a function and at a given line in the
program
2. know how to inspect the elements of a list using the print command
3. inspect the call stack.
Exercise 2 - Linked Lists (0.5 mark)
Type in the command
valgrind./testLists
The output should show you that you have some memory leaks - assuming
you have written some code in testLists that actually adds some nodes to your
linked list.
Implement the function
voidfreeList(linklist);

that frees all the memory for each node in your list. Once you have written the
function, test it in your testLists code. Run valgrind again and check that all
the memory leaks have gone. You must be able to show this to your tutor.
Exercise 3 - Linked Lists (1 mark)
Implement the function
linkfromTo(intstart,intend);
which creates a list with the elements start to end. If start is greater
than end, return the empty list. Examples:
fromTo(2,6)2>3>4>5>6>XfromTo(3,3)
3>XfromTo(4,3)>X
Exercise 4 - Doubly Linked Lists (1 mark)
Write a function
dlinkdoublify(linkls)
which, given a linked list, creates a new doubly linked list with the same items
as elements. You might want to write a printDList function to test it.
You must also write a function
voidfreeDList(dlinklist);
and make sure you can demonstrate that you have freed the memory
correctly to your tutor.
Submitting your lab
You must get the lab marked by your tutor in your lab. You should also submit
your solution using give on a CSE machine. To do this, run:
1927classrun15x1givelab01lists.c
Due Date: 11:59:59pm Wednesday 11/12/2013

You might also like