#include<iostream.h>
#include<string.h>
class circle{
private:
int r,ar,c;
public:
circle (int r1){r=r1;}
int area(){
ar=(r*r*3.14);
return ar;
}
int cir(){
c=(2*3.14*r) ;
return c;
}
void display(){
cout<<"\nFirst circle:\n";
cout<<"area = "<<area();
cout<<"\ncir = "<<cir();
cout<<"\n\nSecond circle:\n";
cout<<"area = "<<area();
cout<<"\ncir = "<<cir();
}
friendvoid compare(circle a, circle b);
};
void compare(circle a, circle b){
if (a.r > b.r) {
cout<<"\nThe first circle is bigger";
}
elseif (a.r<b.r){
cout<<"\nThe second circle is bigger";
}
else cout<<"\nThey are both the same size";
}
void main(){
int r1,r2;
cout<<"Enter the radius of the first circle:\n";
cin>>r1;
cout<<"\nEnter the radius of the second circle:\n";
cin>>r2;
circle c1(r1);
circle c2(r2);
circle *c3;
c3=&c1,c2;
c3->display();
compare(c1,c2);
}
Line 39 is always int main() { if your compiler allows this - it means it is really old like Borland Turbo C++ - get a new one if you can - there are plenty of free ones.
You can avoid using the friend function by providing a public interface to your class. That is, have a public function which returns the value of r.
int main(){
int r1,r2;
cout<<"Enter the radius of the first circle:\n";
cin>>r1;
cout<<"\nEnter the radius of the second circle:\n";
cin>>r2;
circle c1(r1);
circle c2(r2);
circle *c3;
c3=&c1,c2; // this is equivalent to c3 = &c1; c2 ; So c3 points to c1 and only c1.
c3->display(); // so this will display c1, and only c1.
cout << "First circle:\n" ;
c1.display() ;
cout << "Second circle:\n";
c2.display() ;
compare(c1,c2);
}
@theideasman ,
this question was given to me in my exam so when i asked the instructor why did she ask us to put int instead of double or unsigned she said it was easier for her when grading the exam ,so i just gave in !
and yes i do have turbo borland c++ i did not know there were newer ones since we use the sam one in our lab
also the friend function was a given in the question
lastly thank you very much
@cire thank you know i know where i went wrong !
its always the stupidest things with me :( ,at least i know i wont make the same mistake again . thank you again !