Write a program to accept five different numbers by creating a class called friend func1 and friend func2 taking 2 and 3 arg respectively and calculate the average of these numbers by passing object of the class to friend function.
#include <iostream>
using namespace std;
class friend_func2;
class friend_func1 {
protected:
int a, b;
public:
friend_func1(int a, int b) { this->a = a; this->b = b; }
friend void operator<<(friend_func1 a, friend_func2 c);
};
class friend_func2 {
protected:
int c, d, e;
public:
friend_func2(int c, int d, int e) { this->c = c; this->d = d; this->e = e; }
friend void operator<<(friend_func1 a, friend_func2 c);
};
int main() {
int first, second, third, fourth, fifth;
cout << "Enter 1st number: ";
cin >> first;
cout << "Enter 1st number: ";
cin >> second;
cout << "Enter 1st number: ";
cin >> third;
cout << "Enter 1st number: ";
cin >> fourth;
cout << "Enter 1st number: ";
cin >> fifth;
friend_func1 friend1(first, second);
friend_func2 friend2(third, fourth, fifth);
friend1 << friend2;
return 0;
}
void operator<<(friend_func1 a, friend_func2 c){
cout << (float)(a.a+a.b+c.c+c.d+c.e)/5;
}
Comments
Leave a comment