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
Need help with C network program

#quesdifferentiate betweenrelocatable and self relocating program with exampletion..

Programming Assignment #3: Vehicle Track Performance Tests Purpose: The purpose of this programming assignment is to give the student experience in using functions, arrays, and str

want the codings for these topic in ur experts minds.com

I need to make a fractal trees in OpenGL C++ . The method used is to write a recursive function with cylinders of different sizes and angles to create the tree trunk and branches.

WAP TO ACCEPT THE BASIC SALARY OF EMPLOYEES & CALCULATE NET SALARY   #include stdio.h> #include conio.h>   void main() {                    float Basi

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed

I. COURSE DESCRIPTION Develops a working knowledge of object-oriented concepts in areas of classes, inheritance, data structures, error handling, templates and file processing.

C Program for RADIUS OF CIRCLE   #define PI 3.14159 main() {           float r,a;           clrscr();           printf("ENTER THE RADIUS OF A CIRCLE: ");