Terminologies:
Triangle:
Any 3-sided shape called triangle, which are classified based on the lengths of their sides or the measures of their angles. Here are some of the most common types of triangles:
- Equilateral triangle: All three sides of an equilateral triangle are equal in length, and all three angles are also equal (60 degrees).
- Isosceles triangle: An isosceles triangle has two sides that are equal in length, and two angles that are also equal.
- Scalene triangle: A scalene triangle has no equal sides, and all three angles are also different.
- Right triangle: A right triangle has one angle that measures 90 degrees (a right angle). The side opposite the right angle is called the hypotenuse, and the other two sides are called the legs.
- Acute triangle: An acute triangle has all three angles that are less than 90 degrees.
- Obtuse triangle: An obtuse triangle has one angle that is greater than 90 degrees.
How to calculate the perimeter and area for a triangle?
Perimeter of a Triangle: The perimeter of a triangle is the sum of the lengths of its three sides. Perimeter = side1 + side2 + side3
Area of a Triangle: The area of a triangle can be calculated using different formulas, depending on the given information. Here are some common formulas:
- If the base and height are given: Area = (base * height) / 2
Quadrilateral:
Quadrilaterals are four-sided polygons that have four angles. There are several types of quadrilaterals, which are classified based on their properties. Here are some of the most common types of quadrilaterals:
- Square: A square is a quadrilateral with four equal sides and four right angles.
- Rectangle: A rectangle is a quadrilateral with four right angles. The opposite sides are equal in length.
- Rhombus: A rhombus is a quadrilateral with four equal sides. The opposite angles are equal in measure.
- Parallelogram: A parallelogram is a quadrilateral with opposite sides parallel to each other.
- Trapezoid: A trapezoid is a quadrilateral with one pair of parallel sides.
- Kite: A kite is a quadrilateral with two pairs of adjacent sides that are equal in length.
How to calculate the perimeter and area for a Quadrilateral?
Perimeter of a Quadrilateral: The perimeter of a quadrilateral is the sum of the lengths of its four sides. Perimeter = side1 + side2 + side3 + side4
Area of a Quadrilateral: The area of a quadrilateral can be calculated using different formulas, depending on the given information. Here are some common formulas:
- If the quadrilateral is a rectangle or square (base and height are given): Area = base * height
- If the quadrilateral is a parallelogram (base and height are given): Area = base * height
- If the quadrilateral is a rhombus (diagonals are given): Area = (diagonal1 * diagonal2) / 2
- If the quadrilateral is a trapezoid (height and two bases are given): Area = (base1 + base2) / 2 * height
- If the quadrilateral is a kite (diagonals are given): Area = (diagonal1 * diagonal2) / 2
The exercise objective:
The objective is to create a script that prompt the user to choose from:
- Triangle
- Quadrilateral
Based on the user’s choice, the script should instruct the user to input the measures of the shape’s side [i.e. if the user chose triangle, the script should ask about the measures of AB, BC, and CD sides in centimeters along with all the needful givens] and based on the user’s inputs, the script should print the following attributes:
- The shape type [i.e., for a triangle, whether its equilateral or isosceles, …etc.]
- The shape perimeter
- The shape area