2.4P.pdf - Faculty of Science Engineering and Technology...

This preview shows page 1 - 4 out of 7 pages.

Faculty of Science, Engineering and Technology Introduction to Programming Pass Task 2.4: My Functions Overview Procedures are a great tool for capturing the instructions needed to perform a task, but some-times you need to be able to capture the instructions needed to calculate a value. Using func-tions you can now create artefacts to encapsulate the steps needed to calculate a value. Submission Details You must submit the following files to Doubtfire: Program source code demonstrating creation and use of a function Screenshot of the Terminal showing the execution of your program. Make sure that your task has the following in your submission: The program must use your function to calculate two fixed and one user . Code must follow the Pascal coding convention used in the unit (layout, and use of case). The code must compile and the screenshot show it working. Your program must demonstrate the use of functions with parameters, as well as constants.Purpose:Learn how to create your own functions.Task:Use the following instructions to implement a function and use it to calculate some values based on user input.Time:This task should be completed before the start of week 3.Resources:Chapter 4 of the Programming Arcana Swinburne CodeCasts (YouTube Channel, iTunesU) Creating your own Functions Syntax Videos Calling Functions, Creating Your Own Functions
Introduction to ProgrammingPass Task 2.4: My FunctionInstructions In programming, functions are used to calculate a value. They are very similar to procedures, with the added feature that they returna resultwhen they end. For example, the following program uses the Pi, Sqr and Round functions to calculate the area of a circle. Page of 27programCircleArea; usesTerminalUserInput; procedureMain(); varcirRadius, cirArea: Single; roundedValue: Integer;begin cirRadius := ReadInteger('Enter a radius: '); cirArea := Pi() * Sqr(cirRadius); WriteLn('Circles area is ', cirArea:4:2); roundedValue := Round(cirArea); WriteLn('Which rounded off has a value of ', roundedValue); end; begin Main(); end.Tip: The Free Pascal website has a list of all of the Mathematical functions available to all Pascal programs, as well as a list of units that you can use if you want access to addi-tional functionality.
Introduction to ProgrammingPass Task 2.4: My FunctionIn this program we could create a CircleAreafunction that calculates the area of a circle. That

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture