OOP (313304) Practical No.7: Write a program to Implement the Friend Function using Two different classes Answer
The classes and objects help to represent real-life entities with different attributes and related member functions. The use of the friend function allows non-member functions to access the private and protected data of the class.
Friend Function: A friend function of a class is defined outside that class scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions. friend keyword is used to declare the function as a friend of the class.
OOP (313304) Practical No.7 Exercise:
1. Write a C++ program to exchange the values of two variables using the friend function.
Answer:
2. WAP to create two classes test1 and test2 which stores the marks of a student. Read the value for class objects and calculate the average of two tests using the friend function.
Answer:
Practical Related Questions
1. WAP to declare a class calculation. Display addition, subtraction, multiplication, and division of two numbers. Use the friend function.
Answer:
2. Complete the following table:
Answer:
Conclusion
We completed OOP (313304) Practical No.7 in which we wrote various C++ codes for Implement Friend Function using Two different classes and run them correctly.