Answer to Question #321607 in C++ for kalios

Question #321607

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.


1
Expert's answer
2022-06-23T08:19:30-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog