Write a program to accept five different numbers by creating a class called friendfunc1 and friendfunc2 taking 2 and 3 arg respectivly and calculate the average of these numbers by passing object of the class to friend function.





Implementation of the above problem:
#include <iostream.h>
#include<conio.h>
class friendfunc
{
float a,b,c,d,e;
friend void cal_avg(friendfunc &);
public:
void get_data()
{
cout<<"\nEnter 5 different values:\n";
cin>>a>>b>>c>>d>>e;
}
};
void cal_avg(friendfunc &f)
{
float avg=(f.a+f.b+f.c+f.d+f.e)/5;
cout<<"Average ="<<avg;
}
void main()
{
clrscr();
friendfunc ob;
ob.get_data();

cal_avg(ob);
getch();
}





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments:

  1. this code had many bugs to fix and many errors

    ReplyDelete