CASE 1: Given two numbers a & b, swap these two numbers using the friend function of C++. Examples: Input : a = 5, b = 9 Output : a = 9, b = 5 Input : a = 4, b = 6 Output : a= 6, b = 4 Approach: Create a class Swap, declare one variable in it, i.e., num, and create a constructor for inputs. Declare a friend function in it. Define the friend function outside the class scope by taking arguments as call by reference to pass the copy of Swap Object. Perform the swap operation.
Charvik provides an education and shares Knowledge to reach your goals.