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
Programming an odds betting website Project Description: We want someone to program a odds betting website, Require someone with experience and skills! Skills required are

a program to accept average, if average is 75 to 85 print it out else bypass using counter. enter and process 5 records

what happens when the following command is used? chmod u=rwx,go=r-x foo

(a) Write a procedure (count-even n) that counts the number of even digits in the decimal representation of the number n. For example, (count-even 234) should return 2. (b) Writ

Define the Conditional Operator in c language? The Simple conditional operator can be carried out with the conditional operators (? And :). An expression that makes use of the

6999066263304447777077766622337778 -----> message sent by the first smuggler. my name is robert---------> message decoded by the second smuggler. Where ‘0’ denotes the "space".

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area .

You are to implement a code cracking system. The system will deploy four processes (p1,p2,p3 & p4) to try to guess the password of an encrypted code. For encryption, we consider th

Program to design list in c: Write a program in c to insert the values in list void main() { int i=0; char a[20]; clrscr(); printf("Enter the line\n");