Sei sulla pagina 1di 15

StudentIDnumber:

____________________
Pages:15
Questions:11

THEUNIVERSITYOFTASMANIA

EXAMINATIONSFORDEGREESANDDIPLOMAS

November2013

KXT102ProgrammingwithDataStructures

Examiners:DrJRDermoudy&DrSXu

Timeallowed:THREE(3)hours
Readingtimeallowed:Fifteen(15)minutes

Instructions:
Thereisatotalof180marksavailable.PleaseanswereachquestioninaDIFFERENT
book.

SectionsAandBdealwithDataStructures.AttemptFOUR(4)questionsfrom
sectionAandTWO(2)questionsfromsectionB.

SectionCdealswithSoftwareEngineeringFundamentals.AttemptTWO(2)
questionsfromthissection.

KXT102ProgrammingwithDataStructures

SECTIONADATASTRUCTURESShortanswerquestions
AttemptFOUR(4)questionsfromthefive(5)available.Allquestionsinthissectionareof
equalvalue.Eachquestionisworth10marks.Thissectionisworth40marksor22.2%of
theexamination.

Question1
Considerthefollowingprogramfragmentthatdefinesaselfreferentialclass:

public class TaxonomicKey


{
public String name;
public String description;
public TaxonomicKey parent;
public TaxonomicKey child;
public TaxonomicKey sibling;
public TaxonomicKey(String n, String d, TaxonomicKey p)
{
name=n;
description=d;
parent=p;
child=null;
sibling=null;
}

public boolean isRoot()


{
return (parent==null);
}
public String toString()
{
return this.toString();
}
}

public class Harness


{
public static void main(String []args)
{
TaxonomicKey animals=null;
System.out.println(animals.isRoot());
Continued

Page2

KXT102ProgrammingwithDataStructures

/* ### */
animals=new TaxonomicKey("Bovine","Cows & " +
"Bulls",null);
System.out.println(animals.toString());
}
}
a

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Whatwillbedisplayedonthescreeniftheaboveprogramiscompiledandrun?
Why?
[5marks]
Assumethatanycompilererrorsarecorrectedand,onexecution,theannotated
line(###)isreachedwithouterror.Whatwouldtheoutputofthefinal
println()methodcallbe?Why?
[5marks]

Question2
TheobjectiveofthefollowingprogramistoenableKnowledgetobemanagedina
circularRepository.Thereare,unfortunately,fivelogicerrorsintheprogram
nonearesyntactic.Pleaseidentifythelinenumberonwhicheacherroroccursand
rewritethelineinyouranswerbookinitscorrectedform.Donotrewritelinesthatdo
notcontainerrors.

public class Knowledge


{
public String information;
public Knowledge next;
public Knowledge(String i)
{
i=information;
next=null;
}
}
public class Repository
{
protected Knowledge current;
public Repository(String i)
{
current=new Knowledge(null);
next=this;
}

Continued

Page3

KXT102ProgrammingwithDataStructures

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

public int length()


{
int r=1;
Repository c=current;
while (c!=current)
{
r++;
c=c.next;
}
return r;
}
public void add(String i)
{
Knowledge n=new Knowledge(null);

if (current!=null)
{
n.next=n;
current=n;
}
else
{
n.next=current.next;
current.next=n;
}
}
}

[10marks]

Question3
a
WhatmechanismdoesJavahaveforthespecificationofanADT?Howdoesthis
differfromthemechanismusedforitsimplementationinJava?

[5marks]
b

Objectscanbepolymorphic.Whatdoesthistermmean,howdoyoudefinea
polymorphicobject,andhowcanyouspecifywhichtypeyouwanttheobjectto
be?
[5marks]

Continued

Page4

KXT102ProgrammingwithDataStructures

Question4
ConsidertheKnowledgeandRepositoryclassesfromQuestion2.Writeclone()
methodsforeachoftheseclassesasrequiredbytheCloneableinterfacesothat
objectsofthoseclassesaredeeplycloned.

[10marks]

Question5
a
OurADTimplementationshaveconsistedofbothinterfacesandclasses.Why
havewedonethisandwhatadvantagesarisebydoingso?

[5marks]

b
OurADTimplementationshaveconsistedofaclassfortheADTandaninternal
datastructureforthecollectionofvalues.Whyhavewedonethisandwhat
advantagesarisebydoingso?

[5marks]

Continued

Page5

KXT102ProgrammingwithDataStructures

SECTIONBDATASTRUCTURESLonganswerquestions
AttemptTWO(2)questionsfromthethree(3)available.Allquestionsinthissectionareof
equalvalue.Eachquestionisworth45marks.Thissectionisworth90marksor50%ofthe
examination.

Question6
DenseArraysareanabstractdatatypeconsistingofoneormoreelements.Each
elementconsistsofapairofvalues:oneisanonnegativenumericvalue(anindex)
whichisusedtoidentifytheelement,theothervalueisadataitem(oftypeObject).
Theindicesmustbeuniqueandneedtobeconsecutive.Theabstractdatatypeisto
beimplementedusingadoubleendeddoublylinkedlistorderedbyincreasing
indexnumber.

TheNodedatatypeofalinkedlistcanbedefinedforuseasfollows:

public class Node


{
protected Node previous;
protected Object data;
protected int index;
protected Node next;
public Node(Object o, int i)
{
previous=null;
data=o;
index=i;
next=null;
}

Youshouldassumetheexistenceofset???()andget???()methodsto
modify/examinetherespectiveinstancevariables.ThisimpliesthataDenseArray
canbedefinedasfollows:

public class DenseArray


{
protected Node first;
protected Node last;
public DenseArray()
{
Continued

Page6

KXT102ProgrammingwithDataStructures

first=null;
last=null;
}
public DenseArray(Object o)
{
first=new Node(o,0);
last=first;
}
public boolean isEmpty()
{
return (first==null);
}

TheDenseArray classwillrequireaprimitiveoperationindex()withthe
followingmethodheader:

public Object index(int i)

Whenpassedtheintegerindexoftherequiredelement,themethodshould
returnthevalueoftheelementwiththatindexifitexists,andshouldreturn
nullifitdoesnot.Themethodshouldsearchfromtheendthevalueisclosest
to.Writethemethodindex().
[10marks]
WritethemethodtoString()(fortheDenseArrayclass)thatconvertsthe
arraytoaStringofcommaseparatedvalues.Ifthebooleanparameteristrue
thevaluesshouldbeproducedinfirsttolastorder,ifthebooleanparameteris
falsethevaluesshouldbeinlasttofirstorder.toString()hasthe
followingheader:

public String toString(boolean b)

[10marks]
Writethemethodadd()(fortheDenseArrayclass)thatupdatesa
DenseArraywiththesuppliedObjectparameter.Thenewelementshould
beaddedtothebeginningofthelinkedlistifthebooleanparameteristrue
(shiftingallexistingelementstotheright)andattheendofthelinkedlistifthe
booleanparameterisfalse.add()hasthefollowingmethodheader:

Continued

Page7

KXT102ProgrammingwithDataStructures

public void add(Object o, boolean b)

[15marks]
Writethemethoddelete()(fromtheDenseArrayclass)thatremovesthe
elementwiththegivenindexfromtheDenseArray.Ifanelementwiththe
specifiedindexisnotpresent,nochangetotheDenseArrayshouldoccur.All
elementstotherightofthevaluedeletedshouldbeshiftedtotheleft.The
delete()methodyouwritemusthavethefollowingmethodheader:

public void delete(int i)

[10marks]

Question7
LouisianaGlazedDuckisachainoffastfoodoutlets.Eachoutletemployscheckout
ducklingstoservecustomers.Thefollowingitemsareavailable:
gibletspiecesofduck;
pottychunkspotatochips;and
fowljuiceayellowlemonade.
Customerscomeinandplaceorders.Theorderiskeyedintoacomputerisedcash
registerthatmaintainsthedetails.Onceanorderistaken,thecustomerisgivenan
ordernumberandthecheckoutducklingtakestheorderforthenextcustomer(if
thereisone).Anotheremployee(inthekitchen)putstheorderstogetherand
providesthemtothecustomer;thisemployeealsoremoveseachorderfromthe
computersystem(usingthecustomersordernumber)onceithasbeendispatched.
Thustherearenumerousorderswithinthecomputersystemfornumerous
customersatanytimeandeachordercanconsistofnumerousitems.Thecurrent
computersystemneedstobereplacedandyouvegotthejob!

a
Whichunderlyingdatastructure(arrayorlinkedlist)willyouuseasabasisto
modeltheorderssystem?Intwothreesentences,explainwhy.

[5marks]

b
Whichkindofabstractdatatype(binarytree,generaltree,stack,priorityqueue,
doubleendedqueue,set,list,etc.)wouldyouusetomodeltheorderssystem?In
twothreesentences,explainwhy.

[5marks]

c
Theinternationalheadquarters(LGDHQ)wishtoknowtheprecisedetailsof
salesforalloftheiroutlets.Thesystemwouldbemodifiedtoincludeallorders
Continued

Page8

KXT102ProgrammingwithDataStructures

takenwithintheabovecomputersystemforeachoftheirfivethousandstores.
Managementwishtotypeintheidentificationnumberofastoreandbegiven
thetotalnumberofsalesforeachofthethreeproducts.Whichunderlyingdata
structure(arrayorlinkedlist)willyouuseasabasistomodeltheoutlets?In
twothreesentences,explainwhy.
[5marks]
Inorder(bigOh)notation,whatisthebestandworstcasetimecomplexityfor
findingthetotalnumberofsalesgivenyourchoiceinpart(c).Indicatewhy.
[2marks]
Thefollowingclassfragmentmodelsacustomersorder.Youshouldassume
thattheOrderclasspossessesconstructors,andtheusualget???()and
set???()methods.
public class Order
{
protected int orderNumber;
protected int pieceCount;
protected int chipsCount;
protected int drinkCount;
public Order(int n, int p, int c, int d)
{

}
Implementtheclassthatrepresentsalltheordersforanoutlet(Outlet).You
shouldincludethefollowingmethods:
public Outlet()createanoutlet;
public int addOrder(int p, int c, int d)addanorderto
thosealreadyprovided,returningthenewcustomersordernumber.
Theorderconsistsofthenumberofpieces(p),chunks(c),anddrinks(d)
required;
public void removeOrder(int n)removefromthereceived
orderstheorderwiththegivencustomerordernumber(n).Ifthereisno
orderwiththatnumber,nochangetotheordersshouldoccur;and
public int count()calculatethetotalnumberofordersinthe
system,returningthatvalue.

Continued

Page9

KXT102ProgrammingwithDataStructures

Implementtheclassthatrepresentstheworldwideoutlets(LGD_HQ).You
shouldincludethefollowingmethods:
public LGD_HQ()createthechain;
public void addOutlet(int id, Outlet o)addtheorder
detailsofanoutlet(o)withidentificationnumber(id)tothechain;and
public int whatSales(int id)findandreturnthenumberof
orderswithinthedetailsforanoutletidentifiedbythegivennumber
(id).
[28marks]

Question8
ConsiderthefollowingStringofcharacters:

FACETIOUS

ForeachoftheADTsin(a)(e)below:

i
Show,byusingaconceptualdiagram,thefollowingdatastructuresafter
thecharactershavebeeninsertedintheorderthattheyareencountered.

[3marksforeachADT]

ii
IndicatethebestcasetimecomplexityofsearchingtheADTforan
arbitrarycharacterwhichisstored.(Dothisforthegeneralcase,i.e.
considertheADTashavingnsymbolsbutdonotconverttoorder(big
Oh)notation.)Inasentence,explainwhythistimecomplexitywilloccur.

[2marksforeachADT]

iii IndicatetheaveragecasetimecomplexityofsearchingtheADTforan
arbitrarycharacterwhichisstored.(Dothisforthegeneralcase,i.e.
considertheADTashavingnsymbolsbutdonotconverttoorder(big
Oh)notation.)Inasentence,explainwhythistimecomplexitywilloccur.

[2marksforeachADT]

iv IndicatetheworstcasetimecomplexityofsearchingtheADTforan
arbitrarycharacterwhichisnotstored.(Dothisforthegeneralcase,i.e.
considertheADTashavingnsymbolsbutdonotconverttoorder(big
Oh)notation.)Inasentence,explainwhythistimecomplexitywilloccur.

[2marksforeachADT]

Continued

Page10

KXT102ProgrammingwithDataStructures

circularqueue;
binarysearchtree;
bag;
priorityqueue(inwhichlettersareinsertedinalphabeticalorder);and
searchtreeofdegreefour(4)whichiskeptascompactaspossiblebutwhichis
notrebalancedaftervaluesareinserted.
[45marks]

Continued

Page11

KXT102ProgrammingwithDataStructures

SECTIONCSOFTWAREENGINEERINGFUNDAMENTALS
AttemptTWO(2)questionsfromthethree(3)available.Allquestionsinthissectionareof
equalvalue.Eachquestionisworth25marks.Thissectionisworth50marksor27.8%of
theexamination.

ThefollowingisrelevanttoQuestions9and10.

AtthedisreputableinternationaluniversityDegreesRUs,20%ofstaffareopento
bribery.Theywillacceptcash,beer,chocolate,orvegetablesinexchangefor
marks.Eachstudentisaskedatthecommencementofthedegreewhetherthey
arewillingtoworkfortheirresults.Astudentwhodoesnotwishtoworkfor
theirdegreemaybribetheirlecturer.Theywouldreceiveamarkallocationof
cash/10,10,20,or30marksrespectivelyforeachofthebribesmentionedabove
(cash,beer,chocolate,orvegetables).Ifthebribeisobservedbysomeoneelse,
thenthestudentreceivesnobenefit.Astudentcannotreceiveagradelower
than0%orgreaterthan100%.

ThecodefortheDegreesRUsclassisasfollows:

import java.util.Scanner;
import java.util.Random;
public class DegreesRUs
{
private Scanner sc;
private Random rpg;
private boolean influenced;
private int mark;
public DegreesRUs()
{
String response;
sc=new Scanner(System.in);
rpg=new Random();
influenced=false;
System.out.print("Will you work for your " +
"degree? ");
response=sc.next();
if (response.toLowerCase().charAt(0)=='n')
{
if (rpg.nextInt(10)<2)
{
influenced=true;
}
Continued

Page12

KXT102ProgrammingwithDataStructures

}
mark=0;
}
public void slipMe(String bribe,boolean observed)
{
if ((influenced) && (!observed))
{
if (bribe.equalsIgnoreCase("Chocolate"))
{
mark+=20;
}
if (bribe.equalsIgnoreCase("Beer"))
{
mark+=10;
}
if (bribe.equalsIgnoreCase("Vegetables"))
{
mark-=30;
}
mark=Math.max(mark,0);
mark=Math.min(mark,100);
}
}
public void slipMe(int cash,boolean observed)
{
if ((influenced) && (!observed))
{
mark+=(cash/10);
mark=Math.min(mark,100);
}
}
public boolean passed()
{
return (mark >= 50);
}
}

Aharnessclassthatsimulatestheattemptedbriberybyonestudentisas
follows:

public class GraduateMe


{
public static void main(String args[])
{
Continued

Page13

KXT102ProgrammingwithDataStructures

DegreesRUs bachelors;
bachelors=new DegreesRUs();
while (! bachelors.passed())
{
bachelors.slipMe(250,false);
}
}
}

Question9
a
Whatisblackboxtesting?Howwouldyoublackboxtesttheaboveclasses?
Canyouprovidedetailswiththeinformationgiven?Ifso,giveexamplesof
userinput/activity,testcases(includingthereasonsthetestcaseswerechosen).
Iftheaboveclassescannotbeblackboxtested,whynot?

[9marks]

b
Whatiswhiteboxtesting?Howwouldyouwhiteboxtesttheaboveclasses?
Canyouprovidedetailswiththeinformationgiven?Ifso,giveexamplesof
userinput/activity,testcases(includingthereasonsthetestcaseswerechosen).
Iftheaboveclassescannotbewhiteboxtested,whynot?

[9marks]

c
HowwouldyoudebugtheDegreesRUsclass?Describethechangesyou
wouldmake.Writeatestharnesstodemonstratethecorrectnessofthe
DegreesRUsimplementation.

[7marks]

Question10
Developmentofthesoftwarewasundertakenusingasingleteam.Thesewerethe
fourphasesofdevelopmentandthewaterfallmodelwasadopted.Requirements
analysistookone(1)week.Designlastedtwo(2)weeks.Codinglastedtwo(2)
weeks.Testingoccupiedtwo(2)weeks.Thesoftwarewasduefordeliveryafter
seven(7)weeks.Onlyduringthetestingphasedoesactivitytocorrectthedefects
foundduringtestingoccur.Itmaybeassumedthatnodefectsareintroducedduring
testing.

Itisanticipatedthattwo(2)defectsareintroducedeachweekandthattheremovalof
onedefectwilloccupy5%ofthetotalpretestingdevelopmenttime.

Continued

Page14

KXT102ProgrammingwithDataStructures

Estimatethenumberofdefectsthatwillremaininthesoftwareattheendofthe
developmentperiod.
[14marks]
Estimatethetotaltimerequiredtodelivertheproductcompletelyfreeof
defects.
[8marks]
Ifallthetimeneededtoremoveallthedefectswastaken,whatistheefficiency
(asdefinedinlectures)ofthedevelopment?
[3marks]

Question11
Statewhethereachofthefollowingstatementsisvalidorinvalidandthenbriefly
arguethevalidityorinvalidityofeach:

a
Functionaldecompositionmethodologiesareparticularlysuitedtoparallel
programs.

[5marks]

b
Historicaldataarerequiredfortheindependentteamstestingregime.

[5marks]

c
UnitTestingandSystemTestingshouldbecombinedintoasinglephase.

[5marks]

d
Lifejacketsmadefromconcretearelowquality.

[5marks]

e
CMMisacompliancestandard.

[5marks]

_______________________________________

Page15

Potrebbero piacerti anche