Exercise: Calculating Area
This is a basic exercise on defining a class that helps calculate the area of a triangle.
We'll cover the following
Problem Statement
Let’s start with a very basic example.
Write a class called Triangle
having two public
variables for length
and height
and one member function 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!
Note: There is a
test
function given in the code for testing purposes. Do not modify it.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy