Geometry Calculation

Line: Loopy Line
Medium Difficulty Methods Learning Outcome One Learning Outcome Three Learning Outcome Four Exercise
Type: Exercise
You should have completed:

Breakdown

This topic leads to:

Method Comments

Summary

Methods package up parts of your programs into separate functions that can be run repeatedly from other parts of your code, or just used to simplify the main program and make it easier to read.

In this exercise you will develop methods for the problems posed, then combine them into a program.

Task

  1. Produce pseudocode and then methods for the following calculations
    1. The volume of a rectangular box. Hint: You will need three input parameters for height, width and length, and the return value will be the volume. Volume = length * width * height
    2. Determine if a triangle is right-angled from the lengths of the three sides. Hint: Use pythagoras theorem.
  2. Write code in your Main method to call each of these methods with some data and make sure they work.
  3. Now edit your Main method to ask the user which calculation they want, and then for the data required and use the correct method to calculate the answer
  4. Finally, give the user the option to perform another calculation or quit

Questions

  1. It is good practice to keep input functionality out of the methods that are actually performing the calculations and handle input separately. How would you also move the code for handling user input into separate method(s)?