Answer to Question #232349 in C++ for Arup

Question #232349

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.


1
Expert's answer
2021-09-02T12:52:16-0400
#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);
	
	
}





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
APPROVED BY CLIENTS