Programming 11/12: VB Assignment 3 – Triangular Area

For this assignment, you will create a program that calculates the area of a triangle given the length of the three sides. It is strongly recommended that you calculate the area by applying Heron’s formula:

T = \sqrt{s(s-a)(s-b)(s-c)}

where

s=\frac{a+b+c}{2}.

The area needs to be rounded to 1 decimal place (i.e. nearest tenths). The program needs to consider if the lengths are invalid inputs such as non-numeric strings and negative numbers. In addition, the longest side cannot exceed the sum of the two shorter sides based on the law of triangular inequality.

Test Cases:

  • Valid Inputs:
    • Right Triangle: a = 5, b = 12, c = 13 → Area = 30
    • Isosceles: a = 6, b = 5, c = 5 → Area = 12
    • Equilateral: a = 5, b = 5, c= 5 → Area = 10.8
    • Scalene: a = 7, b = 8, c = 9 → Area = 26.8
    • Line Segment: a = 1, b = 2, c = 3 → Area = 0
  • Invalid:
    • Negative side(s): a = -5, b = -5, c = 5
    • Non-numeric string: a = one, b = 2, c = 2
    • Inconstructable: a = 1, b = 2, c = 10

Evaluation: 10 marks

  • Test Cases: 8 marks (1 mark each)
  • Interface: 1 mark
  • Rounding: 1 mark