Friday, January 9, 2015

Calcuating Areas using Objects in C++

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
class rectangle;
class polar
{
public: float radius;
 float angle;
public: void getdata()
{
cout<<"enter the redius";
cin>>radius;
cout<<"Enter the angle";
cin>>angle;
}
float getradius()
{
return radius;
}
float getangle()
{
return angle;
}

void show()
{
cout<<"RADIUS: "<<radius<<endl;
cout<<"ANGLE: "<<angle<<endl;
}



};
class rectangle
{
protected:float x;
float y;
public:
rectangle()
{
x=0;
y=0;
}
float getx()
{
return x;
}
float gety()
{
return y;
}
rectangle operator +(rectangle p)
{
rectangle w;
w.x=x+p.x;
w.y=y+p.y;
cout<<"w="<<w.x<<"  "<<w.y<<endl;
return w;
}
rectangle(polar a1)
{
float a,r;
a=(a1.getangle())*3.14/100.0;
r=a1.getradius();
x=r*cos(a);
y=r*sin(a);
cout<<"x="<<x<<endl<<"y="<<y<<endl;
}
operator polar()
{
float  p,q;
polar a;
p=getx();
q=gety();
cout<<"p="<<p<<endl<<"q="<<q<<endl;
a.radius=sqrt(p*p+q*q);
a.angle=atan(p/q);
return a;
}
friend polar operator +(polar p,polar q)
{
      polar r;
      rectangle a,b,c;
      a=p;
      b=q;
      c=a+b;
      r=c;
      cout<<"r="<<r.radius<<endl;
      return r;
}
};
void main()
{
polar a,b,c;
a.getdata();
b.getdata();
c=a+b;
c.show();

}


for more codes you can Visit http://codesofprogramming.blogspot.in/

No comments:

Post a Comment