Write a program to find out the area of an rectangle be defining a class named as Rectangle having length and breadth as its data members. Declare another class named as Rectangle Area having one member function named as area to calculate the area by taking the data length and breadth from the Rectangle class. Solve this by using friend class.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Rectangle{
public:
int length;
int breadth;
Rectangle()
{
}
void set(int x, int y)
{
length = x;
breadth = y;
}
};
class Rectangle_Area : public Rectangle{
public:
int area;
int a;
int b;
int calc()
{
length*breadth;
}
friend int calculate_Area(Rectangle_Area ob);
};
int calculate_Area(Rectangle_Area ob)
{
return ob.length * ob.breadth;
}
int main()
{
Rectangle_Area r;
r.set(5,6);
cout<<"Area of rectangle : "<<calculate_Area(r);
}
Comments
Leave a comment