C++ Program to take a value from the user as input all sides of a triangle and check whether the triangle is valid or not. Using user define functions.

Explanation:

  1. Pass-by-Value (isTriangleValidByValue):
    • Function Definition: bool isTriangleValidByValue(double side1, double side2, double side3)
    • This function takes three sides of a triangle as input parameters by value.
    • It checks if the triangle is valid using the triangle inequality theorem, which states that the sum of any two sides must be greater than the third side.
    • It returns true if the triangle is valid, otherwise it returns false.
  2. Pass-by-Reference (isTriangleValidByReference):
    • Function Definition: void isTriangleValidByReference(double side1, double side2, double side3, bool &isValid)
    • This function takes three sides of a triangle as input and a reference variable isValid to store the result.
    • It calculates whether the triangle is valid using the same triangle inequality theorem and updates the isValid reference variable.
  3. Main Function (main):
    • The program prompts the user to input the three sides of the triangle.
    • It checks if the triangle is valid using both methods and prints the results.

Example Outputs:

Example 1:

Input:

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

Output:

Example 2:

Input:

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

Output:

Example 3:

Input:

  • Side 1: 6
  • Side 2: 8
  • Side 3: 10

Output: