C program to add two polar coordinates, C/C++ Programming

 

Aim: To implement a program to add two polar coordinates using operator overloading.

Code:                      

#define PI 3.14

class polar

{

            double theta;

            double r;

            public:

            void getdata();

            void display();

            double convert(double);

            double revert(double);

            polar operator+(polar p2);

};

void polar::display()

{

            double t;

            cout<

}

double polar::convert(double t)

{

            double x;

            x=(PI/180)*t;

            return(x);

}

 

double polar::revert(double t)

{

            double x;

            x=(180*t)/PI;

            return (x);

}

 

void polar::getdata()

{

            double t;

            cout<<"Enter value of 'r':";

            cin>>r;

            cout<<"Enter value of 'é':";

            cin>>theta;

}

 

polar polar::operator+(polar p2)

{

   polar p3;

   double x,y,t1,t2,t;

   t1=convert(theta);

   t2=convert(p2.theta);

   x=(r*cos(t1))+(p2.r*(cos(t2)));

   y=(r*sin(t1))+(p2.r*(sin(t2)));

   t=atan(y/x);

   p3.theta=revert(t);

   p3.r=sqrt((x*x)+(y*y));

   return(p3);

}

 

void main()

{

            polar p1,p2,p3;

            clrscr();

            p1.getdata();

            p2.getdata();

            cout<

            p1.display();

            cout<<"\nB:";

            p2.display();

            p3=p1+p2;

            cout<<"\n\nAfter addition:\n\nA + B = ";

            p3.display();

            getch();

}

Output:

Enter value of 'r':1

Enter value of 'Θ':45

Enter value of 'r':1

Enter value of 'Θ':45

 

A:1 cos 45° + 1 sin 45°

B:1 cos 45° + 1 sin 45°

After addition:

A + B = 2 cos 45° + 2 sin 45°

 

Posted Date: 9/29/2012 4:03:04 AM | Location : United States







Related Discussions:- C program to add two polar coordinates, Assignment Help, Ask Question on C program to add two polar coordinates, Get Answer, Expert's Help, C program to add two polar coordinates Discussions

Write discussion on C program to add two polar coordinates
Your posts are moderated
Related Questions
Static Data Members: A data member inside the class can construct as static data member.   There are few guidelines to be followed when declaring static data member.

Develop Diablo 2 LOD 1.13d Dupe Method for Closed Battle.net This hack is for diablo 2 lord of destruction The program must work on all realms, all cores, all ladders (4x rea

coloring of elements in matrix form inm particular matrix.the color should not match with another color.

Problem: (a) Using a class hierarchy of your own choosing, with at least TWO subclass levels, show (i) the use of abstract and concrete forms of Java class and method in you

The STL details are described in many places online (see the CS377 webpage for some links), and there's a very quick introduction in Section A.14. Here are just a few additional no

Tell what the derived class inherits or doesn't inherit? A: Inherits: - All data member defined in the parent class (even though such members might not always be accessible

If we take the input image and smooth it with a Gaussian of a significant size before computing the Canny edges does the number of edges change, and do the locations of these edges

Temperature Conversions. Problems 28 through30generate temperature-conversion tables. Use the following equations that give relationships between temperatures in degrees Fahrenheit

Write a program to define a matrix: 1. Write a function that takes an integer and calculates and returns the factorial of the integer. The Factorial of a number "n" is compute

The break statement The break statement, which was already covered in the switch.. case, can also be used in the loops. When a loop statement is encountered in the loops the co