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

Assignment Help:

 

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°

 


Related Discussions:- C program to add two polar coordinates

Destruction of local object, Need assignment help What's the order that ...

Need assignment help What's the order that local objects are destructed?

We need to decompile ex4 to mq4, We need to Decompile ex4 to mq4 I have ...

We need to Decompile ex4 to mq4 I have three expert advisors for mt4, which I need to decompile to its original mq4 code. Skills required are C Programming, C++ Programming,

#task1, program for factorial

program for factorial

Determine the total resistance of the circuit, For the circuit shown in Fig...

For the circuit shown in Figure, verify (a) the battery voltage V , (b) the total resistance of the circuit, and (c) the values of resistance of resistors R 1 , R 2 and

C program to check display days and months , C program to check display ...

C program to check display days and month main() {           int months, days;           clrscr();           printf("ENTER DAYS: ");           scanf("%d", &days);

Hep, I need help with a c# program. Do yall help with c sharp

I need help with a c# program. Do yall help with c sharp

Pebble merchant, 3 kilograms of peebles are needed for converting an area o...

3 kilograms of peebles are needed for converting an area of 1 square meter.the rate of the peeble is 5 per kilogram

Declaration of variables in cpp, Declaration of Variables: Variables ar...

Declaration of Variables: Variables are declared as follows: int a; float b;   Assigning value to variables: int a = 100; Declaring and assigning is called ini

#palindrome, replace character into string and return value of string that ...

replace character into string and return value of string that are replaced

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd