SlideShare uma empresa Scribd logo
1 de 6
CP1801 SP2 2015 – Assessment 1
Completed by Luke Veltjens-Swan
S/N - 12627400
Functions:
main
This is the main function, upon starting it will display a prompt and ask the user to enter their
name. The users name will be saved as a variable and then a welcome message will be
displayed with userName. Then the menu will be displayed, it will show three options which
are Play, Instructions and Quit. A loop starts after the menu which states that while the user
does not want to quit, to loop back to the menu after either displaying instructions or playing
a game of golf. Since the menu options rely on capital letter input for all three options if the
user inputs a lowercase character than the program will convert it to uppercase. If the user
enters any letter besides the three corresponding menu options then an error message is
displayed. When the user decides to quit a goodbye message is displayed using userName.
playGolf
This function runs when the user inputs P on the menu, it starts the game of golf. First a
message is displayed telling the user how far they are from the hole, it will always be 230m at
the start of a game. An instructional message is then displayed letting the user know the
controls. A loop starts where the exit condition is the distance to the hole being 0. The
function then gets input from the user while checking for a correct input, if the user enters
anything besides the three controls then the swing miss message is displayed and swings is
increased by 1. The distance that the ball travels with each hit is calculated depending on the
choice of club. With each swing the distance the ball travels is saved to a variable called
distHit and after each swing the value of the new distance to hole is calculated, distToHole –
distHit = new distance to hole. An absolute value is used for the distToHole to avoid negative
distance issues. After each hit the distHit along with distToHole is displayed to the user.
Upon distToHole being 0 the users score will be displayed at the end using the score
function. Finally the function returns to the menu.
score
This function runs at the end of playGolf and it displays the users score in relation to par 5.
Depending on the users score there are three types of finish messages that can be displayed.
function main
Input Processing Output
userName
menuChoice
User selection Prompt
Menu
Menu Choice:
Path Condition Action
Instructions User inputs I Instructions are displayed
Play User inputs P Game of golf begins
Error message User inputs anything but I, P
or Q
Error message
Menu loop:
Loop variable: The user input
Exit condition: Input is Q
Algorithm:
function main():
display prompt
get userName from user
display “welcome userName”
display menu
get menuChoice
while menuChoice is not ‘Q’
if input is lowercase change to uppercase
if input = ‘I’
display “instructions”
otherwise if input = ‘P’
begin playGolf
Otherwise
display “error message”
display menu
get menuChoice
end loop
display goodbye userName
function playGolf(menuChoice)
Input Processing Output
Type of club Current distance to hole =
distToHole – distHit
INITIAL_HOLE_DISTANCE
DRIVER_DISTANCE
IRON_DISTANCE
PUTTER_DISTANCE
PAR_5
MINIMUM_STRENGTH
MAXIMUM_STRENGTH
Current distance to hole.
Distance ball is hit decision:
Path Condition Action
Driver Driver randomDistance * 100
Iron Iron randomDistance * 30
Putter Putter Make a decision based on distToHole
Path Condition Action
Putter hits 80-120% of
distToHole
distToHole is <=10 distHit = randomDistance *
distToHole
Putter hits 80-120% of
putter strength.
distToHole is > 10 distHit = randomDistance *
10
Invalid club loop:
Loop variable: Club entered by user.
Loop exit condition: Valid club selection.
Game loop:
Loop variable: The distance the ball is from the hole
Loop exit condition: Distance to hole being 0.
Algorithm:
playGolf
display “You are 230m from hole”
display “Club selection: press D for driver, I for Iron, P for Putter.”
distToHole = 230
swings = 0
repeat until distToHole = 0
get club from user
while club is not ‘D’ or ‘I’ or ‘P’
display swing miss message
swings = swings + 1
end loop
randomDistance = random number between 80 and 120, divide by 100.
if club = D
distHit = randomDistance * 100
if club = I
distHit = randomDistance * 30
if club = P
if distToHole <=10
distHit = randomDistance * distToHole.
otherwise
distHit = randomDistance * 10
swings = swings + 1
display “You have hit ball X” (distHit)
distToHole = absolute value of distToHole – distHit
display “distance to hole” + distToHole
display score
end loop
return playGolf
Function score(swings)
Input Processing Output
Swings score = absolute value of 5 -
swings
Path Condition Action
Under par Swing count < 5 Congratulations you are
score under par
Par Swing count = = 5 And that’s par
Over par Default Disappointing you are score
over par
Algorithm:
score = difference between 5 and swings
if swings < 5
display score
otherwise If swing = =5
display score
otherwise
display score

Mais conteúdo relacionado

Destaque

Vmarioneaux el7002 8-5
Vmarioneaux el7002 8-5Vmarioneaux el7002 8-5
Vmarioneaux el7002 8-5stormie2796
 
Presentación1
Presentación1Presentación1
Presentación1efren999
 
Act.19 sarb
Act.19 sarbAct.19 sarb
Act.19 sarb951219
 
La energía en el mundo sam
La energía en el mundo samLa energía en el mundo sam
La energía en el mundo samSandra Bello
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropboxkhurlee kosmos
 
Estantería qu2
Estantería qu2Estantería qu2
Estantería qu2tumaniqui
 
La energía en el mundo
La energía en el mundo La energía en el mundo
La energía en el mundo Sandra Bello
 
E catalogue (1)
E catalogue (1)E catalogue (1)
E catalogue (1)vinoth D
 
5 Surefire Ways to Grow Membership Using Data
5 Surefire Ways to Grow Membership Using Data5 Surefire Ways to Grow Membership Using Data
5 Surefire Ways to Grow Membership Using DataWebLink International
 
INFLUENCIA DE LA TECNOLOGIA EN LA EDUCACION
INFLUENCIA DE LA TECNOLOGIA EN LA EDUCACIONINFLUENCIA DE LA TECNOLOGIA EN LA EDUCACION
INFLUENCIA DE LA TECNOLOGIA EN LA EDUCACIONvivian_qui16
 
Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...
Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...
Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...Salesforce Partners
 

Destaque (19)

Diagramas
DiagramasDiagramas
Diagramas
 
Vmarioneaux el7002 8-5
Vmarioneaux el7002 8-5Vmarioneaux el7002 8-5
Vmarioneaux el7002 8-5
 
National_Service_Cert.
National_Service_Cert.National_Service_Cert.
National_Service_Cert.
 
Presentación1
Presentación1Presentación1
Presentación1
 
Act.19 sarb
Act.19 sarbAct.19 sarb
Act.19 sarb
 
La energía en el mundo sam
La energía en el mundo samLa energía en el mundo sam
La energía en el mundo sam
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
 
fotos
fotosfotos
fotos
 
Estantería qu2
Estantería qu2Estantería qu2
Estantería qu2
 
Cyber security
Cyber securityCyber security
Cyber security
 
La energía en el mundo
La energía en el mundo La energía en el mundo
La energía en el mundo
 
Resume 2016
Resume 2016Resume 2016
Resume 2016
 
Massage
MassageMassage
Massage
 
mohamed ramadan cv
mohamed ramadan cvmohamed ramadan cv
mohamed ramadan cv
 
E catalogue (1)
E catalogue (1)E catalogue (1)
E catalogue (1)
 
5 Surefire Ways to Grow Membership Using Data
5 Surefire Ways to Grow Membership Using Data5 Surefire Ways to Grow Membership Using Data
5 Surefire Ways to Grow Membership Using Data
 
INFLUENCIA DE LA TECNOLOGIA EN LA EDUCACION
INFLUENCIA DE LA TECNOLOGIA EN LA EDUCACIONINFLUENCIA DE LA TECNOLOGIA EN LA EDUCACION
INFLUENCIA DE LA TECNOLOGIA EN LA EDUCACION
 
Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...
Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...
Salesforce Member Connect Healthcare Payor Solution Partner Training (July 29...
 
ISLA Sustaining the Vision
ISLA Sustaining the VisionISLA Sustaining the Vision
ISLA Sustaining the Vision
 

Último

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Último (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Luke veltjensswana1

  • 1. CP1801 SP2 2015 – Assessment 1 Completed by Luke Veltjens-Swan S/N - 12627400 Functions: main This is the main function, upon starting it will display a prompt and ask the user to enter their name. The users name will be saved as a variable and then a welcome message will be displayed with userName. Then the menu will be displayed, it will show three options which are Play, Instructions and Quit. A loop starts after the menu which states that while the user does not want to quit, to loop back to the menu after either displaying instructions or playing a game of golf. Since the menu options rely on capital letter input for all three options if the user inputs a lowercase character than the program will convert it to uppercase. If the user enters any letter besides the three corresponding menu options then an error message is displayed. When the user decides to quit a goodbye message is displayed using userName. playGolf This function runs when the user inputs P on the menu, it starts the game of golf. First a message is displayed telling the user how far they are from the hole, it will always be 230m at the start of a game. An instructional message is then displayed letting the user know the controls. A loop starts where the exit condition is the distance to the hole being 0. The function then gets input from the user while checking for a correct input, if the user enters anything besides the three controls then the swing miss message is displayed and swings is increased by 1. The distance that the ball travels with each hit is calculated depending on the choice of club. With each swing the distance the ball travels is saved to a variable called distHit and after each swing the value of the new distance to hole is calculated, distToHole – distHit = new distance to hole. An absolute value is used for the distToHole to avoid negative distance issues. After each hit the distHit along with distToHole is displayed to the user. Upon distToHole being 0 the users score will be displayed at the end using the score function. Finally the function returns to the menu.
  • 2. score This function runs at the end of playGolf and it displays the users score in relation to par 5. Depending on the users score there are three types of finish messages that can be displayed.
  • 3. function main Input Processing Output userName menuChoice User selection Prompt Menu Menu Choice: Path Condition Action Instructions User inputs I Instructions are displayed Play User inputs P Game of golf begins Error message User inputs anything but I, P or Q Error message Menu loop: Loop variable: The user input Exit condition: Input is Q Algorithm: function main(): display prompt get userName from user display “welcome userName” display menu get menuChoice while menuChoice is not ‘Q’ if input is lowercase change to uppercase if input = ‘I’ display “instructions” otherwise if input = ‘P’ begin playGolf Otherwise display “error message” display menu get menuChoice end loop display goodbye userName
  • 4. function playGolf(menuChoice) Input Processing Output Type of club Current distance to hole = distToHole – distHit INITIAL_HOLE_DISTANCE DRIVER_DISTANCE IRON_DISTANCE PUTTER_DISTANCE PAR_5 MINIMUM_STRENGTH MAXIMUM_STRENGTH Current distance to hole. Distance ball is hit decision: Path Condition Action Driver Driver randomDistance * 100 Iron Iron randomDistance * 30 Putter Putter Make a decision based on distToHole Path Condition Action Putter hits 80-120% of distToHole distToHole is <=10 distHit = randomDistance * distToHole Putter hits 80-120% of putter strength. distToHole is > 10 distHit = randomDistance * 10 Invalid club loop: Loop variable: Club entered by user. Loop exit condition: Valid club selection. Game loop: Loop variable: The distance the ball is from the hole Loop exit condition: Distance to hole being 0.
  • 5. Algorithm: playGolf display “You are 230m from hole” display “Club selection: press D for driver, I for Iron, P for Putter.” distToHole = 230 swings = 0 repeat until distToHole = 0 get club from user while club is not ‘D’ or ‘I’ or ‘P’ display swing miss message swings = swings + 1 end loop randomDistance = random number between 80 and 120, divide by 100. if club = D distHit = randomDistance * 100 if club = I distHit = randomDistance * 30 if club = P if distToHole <=10 distHit = randomDistance * distToHole. otherwise distHit = randomDistance * 10 swings = swings + 1 display “You have hit ball X” (distHit) distToHole = absolute value of distToHole – distHit display “distance to hole” + distToHole display score end loop return playGolf
  • 6. Function score(swings) Input Processing Output Swings score = absolute value of 5 - swings Path Condition Action Under par Swing count < 5 Congratulations you are score under par Par Swing count = = 5 And that’s par Over par Default Disappointing you are score over par Algorithm: score = difference between 5 and swings if swings < 5 display score otherwise If swing = =5 display score otherwise display score