هدا برنامج يقو م بمقارنة دائرتين وهو مثال تحت درس الدوال الصديقة .كيف يمكن تطويره حتى يقارن ثلاث دوائر
#include <iostream>
#include <cstdlib>
using namespace std;
class circle
{int r;
float ar,c;
public:
circle(int r1){r=r1;}
void area()
{
ar=3.14*r*r;
}
void cir()
{
c=2*3.14*r;}
void display()
{cout<<"area"<<ar<<endl;
cout<<"cir"<<c<<endl;
}
friend bool compare(circle,circle);};
bool compare(circle c1,circle c2)
{return c1.r>c2.r;}
int main()
{int r1,r2;
cout<<"entre radios r1"<<"\n";
cin>>r1;
cout<<"entre the radios r2"<<"\n";
cin>>r2;
circle cc1(r1),cc2(r2);
cc1.area();
cc1.cir();
cc1.display();
cc2.area();
cc2.cir();
cc2.display();
if(compare(cc1,cc2))
cout<<"r1 is greator";
else
cout<<"r2 is greator";
system("pause");
return 0;
}