In this challenge you should write a program that calculates the area of different shapes. It is a chance for you to practice basic maths inside a program amongst other skills. I would approach it something like:
- Create a program that will calculate the area of a rectangle.
- Use an IF statement to ask the user which shape they would like to calculate the area of.
- Add an option for a Triangle.
- Import the maths library and use it to calculate the area of a Circle.
- At this point you might think about using methods to split your code up into small manageable chunks.
Flowchart Description of the Algorithm.
Write a program to calculate the surface area of the following shapes: a square, a cube, a pyramid, and a cylinder. Ask the user which shape he would like to calculate the area for, and the dimensions that are needed for the calculation.
The formulæ for each shape follows.
- Area of a cube: 6 X (Length of side)2
- Area of a pyramid: (Number of faces X Length of base X Height) / 2
- Area of cylinder : 2?Radius X Height