ASSIGNMENT FRONT SHEET Qualifcation
Edexcel BTE !e"el # HN$ $i%lo&a in o&%utin' and S()te&) $e"elo%&ent
*nit nu&+e, and title
Unit 34: Data Structures and Algorithms
A))i'n&ent due
16-08-2016
A))i'n&ent )u+&itted
!ea,ne,-) na&e
A))e))o, na&e
27-09-2016 !A" #$U%& #$U%& S'"$
!ea,ne, decla,ation ' certi() that the *or+ su,mitted (or this assignment is m) o*n and research sources are (ull) ac+no*ledged !ea,ne, )i'natu,e
27-09-2016
$ate
G,adin' ',id #1 1
#1 2
#1 3
#2 1
#2 2
#2 3
.1 . 2
.3
D1
D2
D3
1
A))i' A) )i'n& n&ent ent tit title le
E"alu E"a luate ate// $e)i $e)i'n/ 'n/ an and d I& I&%le %le&en &entt $at $ata a St St,uc ,uctu, tu,e) e) an and d Al Al'o 'o,it ,it0& 0&) )
'n this assignment/ )ou *ill hae oortunities to roide eidence against the (ollo*ing criteria 'ndicate the age num,ers *here the eidence can ,e (ound
A))e))&ent c, c,ite,ia
Ex%ected e" e"idence
Ta) no.
!O1. *nde,)tand data )t,uctu,e) and al'o,it0&)
11 roduce design secication (or data structures elaining the alid oerations
Descri,e the data structures5 used and their oerations and their relationshis using lo*chart/ DD/ &lass Diagram/ and #seudo code or an) releant
11
A))e))o,-) Feed+ac
A))i' A) )i'n& n&ent ent tit title le
E"alu E"a luate ate// $e)i $e)i'n/ 'n/ an and d I& I&%le %le&en &entt $at $ata a St St,uc ,uctu, tu,e) e) an and d Al Al'o 'o,it ,it0& 0&) )
'n this assignment/ )ou *ill hae oortunities to roide eidence against the (ollo*ing criteria 'ndicate the age num,ers *here the eidence can ,e (ound
A))e))&ent c, c,ite,ia
Ex%ected e" e"idence
Ta) no.
A))e))o,-) Feed+ac
!O1. *nde,)tand data )t,uctu,e) and al'o,it0&)
11 roduce design secication (or data structures elaining the alid oerations that can ,e carried out on the structures
12 elain the oeration and er(ormance o( sorting and search algorithms
Descri,e the data structures5 used and their oerations and their relationshis using lo*chart/ DD/ &lass Diagram/ and #seudo code or an) releant toolsdiagrams to descri,e the *or+ing mechanisms o( the oerations lain and do some eercises a,out searching: - inear search - inar) search
11
12
2
lain and do some eercises ,out sorting: - Selection sort - u,,le sort - 'nsertion sort - Shell sort - ;uic+ sort - .erge sort - $ea sort - !adi sort
13 elain the oeration o( recursie algorithms and identi() situations *hen recursion is used
Dene recursion/ ail recursion/ "on-tail recursion/ gie some eamles o( alications
13
Al) into some eerc eercises ises
!O2. Be a+le to i&%le&ent data )t,uctu,e) and al'o,it0&)
lain and do some eercises ,out sorting: - Selection sort - u,,le sort - 'nsertion sort - Shell sort - ;uic+ sort - .erge sort - $ea sort - !adi sort
13 elain the oeration o( recursie algorithms and identi() situations *hen recursion is used
Dene recursion/ ail recursion/ "on-tail recursion/ gie some eamles o( alications
13
Al) into some eerc eercises ises
!O2. Be a+le to i&%le&ent data )t,uctu,e) and al'o,it0&) 21 imlement data structures in an eecuta,le rogramming language in the contet o( *elldened ro,lems
'mlement one case stud) that student designed in %1
21
Su,mit code *ith ro ram rammer mer
3
22 imlement oortunities (or error handling and reorting
23 test results to ena,le comarison *ith eected results
lain ,out *here*h)ho* did )ou al) error handling and reorting in )our *or+
22
est est cases 23 est est log and eidence eidence
22 imlement oortunities (or error handling and reorting
23 test results to ena,le comarison *ith eected results
lain ,out *here*h)ho* did )ou al) error handling and reorting in )our *or+
22
est est cases 23 est est log and eidence eidence
A))e))&ent c,ite,ia
Ex%ected E"idence
Feed+ac 3note on Me,it4$i)tinction i5 a%%lica+le6
.erit descritor "o .15 .erit descritor "o .25 .erit descritor "o .35 4
Distinction descritor "o D15 Distinction descritor "o D25 Distinction descritor "o D35 Summatie (eed,ac+
Distinction descritor "o D15 Distinction descritor "o D25 Distinction descritor "o D35 Summatie (eed,ac+
A))e))o,-) Si'natu,e
Date
=
1.1 %,oduce de)i'n )%ecifcation 5o, data )t,uctu,e) ex%lainin' t0e "alid o%e,ation) t0at can +e ca,,ied out on t0e )t,uctu,e) Data structures used in this case are Sin'l( !ined !i)t/ !ined i&%le&entation o5 a Stac/ !ined i&%le&entation o5 a Queue •
Sin'l( !ined !i)t A singl) lin+ed list is a list *hose node includes t*o dataelds: in(o and net he in(o eld is used to store in(ormation/ in(ormation/ and this is imortant to the user user he net eld is used to lin+ to its successor in this se>uence he (ollo*ing image deicts a simle integer lin+ed list 12
1=
10
1.1 %,oduce de)i'n )%ecifcation 5o, data )t,uctu,e) ex%lainin' t0e "alid o%e,ation) t0at can +e ca,,ied out on t0e )t,uctu,e) Data structures used in this case are Sin'l( !ined !i)t/ !ined i&%le&entation o5 a Stac/ !ined i&%le&entation o5 a Queue •
Sin'l( !ined !i)t A singl) lin+ed list is a list *hose node includes t*o dataelds: in(o and net he in(o eld is used to store in(ormation/ in(ormation/ and this is imortant to the user user he net eld is used to lin+ to its successor in this se>uence he (ollo*ing image deicts a simle integer lin+ed list 12
$ead
1=
10
ail 1.1 Sin'l( lined li)t c0a,t
Stac A stac+is a linear data structure that can ,e accessed onl) at one o( its o ends (or storing and retrieing retrieing data A stac+is a ast 'n/ irst irst %ut '%5 data structure o An)thing added to the stac+ goes on the ?to@ o( the stac+ o An)thing remoed (rom (rom the stac+ is ta+en (rom the ?to@ o( the stac+ o remoed in the reerse reerse order order (rom that in *hich *hich the) *ere *ere o hings are remoed inserted Queue A >ueueis a *aiting line that gro*s ,) adding elements to its end and o shrin+s ,) ta+ing elements (rom its (ront A >ueue is a structure in *hich ,oth ends are used: %ne (or adding o ne* elements %ne (or remoing them A >ueue is an '%structure: irst 'nirst %ut o In SMS/ I u)e t0e)e data )t,uctu,e) +ecau)e it-) )i&%le and )uita+le 5o, SMS-) data. Sin'l( lined li)t 0a) )o &an( ad"anata'e)
'nsertions and Deletions can ,e done easil) 't does not need moement o( elements (or insertion and deletion 't sace is not *asted as *e can get sace according to our re>uirements re>uirements 'ts siBe is not ed 't can ,e etended or reduced according to re>uirements 6
lements ma) or ma) not ,e stored in consecutie memor) aaila,le/een then *e can store the data in comuter
1.2 la)) dia',a& o5 SMS
7
*or+s/ *hen customers order order roduct/ the $F$ his $F$ his DD sho*s ho* the s)stem *or+s/ manager *ill chec+ that roduct is aaila,le or not/ i( aaila,le the manager *ill delier that roduct to the customers and the customers also chec+out that ,ill at the same time to s)stem %n the orther hand/ the admin *ill hae to maintain this s)stem regularl)
%!D!
.A"AC!
&US%.!S D'!
AA'A
&$&E%U
&$&E
.anager *ill hae to do:
S.S
.A'"A'"
'nut order/ chec+ i( those roducts aaila,le or not Delier Delier roduc roducts ts to customers Udate order to the s)stem
&ustomers:
AD.'"
%rder roduct &hec+out to the s)stem Cet rod roduc uctt a(te a(terr order
Admin:
1.7 $ata 8o9 dia',a& o5 SMS
Udate s)stem .aintain *hen haing errors
Flo9 c0a,t and %)eudo code 8
In)e,t ne9 %,oduct into data )t,uctu,e
SA!
'"#U #!%DU& &%D #!%DU& "A./ ;UA"'F/ #!'&
AS A'DA A'DA '"#U
!U AS '"S! "G #!%DU&
"D
1.: In)e,t ne9 %,oduct 8o9 c0a,t
;)eudo code in)e,t ne9 %,oduct
9
unction insert ne* roduct to data structure: structure: 'nut: H#001 HIeans20/200/0 %utut: ne* roduct inserted #rocess: C'" 'nut roduct code/ roduct name/ >uantit)/ rice '( alidate inutchec+ i( roduct code eisted/ roduct name is not null/ >uantit) and rice must ,e *ell (ormed5 aaila,le then 'nsert ne* roduct to data structure: H#001 HIeans20/200/05 lse inut again or eit rogram "D
1.# In)e,t ne9 %,oduct %)eudo code
$elete %,oduct exi)ted in data )t,uctu,e
10
SA!
S& #!%DU& AS &$&E ' #!%DU& J'SD '" %!D! 'S
!U AS D #!%DU&
"D
1. $elete %,oduct 8o9c0a,t
unction delete roduct eisted in data structure: 'nut: H#001 HIeans20/200/0 %utut: list roducts a(ter deleting one roduct #rocess: C'" Select roduct ;)eudo code delete %,oduct '( roduct selected is aaila,le then Delete roduct selected lse select roduct again or eit rogramme rogramme "D
11
1.= $elete %,oduct %)eudo code
Sea,c0 %,oduct in data )t,uctu,e SA! 12
'"#U #!%DU& &%D "% SA!&$ #!%DU& '" #!%DU& 'S F F &%D
%U"D "%
S$%G #!%DU&
"D
1. Sea,c0 %,oduct 8o9c0a,t
unction search roduct eisted in data structure: 'nut: roduct code H#001< %utut: roduct (ound H#001
13
1.? Sea,c0 %,oduct %)eudo code
So,t %,oduct +( %,oduct code a%%l( +u++le )o,t SA!
Do 14
change K (alse/ current K head net K headnet
GhilenetLKnull5
'( current code M net code5
AS S*a current/net5 change K true
unction sort roduct list:
netK currentnet
'nut: unsorted list roducts %utut: sorted list roducts roducts changeKKtrue #rocess:
!U
C'"
AS
Ghilechange5 do
1.1@ Bu++le )o,t 8o9c0a,t net/ current/ is (alse "D ;)eudo code )o,t change %,oduct *hile net is not null i( current code ,igger than net code then s*a net and current change is true moe to net node end i( moe to net node end *hile *hile change is true "D
1=
1.11 Bu++le )o,t %)eudo code
In)e,t ne9 cu)to&e, to data )t,uctu,e SA!
'"#U &US%.! &%D/ &US%.! "A./ #$%" AS A'DA '"#U
16
!U AS '"S! &US%.!
"D
1.12 In)e,t cu)to&e, 8o9c0a,t
;)eudo code in)e,t ne9 cu)to&e, unction insert ne* customer into customer list: 'nut: H&001 H"gu)en0203028701 H"gu)en0203028701 %utut: ne* customer inserted #rocess: C'" 'nut customer code/ customer name/ hone num,er '( alidate inutchec+ i( customer code eisted/ customer name is not null/ hone num,er must ,e *ell (ormed5 aaila,le then 'nsert ne* customer to data structure: H&001 H"gu)en09030287015 lse inut again or eit rogramme
17
1.17 In)e,t ne9 cu)to&e, %)eudo code
$elete cu)to&e, in data )t,uctu,e
SA!
S& &US%.! AS &$&E ' &US%.! J'SD '" %!D! 'S
!U AS D
18
"D
1.1: $elete cu)to&e, 8o9c0a,t
;)eudo code delete cu)to&e, unction delete customer customer list: 'nut: &ustomer code H&001< %utut: &ustomer list a(ter deleting #rocess: C'" Select customer '( customer selected is not in order list then Delete customer selected lse select select customer and chec+ again or eit eit rogram "D 1.1# $elete cu)to&e, %)eudo code
19
Add ne9 o,de, to data )t,uctu,e
SA!
'"#U &US%.!/ #!%DU&/ ;UA"'F
ADD % %!D! 'S %A %A #!'& K ;UA"'F ;UA"'F N
%!D! 20
"D
1.1 Add ne9 o,de, 8o9c0a,t
;)eudo code add ne9 o,de, unction add ne* order to order list: 'nut: <&001<#00110 %utut: ne* order added H2014091=093020<&00120005 #rocess: C'" 'nut customer/ roduct/ >uantit) inut total K >uantit) N rice Add to list order then %rder or eit rogram "D
1.1= Add ne9 o,de, %)eudo code
21
Add ne9 o,de,detail
SA!
'"#U %!D!'D/ #!%DU& &%D/ #!%DU& "A./ #!'&/ ;UA"'F/ %A %A
ADD % 'S
"D
1.1 In%ut o,de,detail 8o9c0a,t
22
;)eudo code add ne9 o,de,detail unction add ne* orderdetail to orderdetail list: 'nut: H2014091=093020<<#001uantit)/ total Add to list orderdetail 1.1? Add ne9 o,de,detail %)eudo code 1.2 Ex%lain t0e o%e,ation and %e,5o,&ance o5 )o,tin' and )ea,c0 al'o,it0&) Ex%lain and do )o&e exe,ci)e) a+out )ea,c0in' C'" !inea, )ea,c0 inear search is a er) simle search algorithm 'n this t)e o( inearSearc halue/ search/inearSearchalue/ a se>uential searchlist5 is made oer all items one ,) one er) items is chec+ed chec+ed and i( a match (ounds then that articular item is returned other*ise '( the list is emt)/ return return nullO search continues till the end o( the data da ta collection He,e %)eudo code o5 !inea, )ea,c0 ,ecu,)i"el( lse '( the rst item o( the list has the desire alue then return return that itemO
23
lse return inearSearchalue/ inearSearchalue/ reminder o( the list5O
1.2@ !inea, )ea,c0 %)eudo code A%%l( to SMS I u)e !inea, )ea,c0 to )ea,c0 a %,oduct exi)ted in %,oduct li)t +ecau)e it i) )uita+le 9it0 data )t,uctu,e3Sin'l( lined li)t6 code i) )0o9 in %a'e :# Bina,( )ea,c0 inar) search is a (ast search algorithm *ith run-time comleit) o( Plog n5 his search algorithm *or+s on the rincile o( diide and con>uer con>uer or this algorithm to *or+ roerl) the data collection should ,e in sorted (orm inar) search search a articular item ,) comaring the middle most item o( the collection '( match occurs then inde o( item is returned '( middle item is greater than item then item is searched in su,-arra) to the right o( the middle item other *ise item is search in su,-arra) to the le(t o( the middle item his rocess continues on su,-arra) as *ell until the siBe o( su,arra) reduces reduces to C'" #rocedure ,inar)Qsearch Bero sorted )ea,c0 arra) al'o,it0& )0ould loo lie t0i) T0e %)eudocode A o5 +ina,( " siBe o( arra) J alue to ,e searched Set lo*eround K1 Set ueroundK1 Ghile not (ound '( ueroundRlo*eround J': does not eists Set midoint K lo*erounduero lo*eroundueroundundlo*eround52 '( ATmidointR Set lo*eround K midoint 1 '( ATmidointM Set ueround K midoint -1 '( ATmidointK J': (ound at location midoint nd *hile nd rocedure 24 "D
1.21 Bina,( )ea,c0 %)eudo code Selection )o,t o
Selection sort is a simle sorting algorithm his sorting algorithm is a in-lace comarison ,ased algorithm in *hich the list is diided into t*o arts/ sorted art at le(t end and unsorted art at right end 'nitiall) sorted art is emt) and unsorted art is entire list
o
Smallest element is selected (rom the unsorted arra) and s*aed *ith the le(tmost element and that element ,ecomes art o( sorted arra) his rocess continues moing unsorted arra) ,oundar) ,) one element to the right
o
his algorithm is not suita,le (or large data sets as its aerage and *orst case comleit) are o( %n 25 *here n are no o( items
C'" ;)eudo code #rocedure selection sort ist: arra) o( items n: siBe o( list (or iK1 to n-1 Nset current element as minimumN minKi Nchec+ the element to ,e minimuonN (or VKi1 to n '( listTVRlistTmin then minKVO end i( end (or Ns*a the minimum elenment *ith the current current elementN '( inde.inLKi then S*a listTmin and listTi nd i( nd (or 2= nd rocedure "D
1.22 Selection )o,t %)eudo code Bu++le )o,t u,,l u,,le e sort sort is a sim simle le sorti sorting ng algo algori rith thm m his his sort sortin ing g algo algori rith thm m is com comar aris ison on ,ase ,ased d algo algori rith thm m in *hic *hich h each each air air o( adVac adVacen entt elem elemen ents ts is comared and elements are s*aed i( the) are not in order his algorithm is not suita,le (or large data sets as its aerage a erage and *orst case comleit) are o( 2 %n 5 *here n are no o( items C'"
;)eudo code
rocedure ,u,,leSort list : arra) o( items 5 loo K listcountO (or i K 0 to loo-1 do: s*aed K (alse (or V K 0 to loo-1 do: i( listTV M listTV1 then N s*a them N s*a listTV/ listTV1 5 s*aed K true end i( end (or i(not s*aed5 then
,rea+ end i( end (or
end rocedure return list "D
26
1.27 Bu++le )o,t %)eudo code A%%l( to SMS/ I u)e +u++le )o,t to )o,t %,oduct li)t +ecau)e it i) 'ood 5o, )&all data and it i) t0e 5a)te)t 9a( in t0i) ca)e/ code i) )0o9n in %a'e :/ := In)e,tion )o,t o
his is a in-lace comarison ,ased sorting algorithm a lgorithm $ere/ a su,-list is
maintained *hich is al*a)s sorted or eamle/ the lo*er art o( an arra) is maintained to ,e sorted A element *hich is to ,e WinsertWed in this sorted su,-list/ has to nd its aroriate lace and insert it there $ence the name in)e,tion )o,t )o,t o he arra) is searched se>uentiall) and unsorted items are moed and C'" inserted into sorted su,-list in the same arra)5 his algorithm is not rocedure insertionSort A : arra) o( items 5 suita,le (or large data sets as its aerage and *orst case comleit) are 2 o( int Pnhole#osition 5 *here n are no o( items int alueo'nsert alueo'nsert (or i K 1 to lengthA5 inclusie do: alueo'nsert alueo'nsert K ATi hole#osition K i *hile hole#osition M 0 and AThole#osition-1 M alueo'nsert do: AThole#osition K AThole#osition-1 AThole#osition-1 hole#osition K hole#osition -1 end *hile AThole#osition K alueo'nsert alueo'nsert end (or end rocedure "D
27
1.2: In)e,tion )o,t %)eudo code S0ell )o,t o
o
Shell sort is a highl) eXcient sorting algorithm and is ,ased on insertion sort algorithm his algorithm aoids large shi(ts as in case o( insertion sort i( smaller alue is er) (ar right and hae to moe to (ar le(t his algorithm uses insertion sort on *idel) sread elements elements rst to sort
C'"
them and then sorts the less *idel) saced elements his sacing is termed as interal his interal is calculated ,ased on EnuthWs (ormula rocedure shellSort5 as h =h*3+1 (h is interval with initial value 1) A : arra) o( items o his algorithm is >uite eXcient (or medium siBed data sets as its *hile interal and R Alength 3 do:comleit) are o( %n5 *here n are no o( items aerage *orst case
;)eudo inter tercode al K inte interral N 3 1 end *hile *hile interal M 0 do: (or outer K interalO outer R AlengthO outer do: alueo'nsert alueo'nsert K ATouter inner K outerO *hile inner M interal -1 YY ATinner - interal MK alueo'nsert do: ATinner K ATinner - interal inner K inner - interal end *hile ATinner K alueo'nsert alueo'nsert
28
end (or interal K interal -15 3O end *hile end rocedure "D
1.2# S0ell )o,t %)eudo code
Quic )o,t o
;uic ;uic+ + sort sort is a high highl) l) eXci eXcien entt sort sortin ing g algo algori rith thm m and and is ,ase ,ased d on art artit itio ioni ning ng o( arra arra) ) o( data data into into smal smalle lerr arra arra)s )s A lar large arra arra) ) is artit artition ioned ed into into t*o arra) arra)s s one o( *hich *hich holds holds alues alues smalle smallerr than than secied alue sa) iot ,ased on *hich the artition is made and another arra) holds alues greater than iot alue
29
o
he >uic+ sort artitions an arra) and then calls itsel( recursiel) recursiel) t*ice to sort the resulting t*o su,arra) his algorithm is >uite eXcient (or large siBed data sets as its aerage and *orst case comleit) are o( %nlogn5 *here n are no o( items
C'" (unction artitionuncle(t/ right/ iot5 le(t#ointer K le(t -1 right#ointer K right *hile *hil e rue do *hile ATle(t#ointer R iot do
do-nothing
;)eudo code
end *hile *hile right#ointer M 0 YY AT--right#ointer M iot do
do-nothing end *hile i( le(t#ointer MK right#ointer
,rea+ else s*a le(t#ointer/right#ointer end i( end *hile s*a le(t#ointer/right return le(t#ointer
end (unction "D
30
1.2 QuicSo,t ;i"ot ;)eudocode
C'" rocedure rocedure >uic+Sortle(t/ >uic+Sortle(t/ right5 i( right-le(t RK 0 return else iot K ATright artition K artitionuncle(t/ artitionuncle(t/ right/ iot5 >uic+Sortle(t/artition-15 >uic+Sortartition1/right5 end i( end rocedure "D 1.2= Quic )o,t %)eudo code
31
Me,'e )o,t .er .erge sort sort is a sort sortin ing g tech techni ni>u >ue e ,ase ,ased d on dii diide de and and con> con>ue uerr o
o
techni>ue Gith *orst-case time comleit) ,eing Pn log n5/ it is one o( the most resected resected algorithms .erge sort rst diides the arra) into e>ual hales and then com,ines them in a sorted manner return merge l1/ l2 5
;)eudo code end rocedure C'" rocedure merge ar a as arra)/ ar , as arra) 5 rocedure mergesort ar a as arra) 5 ar c as arra) i( n KK 1 5 return return *hile a and , hae haea elements elements 5 ar as arra) K 5aT0 aTn2 i( l1aT0 M ,T0 ar add l2 as,T0 arra) aTn21 to K the end o( c aTn l1 Kremoe mergesort 5 , ,T0 l1 (rom K mergesort l2 5 l2else add aT0 to the end o( c remoe aT0 (rom a end i( end *hile *hile a has elements 5 add aT0 to the end o( c remoe aT0 (rom a end *hile *hile , has elements 5 add ,T0 to the end o( c remoe ,T0 (rom , end *hile return c "D
end r rocedure
32
C'" $easortA as arra)5 uild$eaA5 (or i K n to 1 s*aAT1/ ATi5
1.2 Me,'e )o,t %)eudo code
Hea% )o,t he heasort inoles rearing inoles rearing the list ,) rst turning turning it into a ma n Kalgorithm n-1 hea he algorithm then reeatedl) s*as the rst alue o( the list *ith the hea last alue/ decreasing $eai()A/ 15the range o( alues considered in the hea oeration ,) one/ and si(ting the ne* rst alue into its osition in the hea his reeats uild$eaA as arra)5 until the range o( considered alues is one alue in length ;)eudo code n K elementsQinA5 elementsQin A5
(or i K Zoorn25 to 1
$eai()A/i5
$eai()A as arra)/ i as int5 le(t K 2i right K 2i1 i( le(t RK n5 and ATle(t M ATi5 else
ma K le(t
ma K i
i( rightRKn5 and ATright M ATma5 i( ma LK i5 "D
s*aATi/ ATma5
ma K right $eai()A/ ma5
33
C'"
1.2? Hea% )o,t %)eudo code
Radix )o,t u,lic static intT sortintT old5 [ o he (undamental rincile o( radi radi sort stems (rom the the denition o( the sta,le sorting is sta,le/ i( it maintains the order o( +e)s/ oo sort (or eer) ,it in algorithm the integers *hich are e>ual (or int shi(t K 'ntegerS'\ - 1O shi(t M -1O shi(t--5 [
o
!adi sort iteratiel) orders orders all the strings ,) their n-th character in the he arra) to ut the artiall) sorted arra) into rst iteration/ the strings are ordered ordered ,) their last character character 'n the second intT tm K ne* intToldlengthO intToldle ngthO run/ the strings are ordered in resect to their enultimate character And ,ecause the sort is sta,le/ s ta,le/ the strings/ *hich hae the same sa me enultimate he num,er o( 0s character/ are still sorted in accordance to their last characters A(ter A(ter n-th intthe V Kstrings 0O run are sorted in resect to all character ositions
.oe the 0s to the ne* arra)/ and the 1s to the old one ;)eudo code (or int i K 0O i R oldlengthO i5 [ '( there is a 1 in the ,it *e are testing/ the num,er *ill ,e negatie ,oolean moe K oldTi RR shi(t MK 0O '( this is the last ,it/ negatie num,ers are actuall) lo*er i( shi(t KK 0 ] Lmoe : moe5 [ tmTV K oldTiO
VO
34
^ else [ 'tWs a 1/ so stic+ it in the old arra) (or no* oldTi - V K oldTiO ^ ^ &o) oer the 1s (rom the old arra) (or int i K VO i R tmlengthO i5 [ tmTi K oldTi - VO ^ And no* the tm arra) gets s*itched (or another round o( sorting old K tmO ^ return oldO ^ 3= "D
1.7@ Radix )o,t %)eudo code
1.7 ex%lain t0e o%e,ation o5 ,ecu,)i"e al'o,it0&) and identi5( )ituation) 90en ,ecu,)ion i) u)ed $efne ,ecu,)ion/ Tail ,ecu,)ion/ Nontail ,ecu,)ion/ 'i"e )o&e exa&%le) o5 a%%lication) Recu,)ion Gi+iedia: ?A recursie denition or inductie denition is one that denes something in terms o( itsel( that is/ recursiel)5 recursiel)5 or it to *or+/ the denition in an) gien case must ,e *ell-(ounded/ aoiding an innite regress@ A recursie denition consists o( at least 2 arts: 15 A ,ase case anchor or the ground case5 that does notcontain a re(erence re(erence to its o*n t)e 25 An inductie case that does contain a re(erence to its o*n t)e or eamle: eamle: Dene the set o( natural num,ers 1. @ N 2. I5 n N t0en t0en 3nC16 3nC16 N 7. T0e,e a,e no ot0e, o+Dect o+Dect in t0e )et )et N
36
A recursie rogramalgorithm rogramalgorithm is one that calls itsel( again here are three ,asic rules (or deeloing recursie recursie algorithms _ Eno* ho* to ta+e one ste _ rea+ each ro,lem do*n into one ste lus a smaller ro,lem _ Eno* ho* and *hen to sto
ail recursion recursion is characteriBed characteriBed ,) the use o( onl) one Tail ail ,ecu, ,ecu,)io )ion n ail recursie call at the er) end o( a method imlementation 'n other *ords/ *hen the call is made/ there are no statements le(t to ,e eecuted ,) the methodO the recursie call is not onl) the last statement ,ut there are no earlier recursie recursie calls/ direct or indirect or eamle/ the method tail5 dened as:
oid tail int i5 [ i( i M 05 [ S)stemoutrint i ``5O
1.71 Tail ,ecu,)ion exa&%le Non tail ,ecu,)ion he recursie recursie call is not at the er) end end o( a method imlement imlementation ation u,lic static oid reerse5 reerse5 thro*s cetion [ char ch K char5 S)steminread5O i(ch LK WnW5 [ reerse5O S)stemoutrintch5O ^ ^
1.72 Non tail ,ecu,)ion exa&%le
37
!ecursion occurs *hen a thing is dened in terms o( itsel( or o( its t)e !ecursion is used in a ariet) o( discilines ranging (rom linguistics to logic logic he most common common alication alication o( recursi recursion on is in mathemati mathematics cs and comuter science/ *here a (unction ,eing dened is alied *ithin its o*n o*n den denit itio ion n Ghil Ghile e this this aar aaren entl tl) ) den denes es an inn innit ite e num, num,er er o( instances (unction alues5/ it is o(ten done in such a *a) that no loo or innite chain o( re(erences can occur he term is also used more generall) to descri,e a rocess o( reeating o,Vects in a sel(-similar *a) or instance/ *hen the sur(aces o( t*o mirrors are eactl) arallel *ith each other/ the nested images that occur are a (orm o( innite recursion A%%l( to SMS/ I u)e +ot0 tail ,ecu,)ion and non tail,ecu,)ion +ecau)e +ecau)e it i) is particularly useful, and easy to handle in implementations. code i) )0o9n in %a'e :#
2.1 i&%le&ent data )t,uctu,e) in an executa+le %,o',a&&in' lan'ua'e in t0e context o5 9elldefned %,o+le&) According to the re>uest o( S.S: u,licIinter(ace [ contain &an( ,eui,ed &et0od) c,eate :'#roduct inte,5ace) roduct ;,oduct loadDatar loadDa taromile5O omile5O )o&e &et0od) a) it-) )0o9n +elo9 Inte,5ace contain) roduct disla)Data5O oid saeData saeData oile5O roduct insert"e*#roductString insert"e*#roductString code/String name/ int >uantit)/ dou,le rice5O roduct search)&odeString search)&odeString code5O oid delete)&odeString delete)&odeString code5O oid sort)&ode5O oid deleteA(ter&odeStrin deleteA(ter&odeString g code5O ^
38
2.1 Inte,5ace %,oduct
Inte,5ace u)to&e, contain) )o&e a+)t,act &et0od) u,lic inter(ace '&ustomer [ customer loadDataromile5O customer disla)Data5O oid saeData saeData oile5O oid insert"e*&ustomerString insert"e*&ustomerString code/ String name/ String hone5O customer search)&odeString search)&odeString code5O u,lic '%rder [ ring code5O oidinter(ace delete)&odeString delete)&odeSt loadDataromile5O ^ order loadDataromile5O order disla)Data5O disla)Data 5O oid saeDatao saeDataoile5O ile5O
2.2 Inte,5ace u)to&e,
oid insert"e*%rderString insert"e*%rderS tring orderid/ String ccode/ dou,le total5O Inte,5ace O,de, contain) )o&e a+)t,act &et0od) oid sort)cus&ode5O sort)cus&ode 5O ^
39
2.7 Inte,5ace O,de,
And in o,de, to add &o,e t0an one %,oduct to o,de, li)t/ I al)o c,eate an Inte,5ace O,de,$etail contain) )o&e &et0od )uc0 a) load$ataF,o&File/ di)%la($ata/ )a"a$ataToFile/ in)e,tNe9 u,lic inter(ace '%rderDetail [ orderdetail loadDataromile5O loadDataromile5O orderdetail disla)Data5O disla)Data 5O oid saeDatao saeDataoile5O ile5O orderdetail insert"e*String insert"e* String orderid/ String code/ String name/ int >uantit)/dou,le >uantit)/dou,le rice/ dou,le total5O
^
2.: Inte,5ace O,de,$etail
40
I u)e : &odel cla))e)/ : cont,olle, cla))e) 9it0 data )t,uctu,e a%%,o%,iate ;,oduct cla)) 3Sin'l( lined li)t6 ,e%,e)ent a %,oduct 9it0 it) %,o%e,tie) u,lic class roduct imlements SerialiBa,le [ u,lic String codeO u,lic class roductQ&ontroller imlements '#roduct [ u,lic String nameO u,lic roduct headO u,lic int >uantit)O b%erride u,lic int saledO u,lic roduct loadDataromile5 loadDataromile5 [ ^ u,lic dou,le riceO b%erride u,lic roduct netO u,lic roduct disla)Data5 [ ^ ^ b%erride
2.# ;,oduct cla))
u,lic oid saeDataoile5 saeDataoile5 [
^
b%erride
;,oductont,olle, i&%le&ent) Inte,5ace) ;,oduct and contain)
u,lic roduct insert"e*#roductString insert"e*#roduct String code/ String name/ int >uantit)/ )o&e &et0od) dou,le rice5 [ ^ u,lic roduct insertroduct h/ roduct ro5 [
^
b%erride u,lic roduct search)&odeString search)&odeStr ing code5 [
^
b%erride u,lic oid delete)&odeString delete)&odeString code5 [
^
b%erride u,lic oid sort)&ode5 [
^
b%erride u,lic oid deleteA(ter&odeString code5 [ ^ u,lic roduct searchroduct c/ String code5 [ riate roduct deleteroduct n/ String 5 [ ^
^
41
b%erride u,lic roduct loadDataromile5 [ tr) le is store in this director)
2. ;,oduct cont,olle, cla))
ile'nutStream ile'nutS tream s K ne* ile'nutStream`D:DSAQ ile'nutStream`D:DSAQroducttt`5O roducttt`5O
Met0od load$ataF,o&File36 i) u)ed to load data %,Vect'nutStream %,Vect'nutS treamt0i) ois K&et0od ne* %,Vect'nutStreams5O5 %,Vect'nutSt reams5O5 [ 5,o& fle 90ic0 i) )a"ed in t0e local 5olde, di,ecto,( tr) [ head K roduct5 oisread%,Vect5Oread oisread%,Vect5 Oread le and assgin to head ^ catch &lass"otoundcetio &lass"otoundcetion n e5 [ ^ return headO ^ catch '%cetion e5 [
erintStac+race5O ^ return nullO ^
42
2.= Met0od load data 5,o& fle
Met0od di)%la($ata 36 t0i) &et0od i) u)ed to )0o9 data 5,o& fle a5te, loaded b%erride b%erride u,lic oid oi d saeData saeDa tao oile5 ile5 [ u,lic roduct disla)Data5 [ tr) sae data to le in this director) return headO ile%ututStream ile%ututSt ream (os K ne* ile%ututStream`D:DSAQ ile%ututSt ream`D:DSAQroducttt`5O roducttt`5O ^ %,Vect%ututStream %,Vect%ututSt ream os K ne* %,Vect%ututStream(os5O5 %,Vect%ututSt ream(os5O5 [ os*rite%,Vecthead5O os*rite%,Vecthead5O*rite *rite o,Vect to le
2. Met0od di)%la( data
osclose5O
Met0od )a"e$ataToFile 36 t0i) &et0od i) u)ed to )a"e data to fle in t0e di,ecto,( (osclose5O )%ecifc ^ catch '%cetion e5 [
erintStac+race5O ^ ^
43
2.? Met0od )a"e data to fle
Tail ,ecu,)ion &et0od )ea,c0 %,oduct/ it-) u)ed to )ea,c0 a %,oduct in %,oduct li)t +( %,oduct code b%erride u,lic roduct search)&odeString search)&odeS tring code5 [ return searchhead/ code5O
^call method search5 *ith t*o arameters
u,lic roduct searchroduct c/ String code5 [ t*o arameters are assed to this method i( c KK null ccodee>ualscode55 ccodee>ualscode55 [chec+ i( c is null or c has code e>ual to code/ then return c return cO ^ else [ return searchcnet/ code5Ocall this method recursiel)
^
^ 44
2.1@ Met0od )ea,c0 %,oduct Nontail ,ecu,)ion &et0od in)e,t ne9 %,oduct i) u)ed to in)e,t ne9 %,oduct to %,oduct li)t b%erride
u,lic roduct insert"e*#roductString insert"e*#roduct String code/ String name/ int >uantit)/ dou,le rice5 [ roduct K ne* roductcode/ name/ >uantit)/ 0/ rice5Ocreate ne* o,Vect roduct return inserthead/ 5Ocall method insert ^ u,lic roduct insertroduct h/ roduct ro5 [ i( h KK null5 [i( h is null/ then assign ro to h b%erride h K roO u,lic^ oid [ else sort)&ode5 [ ,oolean hnetchangeO K inserthnet/ ro5Onet *ill ,e assigned recursiel) do [ head K hO roduct current K headO return hO roduct reious K nullO ^
roduct net K headnetO change K (alseO
2.11 Met0od in)e,t ne9 %,oduct
*hile net LK null5 [
In t0i) a))i'n&ent I a%%l( +u++le )o,t to t0e data )t,uctu,e u)ed +ecau)e it i) )i&%le/ ea)( to )et u% and al)o onetcode5 adeuated to t0e data i( )t,uctu,e/ I u)ed i( currentcodecomare currentcodeco mareonetcode5 M 05 [chec+ current code M it to )o,t %,oduct li)t and o,de, li)t. net code He,e an exa&%le o5 )o,tin' change K trueO%,oduct +( %,oduct code 9it0 +u++le )o,t i( reious LK null5 [then s*a the nodes roduct tem K netnetO reiousnet K netO netnet K currentO currentnet K temO
4=
^ else [ roduct tem K netnetO head K netO netnet K currentO currentnet K temO ^ reious K netO net K currentnetOmoe to net node ^ else [moe to the net node reious K currentO current K netO net K netnetO ^ ^ ^ *hile change5O ^
46
2.12 Met0od )o,t %,oduct +( +u++le )o,t
Met0od deleteB(ode 36 t0i) &et0od i) u)ed to ,e&o"e a %,oduct in %,oduct li)t +( %,oduct code b%erride u,lic oid delete)&odeString delete)&o deString code5 [ head K deletehead/ code5O
^call method delete *ith t*o arameters
riate roduct deleteroduct n/ String 5 [ i( n KK null5 [i( n is null then thro* ecetion thro* ne* Vaautil"oSuchlementcetion`cannot delete`5O ^ else [ i( ncodee>uals55 ncodee>u als55 [i( n has code e>uals to code then return net return nnetO
^ else [
nnet K deletennet/ deleten net/ 5O recursiel) to the net node return nO
^
^
^else call this method 47
2.17 Met0od delete %,oduct +( code Met0od deleteA5te,xode 36 t0i) &et0od i) u)ed to ,e&o"e a %,oduct 0a"e code a5te, xcode b%erride u,lic oid deleteA(ter&odeString code5 [ u,licroduct class customer imlements SerialiBa,le [ roduct K headO u,lic String ccodeO *hile roduct LK null5 [ u,lici( String cnameO e>ualscode555 [chec+ i( roduct has code e>uals to code roductcodee>ualscode5 roductcode u,lic String honeO i( roductnet LK null5 [ roductnet K roductnetnetOassi roductnetnetOassign gn node a(ter netcustomer node (or netO the current node ^ ^ roduct K roductnetOmoe to u,lic net node ^ ^ u,lic customer5 [ ^
2.1: Met0od delete %,oduct a5te, xcode
u,lic customerString customerStri ng ccode/ String cname/ String hone5 [
u)to&e, cla)) 3Sin'l( lined li)t6 ,e%,e)ent) a cu)to&e, 9it0 it) %,o%e,tie)thisccode K ccodeO thiscname K cnameO thishone K honeO ^ u,lic customerString customerStri ng ccode/ String cname/ String hone/ customer net5 [ thisccode K ccodeO thiscname K cnameO thishone K honeO thisnet K netO ^ ^
48
u,lic class customerQ&ontroller imlements '&ustomer [ u,lic customer headO u,lic customer toO
b%erride u,lic customer loadDataromile5 loadDataromile5 [ ^ b%erride
2.1# u)to&e, cla))
u,lic customer disla)Data5 disla)Data5 [ ^ u,lic customer geto5[ geto5[ ^ u,lic ,oolean chec+5 [ ^
u)to&e,ont,olle, i&%le&ent) Inte,5ace) u)to&e, and contain) b%erride )o&e nece))a,( &et0od) u,lic oid saeDataoile5 saeDataoile5 [ ^ b%erride u,lic oid insert"e*&ustomerString insert"e*&ust omerString code/ String name/ String hone5 [^ b%erride u,lic customer search)&odeString search)&odeS tring code5 [
^
b%erride u,lic oid delete)&odeString delete)&odeString code5 [
^
riate customer deletecustomer deletecustomer n/ String 5 [^ u,lic customer searchcustomer c/ String code5 [^ ^
49
2.1 u)to&e, cont,olle, cla))
b%erride
Met0od in)e,tNe9u)to&e,36 t0i) &et0od i) u)ed to in)e,t a ne9 cu)to&e, to t0e )t,uctu,e3Sin'l( !i)t name/ i&%le&ent) )tac6 u,lic oid data insert"e*&ustomerString insert"e*&ust omerString!ined code/ String String hone5 [ customer cus K ne* customercode/ customercode / name/ hone/ null5O create ne* customer head K toO i( head KK null5 [i( head is null/ then assign ne* customer to head head K cusO to K headO ^ else [i( head is not null/ then assign ne* customer to net node cusnet K headO head K cusO to K headO
=0
2.1= Met0od in)e,t ne9 cu)to&e, Met0od di)%la($ata 36 t0i) &et0od i) u)ed to )0o9 all t0e data )to,ed in t0e data )t,uctu,e b%erride u,lic customer disla)Data5 disla)Data5 [ customer cus K headOassgin head to a customer head K cusnetOmoe to net node return cusO
^
2.1 Met0od di)%la( data
O,de,u,lic cla))class 3Sin'l( !i)t6 ,e%,e)ent an o,de, 9it0 it) %,o%e,tie) order!ined imlements SerialiBa,le[ u,lic String orderidO u,lic String ccodeO u,lic dou,le totalO u,lic order netO u,lic order5 [
^
u,lic orderString orderid/ String ccode/ dou,le total5 [ thisorderid K orderidO thisccode K ccodeO thistotal K totalO =1 ^ ^
2.1? O,de, cla)) O,de,ont,olle, i&%le&ent) Inte,5ace) O,de, and contain) )o&e nece))a,( &et0od) u,lic class orderQ&ontroller imlements '%rder [ u,lic order head K null/ tail K nullO u,lic order rst K nullO b%erride u,lic order loadDataromile5 loadDataromile5 [^
b%erride u,lic order disla)Data5 [^ b%erride u,lic oid saeDataoile5 saeDataoile5 [^ b%erride u,lic oid insert"e*%rderString insert"e*%rderSt ring orderid/ String ccode/ dou,le total5 [^ u,lic ,oolean ismt)5 [ ^ b%erride u,lic oid sort)cus&ode5 sort)cus&ode 5 [^ ^ =2
2.2@ O,de, ont,olle, cla)) Met0od in)e,tNe9O,de,36t0i) &et0od i) u)ed to in)e,t a ne9 o,de, to t0e data )t,uctu,e3Sin'l( !ined !i)t i&%le&ent) ueue6 b%erride u,lic oid insert"e*%rderString insert"e*%rderS tring orderid/ String ccode/ dou,le total5 [ head K rstO tail K ne* orderorderid/ ccode/ total5O ne* order *ill ,e assigned to tail tailnet K nullOnode a(ter taill is null i( ismt)55 [i( data structure is null/ then head / tail *ill ,e hae the same alue head K tailO rst K headO ^ else [ order tem K headO b%erride u,lic order disla)Data5 disla)Data 5 [ *hile temnet LK null5 [ i( ismt)55 [ i( data structure is emt)/ then *ill thro* an ecetion tem K temnetO tr) [ ^moe to the nal node o( the data structure structure thro* ne* cetion5O temnet K tailOassgin tail to the net node ^ catch cetion e5 [ rst K headO
erintStac+race5O
^ ^
2.21 Met0od in)e,t ne9 o,de,
^
Met0od di)%la($ata 36 t0i) &et0od i) u)ed to )0o9 all o,de, in o,de, li)t order o K headOhead *ill ,e assigned to an order o,Vect head K headnetOmoe to the net node return oOreturn o,Vect order ^
=3
2.22 Met0od di)%la( data o,de, O,de,$etail cla)) 3Sin'l( !ined li)t6 ,e%,e)ent) an o,de,detail 9it0 it) %,o%e,tie) u,lic class orderdetail imlements SerialiBa,le[ u,lic String orderidO u,lic String codeO u,lic String nameO u,lic int >uantit)O u,lic dou,le riceO u,lic dou,le totalO u,lic orderdetail netO u,lic orderdetail5 [ ^ ^ =4
2.27 O,de, detail cla)) O,de,$etailont,olle, cla)) I&%le&ent) Inte,5ace O,de,$etail and contain) )o&e &et0od) u,lic class orderdetailQ&ontroller imlements '%rderDetail[ u,lic orderdetail headO
b%erride u,lic orderdetail loadDataromile5 loadDataromile5 [^ b%erride u,lic orderdetail disla)Data5 [
^
b%erride u,lic oid saeDataoile5 saeDataoile5 [^
b%erride u,lic orderdetail insert"e*String insert"e*S tring orderid/ String code/String name/ int
alue to data )t,uctu,e/ I catc0 e,,o, 90en cu)to&e,. I5 null "alue/ t0 >uantit)/dou,le >uantit)/dou,le rice/t0i) dou,le total5 [^ in)e,t %,oduct o, cu)to&e,. ate oid ,tn'nsert#roductAction#er(ormedVaaa*teentActionent ,tn'nsert#roductAction#er(ormedVaaa*teentActionent et5 [ u,lic orderdetail insertorderdetail h/ orderdetail order5 [^ String code K codegetet5O String name K namegetet5O String ttriceK ricegetet5O ricegetet5O String tt>uantit) K >uantit)get >uantit)getet5O et5O u,lic ,oolean ismt)5 [^ i( Lchec+nullcode5 Lchec+nullcode5 YY Lchec+nullname5 Lchec+nullname5 YY Lchec+nullttrice5 Lchec+null ttrice5 ^ YY Lchec+nulltt>uantit)55 Lchec+nulltt>uantit)55 [ ^ else [ 2.2: O,de, $etail cont,olle, I%tion#anesho*.essageDialogroot#ane/ I%tion#anesho*.essa geDialogroot#ane/ `#lease ll all elds`5O ^
2.2 i&%le&ent o%%o,tunitie) 5o, e,,o, 0andlin' and ,e%o,tin' Ex%lain a+out 90e,e490(40o9 did (ou a%%l( e,,o, 0andlin' and ,e%o,tin' in (ou, 9o,
==
5 data )t,uctu,e i) null/ to %,e"ent e,,o, t0e,e 9ill +e an in5o,& t0e u)e, clic on di)%la( d
ate oid ,tnDisla)#roductAction#er(ormedVaaa*teentActionent et5 [ i( chead LK null5 [ ^ else [ I%tion#anesho*.essageDialogroot#ane/ I%tion#anesho*.essa geDialogroot#ane/ `here is nothing to sho*L`5O ^ ^
=6
30en u)e, ente, a %,oduct code to )ea,c0/ i5 t0e,e i) no code
&atc0ed/ t0e,e 9ill +e an in5o,& to t0e u)e, riate oid ,tn'nsert#roductAction#er(ormedVaaa*teentActionent et5 [ String code K codegetet5O String m K `#T0-9[3/4^f`O i( Lchec+#rodu Lchec+#roduct&odecode55 ct&odecode55 [ ^ else [I%tion#anesho*.essa [I%tion#anesho*.essageDialogroot#ane/ geDialogroot#ane/ `&ode not An in5o,& 9ill +e di)%la(ed matched`5O ^
4 0en u)e, 9ant to delete a %,oduct o, a cu)to&e, in t0e li)t
90ic0 ce,tainl( exi)ted in o,de, li)t/ t0i) i) an e,,o,/ an in5o,& 9ill +e )0o9n riate oid ,tnDelete#roductAction#er(ormedVaaa*teentActionent et5 [ String code K String5 ta,le#roductgetalueAtt,l#roductgetSelected!o*5/ 15O i( Lchec+deletroducteaaila, Lchec+deletroducteaaila,lecode55 lecode55 [
in5o,& 9ill +e lie ^ else [I%tion#anesho*.essageDialogroot#ane/ [I%tion#anesho*.essaAn geDialogroot#ane/ `hist0i) roduct
=7
#.0en u)e, 9ant) to )0o9 o,de, detail 9it0out c0oo)in' an o,de,/ t0e,e 9ill +e a 9a,nin' to &ae )u,e t0at u)e, c0oo)e) an o,de, to "ie9 riate oid ,tn%rderDetailAction#er(ormedVaaa*teentActionent et5 [ i( t,l%rdergetSelected!o*5 KK -15 [ I%tion#anesho*.essage Dialogroot#ane/ `#lease I%tion#anesho*.essageDialogroot#ane/ choose an order`5O ^
T0e,e 9ill +e an in5o,&
. 0en u)e, 9ant) to delete a %,oduct a5te, t0e la)t one/ t0i) i) an e,,o,/ an e,,o, &e))a'e 9ill +e di)%la(ed to t0e u)e, riate oid ,tnDeleteA(ter&ode#roductAction#er(ormedVaaa*teentActionent et5 [ String code K ttDeleteA(ter&odegetet5O i( csearch)&odecode5net LK null5 [ ^ else else
% tion# tion#ane anes sho* ho*.es .essa sa eDialo eDialo T0e,e root root#a #ane/ ne/ `Fou `F ouan are arein5o,& at the 9ill +e
=8
=.To %,e"ent in)e,t )a&e %,oduct code o, cu)to&e, code to data )t,uctu,e/ I 9ill c0ec code +e5o,e in)e,t/ i5 code i) exi)ted/ t0e,e 9ill +e an in5o,& to +e )0o9n riate oid ,tn'nsert#roductAction#er(ormedVaaa*teentActionent et5 [ String code K codegetet5O i( Lchec+#roduct&odeco Lchec+#roduct&odecode55 de55 [ [ ^else [I%tion#anesho*.e [I%tion#anesho*.essageDialog ssageDialogroot#ane/ root#ane/ `#roduct code eisted`5O^ An in5o,& 9ill +e )0o9n
. To %,e"ent in)e,t 9,on' t(%e "alue/ )uc0 a) %,oduct uantit(/ %,oduct %,ice/ an e,,o, 9a,nin' 9ill +e di)%la(ed riate oid ,tn'nsert#roductAction#er(ormedVaaa*teentActionent et5 [ String ttriceK ricegetet5O String tt>uantit) tt>uantit ) K >uantit)get >uantit)getet5O et5O i( num,eralidationtt>uantit)/ ttrice55 [ ^ else [I%tion#anesho*.essageDialogroot#ane/ An in5o,& 9ill +e )0o9n `#lease enter num,er onl)`5O^
=9
2.7 te)t ,e)ult) to ena+le co&%a,i)on 9it0 ex%ected ,e)ult). Te)t nu& +e, 1
0at i) +ein' te)ted #roduct code
2
#roduct name
3
#roduct >uantit )
4
#roduct rice
=
&ustom er code
6
&ustom er name
Ex%ected outco&e
String H#< H#002<5 String H< HVeans<5 'ntMK1/R K2005 1205
String H#002<5
;a E"idence )) o, 5ail #as Success(ul s
String HVeans<5
#as s
'nt 3005
ail
Dou,leMK 1/RK30005 20005 String H&< H&002<5
Dou,le 20005
#as s
String H&00134<5
ail
String HIac+<5
#as s
String H< HIac+<5
Actual outco&e
Success(ul
Success(ul
Success(ul
60
7
&ustom er hone
String 1011 digits5 H09203021 23<5
String H09030280<5
ail
8
%rderid
Success(ul
otal rice
String H201609090 92400<5 Dou,le 20005
#as s
9
String H20160909 092400<5 Dou,le 20005
#as s
Success(ul
10
loadDat aromi le5
Success(ul
disla) Data5
!ead (rom le in director) D:DSAQro ducttt5 "ull
#as s
11
!ead (rom le in director) D:DSAQr oducttt5 #roduct list
12
saeDa taoile 5
ile is saed in director) D:DSAQr oducttt5 insert" #roduct e*#rod H#001
ile is saed in director) D:DSAQro ducttt5
#as s
Success(ul
#roduct H#001
#as s
Success(ul
"ull
ail
12
13
ail
61
14
delete )&ode5
1=
sort)& ode5 deleteA (ter&o de5
16
Delete roduct H#001
Delete roduct H#001
#as s
Success(ul
Sorted list
Success(ul
Delete roduct H#001
"ull
#as s ail
17
search 5
#roduct H#001
"ull
ail
18
loadDat aromi le5
Success(ul
disla) Data5 saeDa taoile 5
!ead (rom le in director) D:DSAQord ertt5 %rder list
#as s
19
!ead (rom le in director) D:DSAQor dertt5 %rder list
success(ul
ile is saed in director) D:DSAQor dertt5 %rder H2014091= 093020<& 00120005
ile is saed in director) D:DSAQord ertt5
#as s #as s
%rder H2014091=0 93020<&00 120005
#as s
Success(ul
Sorted
Sorted order
#as
Success(ul
20
21
insert" e*%rde r5
22
sort)c
Success(ul
62
order list
list
!ead (rom le in director) D:DSAQcu stomertt5 &ustomer list
!ead (rom #as le in s director) D:DSAQcust omertt5 "ull ail
Success(ul
ile is saed in director) D:DSAQcu stomertt5 insert" &ustomer e*&ust H&001<"g omer5 u)en0903 0202935 search &ustomer )&ode5 H&001<"g u)en0903 0202935
ile is saed #as in director) s D:DSAQcust omertt5
Success(ul
&ustomer H&001<"gu )en090302 02935 "ull
Success(ul
28
delete )&ode5
29
loadDat aromi le5
Delete customer H&001<"gu )en090302 02935 !ead (rom le in director) D:DSAQord
23
us&ode 5 loadDat aromi le5
24
disla) Data5
2=
saeDa taoile 5
26
27
Delete customer H&001<"g u)en0903 0202935 !ead (rom le in director) D:DSAQor
s
#as s
ail
#as s
Success(ul
#as s
Success(ul
63
30
disla) Data5 saeDa taoile 5
31
32
insert" e*5
de4rdetailt t5 %rderdetail list ile is saed in director) D:DSAQor derdetailt t5 %rderdetail H2014091= 093020<# 001
erdetailtt5 %rderdetail list ile is saed in director) D:DSAQord erdetailtt5
#as s #as s
Success(ul
%rderdetail #as H2014091=0 s 93020<#00 1
Success(ul
Success(ul
S()te& Reui,e&ent) Gindo*s J# or later/inu/ .ac%S !A.: 128 .O 64 . (or Gindo*s J# 32-,it5 Dis+ sace: 124 . IDE 6 or later o&%ilin' and ,unnin' %,o',a& &omile the rogram (rom *ithin the director): Vaac DSAQA1Vaa • • • •
•
•
A(ter A(ter comiling the rogram success(ull)/ run it (rom the director) a,oe: Vaa DSAQA1
64
He,e i) a u)e, inte,5ace 90en %,o',a&&e i) loaded. Ta+ %,oduct 9ill +e )0o9n f,)t
1
2
= #
:
12
1
7
? 1 1: 1
6=
1 T0i) +utton i) u)ed to load data 5,o& fle 2 T0i) +utton i) u)ed to )a"e data to fle and exit 7 T0i) +utton i) u)ed to )ea,c0 %,oduct code in t0e data )t,uctu,e and ,etu,n 5ound "alue to t0e ta+le : Mo"e to ta+ O,de, # Mo"e to ta+ u)to&e, T0i) +utton i) u)ed to delete %,oduct a5te, code = Mo"e to ta+ ;,oduct lic on t0i) +utton 9ill o%en an in)e,t %,oduct 9indo9 ? T0i) 9ill delete %,oduct 90ic0 i) )elected in t0e %,oduct ta+le 1@ lic on t0i) +utton 9ill )o,t t0e data )t,uctu,e +( %,oduct code 11 lic on t0i) +utton 9ill )0o9 all t0e "alue in t0e data )t,uctu,e 12 A textfeld acce%t %,oduct code to +e deleted a5te, t0at 17 A textfeld acce%t %,oduct code to +e )ea,c0ed 1: T0i) ta+le i) u)ed to di)%la( %,oduct) in t0e data )t,uctu,e
In)e,t ne9 %,oduct
66
1 2
1 Text feld acce%t %,oduct code
7
2 Text feld acce%t %,oduct na&e
:
7 Text feld acce%t %,oduct uantit(
#
: Text feld acce%t %,oduct %,ice
Mo"e to ta+ u)to&e,
67
1
2
#
=
:
7
? 1
1
1 T0i) +utton i) u)ed to load data 5,o& fle 2 T0i) +utton i) u)ed to )a"e data to fle and exit %,o',a&&e 7 lic on t0i) +utton 9ill )ea,c0 cu)to&e, in data )t,uctu,e +( cu)to&e, code : Textfeld acce%t cu)to&e, code to +e )ea,c0ed # Mo"e to ta+ %,oduct Mo"e to ta+ cu)to&e,
68
= Mo"e to ta+ o,de, lic on t0i) +utton 9ill o%en an in)e,t cu)to&e, 9indo9 ? lic on t0i) +utton 9ill delete cu)to&e, 90ic0 i) )elected in t0e cu)to&e, ta+le 1@ lic on t0i) +utton 9ill di)%la( all data on t0e ta+le 11 Ta+le 9ill +e u)ed to di)%la( data
In)e,t ne9 cu)to&e, 1 Text Text feld acce%t cu)to&e, code
1 2 7 :
#
2 Text Text feld acce%t cu)to&e, na&e 7 Text Text feld acce%t cu)to&e, %0one nu&+e, : lic on t0i) +utton 9ill clo)e t0i) 9indo9 # lic on t0i) 9indo9 9ill in)e,t ne9 cu)to&e, to t0e data )t,uctu,e
69
Mo"e to ta+ O,de,
1
2
7 :
#
= ?
1
1 T0i) +utton i) u)ed to load data 5,o& fle 2 T0i) +utton i) u)ed to )a"e data to fle and exit %,o',a&&e 7 Mo"e to ta+ ;,oduct : Mo"e to ta+ u)to&e, # Mo"e to ta+ O,de,
70
lic on t0i) +utton 9ill )o,t cu)to&e,) in t0e data )t,uctu,e and 9ill )0o9 in t0e ta+le = lic on t0i) +utton 9ill o%en an in)e,t o,de, 9indo9 lic on t0i) +utton 9ill di)%la( all data in t0e ta+le ? lic on t0i) +utton 9ill )0o9 o,de, detail 90ic0 i) )elected in t0e ta+le 1@ Ta+le i) u)ed to di)%la( all o,de,) in t0e data )t,uctu,e In%ut ne9 o,de,
71
1
7
2
:
#
=
1
?
1 Select cu)to&e, code 90o i) o,de,in' 2 Select %,oduct code 90ic0 i) o,de,ed 7 In%ut %,oduct uantit( : T0i) 9ill )0o9 %,oduct %,ice # T0i) 9ill )0o9 total %,ice
72
lic on t0i) +utton 9ill add %,oduct to o,de, li)t and 9ill )0o9 in t0e ta+le = T0i) ta+le i) u)ed to )0o9 %,oduct) in o,de, li)t T0i) 9ill )0o9 total %,ice o5 t0e o,de, ? lic on t0i) +utton 9ill &ae o,de,in' 1@ lic on t0i) +utton 9ill clo)e t0i) 9indo9 O,de, detail 1 T0i) 9ill )0o9 o,de,id
7
2 T0i) 9ill )0o9 o,de, total
2
1
:
7 T0i) 9ill )0o9 cu)to&e, code : T0i) 9ill )0o9 cu)to&e, na&e
#
# T0i) ta+le i) u)ed to )0o9 li)t %,oduct in an o,de, lic on t0i) +utton 9ill clo)e t0i) 9indo9
SA!
%AD DAA % 73
#!%DU&
'"S!
&US%.!
D
S%!
%!D!
SA!&$
D'S#AF
SA DAA %
"D
SMS F!O HART
A+out t0i) %,o',a&&e •
•
;o)iti"e: ;o)iti"e : his rogramme is er) simle/ eas) to handle/ admin can an) error an)time Ne'ati"e: Ne'ati"e: Don
.ana .anage ge custo ustom mers ers ,ut ,ut don< don
7=