C++ program to calculate area of the circle if the radius is greater than 0 using goto statement.

Explanation

1. Pass-by-Value (calculateAreaByValue Function)

  • Definition:


    • Parameters: Accepts the radius of the circle as a parameter by value.
    • Operation:
      • The function calculates the area of the circle using the formula π * radius^2, where π is approximated as 3.14159.
      • Displays the calculated area.
    • Effect:
      • The original value of radius remains unchanged after the function call.

2. Pass-by-Reference (calculateAreaByReference Function)

  • Definition:


    • Parameters: Accepts the radius of the circle as a parameter by reference.
    • Operation:
      • The function calculates the area of the circle using the same formula as above.
      • Displays the calculated area.
    • Effect:
      • The radius variable is passed by reference, so any modifications to radius within the function would affect the original variable. However, in this case, the radius is not modified inside the function.

3. Input Validation Using goto

  • Label: The start label marks the point where the program should return if invalid input is entered.
  • Condition: The program checks if the entered radius is greater than 0.
  • Flow: If the radius is not greater than 0, the program prints an error message and prompts the user to re-enter the radius by jumping back to the start label.

Sample Output:

Key Points

  • Area Calculation:
    • The area of the circle is calculated using the formula π * radius^2.
    • The program approximates π as 3.14159.
  • Pass-by-Value:
    • The function receives a copy of the radius.
    • The original variable is unaffected by changes made inside the function.
  • Pass-by-Reference:
    • The function receives a reference to the radius.
    • Any changes to radius inside the function would affect the original variable, though in this case, the radius is not modified.
  • Input Validation with goto:
    • The goto statement is used to ensure the user enters a valid radius (greater than 0).
    • The program prompts the user to re-enter the radius if the input is invalid.