SlideShare una empresa de 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

Más contenido relacionado

Destacado

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
 

Destacado (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

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
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
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Último (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.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!
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

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