C++ Program to check whether the triangle is an equilateral, isosceles or scalene triangle. Using the user define functions.

Explanation:

  1. Pass-by-Value (triangleTypeByValue):
    • Function Definition: string triangleTypeByValue(double side1, double side2, double side3)
    • This function takes three sides of a triangle as input parameters by value.
    • It determines the type of triangle based on the side lengths:
      • Equilateral: All three sides are equal.
      • Isosceles: Two sides are equal.
      • Scalene: All three sides are different.
    • If any side length is non-positive, the function returns "Invalid".
    • It returns a string indicating the type of triangle.
  2. Pass-by-Reference (triangleTypeByReference):
    • Function Definition: void triangleTypeByReference(double side1, double side2, double side3, string &triangleType)
    • This function also takes three sides of a triangle as input, but uses a reference variable triangleType to store the result.
    • It calculates the type of triangle using the same conditions and updates the triangleType reference variable.
  3. Main Function (main):
    • The program prompts the user to input the three sides of the triangle.
    • It determines the type of triangle using both methods and prints the results.

Example Outputs:

Example 1:

Input:

  • Side 1: 5
  • Side 2: 5
  • Side 3: 5

Output:

Example 2:

Input:

  • Side 1: 5
  • Side 2: 5
  • Side 3: 8

Output:

Example 3:

Input:

  • Side 1: 3
  • Side 2: 4
  • Side 3: 5

Output:

Example 4:

Input:

  • Side 1: 0
  • Side 2: 5
  • Side 3: 5

Output: