C++ Program to take a value from the user as input the month number and print number of days in that month. Using user define functions.

Explanation:

  1. Pass-by-Value (getDaysInMonthByValue):
    • Function Definition: void getDaysInMonthByValue(int month)
    • This function takes the month number month as a parameter by value.
    • It uses a switch statement to determine the number of days in the month.
    • It prints the result directly.
  2. Pass-by-Reference (getDaysInMonthByReference):
    • Function Definition: void getDaysInMonthByReference(int month, int &days)
    • This function takes the month number month by value and a reference to an int variable days.
    • It uses a switch statement to determine the number of days and updates the days reference variable accordingly.
    • The result is updated through the reference variable, and the function does not print directly. Instead, it relies on the main function to handle the output.
  3. Main Function (main):
    • Prompts the user to input a month number (from 1 to 12).
    • It uses both pass-by-value and pass-by-reference methods to get and display the number of days in the month.

Example Outputs:

Example 1: Input:
  • Month number: 2
Output: Example 2: Input:
  • Month number: 4
Output: Example 3: Input:
  • Month number: 13
Output:  
All Copyrights Reserved 2025 Reserved by T4Tutorials