C++ Program to take value from the user as an input weekday number and print weekday by using user define functions. Weekday program

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 3, 2024

Explanation:

  1. Pass-by-Value (getWeekdayByValue):
    • Function Definition: void getWeekdayByValue(int day)
    • This function takes the integer day by value.
    • It uses a switch statement to determine the weekday based on the number.
    • It prints the corresponding weekday directly.
  2. Pass-by-Reference (getWeekdayByReference):
    • Function Definition: void getWeekdayByReference(int day, string &weekday)
    • This function takes the integer day by value and a reference to a string variable weekday.
    • It uses a switch statement to determine the weekday and sets the weekday reference variable accordingly.
    • The result is updated through the reference variable.
  3. Main Function (main):
    • Prompts the user to input a weekday number (from 1 to 7).
    • It uses both pass-by-value and pass-by-reference methods to get and display the weekday name.

Example Outputs:

Example 1:

Input:

  • Day number: 3

Output:

Example 2:

Input:

  • Day number: 6

Output:

Example 3:

Input:

  • Day number: 8

Output: