Â
The Code given below can be used in TURBO C++ Compilers: -
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
class integer
{
int a, b;
public:
void set_value()
{
cout << "Enter two numbers: \n";
cin >> a >> b;
}
friend int mean(integer s); //declaration of friend function
};
int mean(integer s)
{
return int(s.a + s.b) / 2.0; //friend function definition
}
void main()
{
integer c;
c.set_value();
cout << "Mean value: " << mean(c);
getch();
}
//.........Coded by JAIDEEP JAMBHALE
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class integer
{
int a, b;
public:
void set_value()
{
cout << "Enter two numbers: \n";
cin >> a >> b;
}
friend int mean(integer s); //declaration of friend function
};
int mean(integer s)
{
return int(s.a + s.b) / 2.0; //friend function definition
}
int main()
{
integer c;
c.set_value();
cout << "Mean value: " << mean(c);
return 0;
}
//.........Coded by JAIDEEP JAMBHALE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP