Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
1
Indexable
#include<iostream>
using namespace std;

class rectangle{
	float length;
	float breadth;
	float area;
	public:
		void input(){
			cout<<"Enter the length of the Rectangle: ";
			cin>>length;
			cout<<"Enter the breadth of the Rectangle: ";
			cin>>breadth;
		}
		void display(){
			cout<<"\nThe length of the Rectangle is: "<<length<<"\n";
			cout<<"The breadth of the Rectangle is: "<<breadth<<"\n";
			cout<<"The area of the Rectangle is: "<<area<<"\n";
		}
		void calc_area(){
			area=length*breadth;
			cout<<"\nThe area of the Rectangle is: "<<area<<"\n";
		}
		friend void compare(rectangle a, circle b);
};

class circle{
	float radius;
	float pi;
	float area;
	public:
		void input(){
			cout<<"Enter the radius of the Circle: ";
			cin>>radius;
		}
		void display(){
			cout<<"\nThe radius of the Circle is: "<<radius<<"\n";
			cout<<"The area of the circle is: "<<area<<"\n\n";
		}
		void calc_area(){
			pi=3.14;
			area=pi*radius*radius;
			cout<<"\nThe area of the circle is: "<<area<<"\n";
		}
		friend void compare(rectangle a,circle b);
};                     

void compare(rectangle a, circle b){
	if(a.area==b.area){
		cout<<"\nBoth have equal areas.\n";
	}
	else if(a.area>b.area){
		cout<<"\nThe area of Rectangle is greater.\n";
	}
	else{
		cout<<"\nThe area of Circle is greater.\n";
	}
}

int main(){
	rectangle a;
	circle b;
	a.input();
	a.calc_area();
	a.display();
	b.input();
	b.calc_area();
	b.display();
	compare(a,b);
	
	return 0;
}