Challenge: Calculating Area
Explore creating a Perl package named Triangle with public variables for length and height and a method to calculate the area of a right-angled triangle. Learn to implement setters, getters, and perform basic geometric calculations in Perl packages.
We'll cover the following...
We'll cover the following...
Problem statement
Let’s start with a very basic example.
Write a package called Triangle having two public variables for length and height and one member method called area which will return the area of the right angle triangle. You can calculate the area of a triangle using
Input
Two variables (integer or float) as the dimensions of the triangle.
Output
Area of that triangle.
Sample input
4, 5
Sample output
10
Coding challenge
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Good Luck!