SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

Diagramas
DiagramasDiagramas
Diagramas
RafaelDavid07
 
Vmarioneaux el7002 8-5
Vmarioneaux el7002 8-5Vmarioneaux el7002 8-5
Vmarioneaux el7002 8-5
stormie2796
 
Presentación1
Presentación1Presentación1
Presentación1
efren999
 
Act.19 sarb
Act.19 sarbAct.19 sarb
Act.19 sarb
951219
 
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
Sandra Bello
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
khurlee kosmos
 
fotos
fotosfotos
fotos
marcelino4
 
Estantería qu2
Estantería qu2Estantería qu2
Estantería qu2
tumaniqui
 
Cyber security
Cyber securityCyber security
Cyber security
Luke Veltjens-Swan
 
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
 
Resume 2016
Resume 2016Resume 2016
Resume 2016
kumar shashi kant
 
Massage
MassageMassage
Massage
Claudia Varez
 
mohamed ramadan cv
mohamed ramadan cvmohamed ramadan cv
mohamed ramadan cv
Mohamed Ramadan
 
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 Data
WebLink 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 EDUCACION
vivian_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
 
ISLA Sustaining the Vision
ISLA Sustaining the VisionISLA Sustaining the Vision
ISLA Sustaining the Vision
Elizabeth Dudley-Bestow
 

Viewers also liked (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
 

Recently uploaded

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 

Recently uploaded (20)

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 

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