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