Â
The Code given below can be used in TURBO C++ Compilers: -
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
class sample
{
int length, breadth;
public:
sample(int length, int breadth) : length(length), breadth(breadth)
{
}
friend void calcArea(sample s); //friend function declaration
};
//friend function definition
void calcArea(sample s)
{
cout << "Area of Rectangle = " << s.length * s.breadth;
}
void main()
{
int len, bdth;
cout << "Enter length and breadth: \n";
cin >> len >> bdth;
sample s(len, bdth);
calcArea(s);
getch();
}
//.........Coded by JAIDEEP JAMBHALE
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
#include <string>
using namespace std;
class sample
{
int length, breadth;
public:
sample(int length, int breadth) : length(length), breadth(breadth)
{
}
friend void calcArea(sample s); //friend function declaration
};
//friend function definition
void calcArea(sample s)
{
cout << "Area of Rectangle = " << s.length * s.breadth;
}
int main()
{
int len, bdth;
cout << "Enter length and breadth: \n";
cin >> len >> bdth;
sample s(len, bdth);
calcArea(s);
return 0;
}
//.........Coded by JAIDEEP JAMBHAL
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP