Sei sulla pagina 1di 2

11/24/2016

www.cse.csusb.edu/egomez/cs202/lab1.txt

Lab1createaclassthanrepresentsasailingship,forpossiblelateruseinagameorhistorical
simulation.
Classnameshouldbesomthinglike"sailb"(forsailboat)
Theclassshouldincludethefollowingdataattributes:
stringname//nameofboatorship(itisunluckytosailonashipwithnoname!)
doublelength//lengthinfeet
doublebeam//widthinfeet(beamisthenauticalterm)
doubledisplacement//onlandwewouldcallthisweight.inpounds
doublesail_area//insquarefeet
??rig//thisisthetypeofsailssquarerig(likeColumbus)orforeandaft(triangular
likeamodernsailboat)
//youdefinehowyouwanttostorethiscouldbeBoolean,integercodeorstring
Youmayaddotherattibutesifyouneedthem.Youwantatleastadefaultconstructor,accessand
modify
functionsforeachdataitem.Inaddition,classshouldbeabletocalculateandreportthefollowing
values,
calculatedfromtheboatdesign.
hullspeedHS=1.34*sqrt(length):hullspeedinknots(nauticalmiles/hour,1nauticalmile=
1.1508normalmiles)
Thisisthemaximumspeedtheshipcanreach;atthisspeedthewaterresistanceincreasesso
muchthatsailscan't
pushtheshipanyfasternomatterhowmuchwind.
sailpowerP=sail_area/displacement^(2/3):(displacementtothe2/3power)
Weignoreunitsonthis,itisjustanumberwecalibrateitbytakingasampleboat40ft
long,25000pounddisplacement
450squarefeetofsailhasP=.52andreacheshullspeedofabout7.5knotsin15knotsofwind.
Sowearegoingtomake
thehorrible,inexactapproximationthat
P*wind_speed=boat_speed

Rememberthatboat_speed<=HS.Windgreaterthanwhatittakestoreachhullspeedjusttilts
theboatmore.
(thenauticaltermfortiltisangleofheel,orjustheel).

stabilitycoefficientCSV=beam/cube_root(displacement/64)
Again,thisisjustanumber.Itmeasureshoweasyitisforthewindtofliptheboatover
(capsizeisthenauticalterm)
CSV>2istoostableiftheboatcapsizesitwillstaystayupsidedown.
CSV<1.5istoolikelytocapsizeinalightwind,isconsideredunsafe
YourclassshouldrejectaboatwithCSVoutsidetherange21.5
Inalateriterationonthisclass,wemayreplacethisyes/noresultwithafunctionthatsays
howlikelytheboatis
tocapsizewithagivenwindspeed.
Performancecalculation:
Sailboatscansailsomewhatagainsthewind
upwind_angle=45//amoderntrianglerigcansailthismuchintothewind
upwind_angle=10//asquarerigcansailthismuchintothewind.
Shipdirectionis:
doublecourse//avaluebetween0and360degreeswhere0and360arethesamecourse
http://www.cse.csusb.edu/egomez/cs202/lab1.txt

1/2

11/24/2016

www.cse.csusb.edu/egomez/cs202/lab1.txt

Winddirectionis:
doublewind_angle//alsoavaluebetween0and360degrees
Wewilldefinewind_angleasthedirectionintowhichthewindblows(thisisoppositetothe
normaldefinition
inwhichwegivethedirectionthewindiscomingfrom,makescalculationeasiertovisualize)
boat_speed:tocalculatespeedfordifferentangles:
Ifabsolute_value(wind_anglecourse)<=95//doubleboat_speed=P*wind_speed
Ifabsolute_value(wind_anglecourse)>95and<=90+upwind_angle//boat_speed=P*wind_speed/2
Ifabsolute_value(wind_anglecourse)>90+upwind_angle//shipcan'tsailinthatdirection
//ithastozigzagupwind(called"tacking")
Laterwemayrefinethiswithboat_speed=somefunctionofangle

safetycheck:
givenhullspeedHS,thefastestusefulwindUW=HS/P,thatisthewindspeedneededtodrive
theboat
asfastasitcango.Wewillassumethatwind_speed>UWisunsafeandwehavetodropthesails
and
justsituntilthewindcomesdown.

Youneedtowritetheclassdefinitionandfunctionstodoalltheabove,thenwriteaprogramthat
letsyouenter
boatparameters,andthencheckperformancebyenteringwind_speed,wind_angleandcourseandthe
programshould
tellyoueitherhowfasttheboatwillgoonthatcourse,whetheryoucansailthatcourseatall,
and
ifthewindistoostrongforsafety.Trythiswithboatsofdifferentsizes,beams,weightsandsail
areas
andseeifresultsseemtomakesenseornot.

http://www.cse.csusb.edu/egomez/cs202/lab1.txt

2/2

Potrebbero piacerti anche