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

C program for maximum no, C Program for MAXIMUM NO, MINIMUM NO AND SORTING ...

C Program for MAXIMUM NO, MINIMUM NO AND SORTING   void main() {           int i,j,t;           int a[5];           clrscr();           for(i=0;i

Explain the declaration of multi dimensional arrays, Explain the Declaratio...

Explain the Declaration of Multi Dimensional Arrays? In the figure, the range in the first dimension is 3 and in the second dimension is 4. The shaded portion corresponds to th

Matlab assignmnet, I have a Matlab assignment and I have the assignment des...

I have a Matlab assignment and I have the assignment description+ algorithm + and the output sample. the files are on a dropbox folder and you can download them from the link below

Define internal static storage class - computer programming, Define Interna...

Define Internal static storage class - computer programming? The Internal static variables are those that declared inside a function. The scope of the internal static variables

I want to convert atmel c code into arduino mppt, Normal 0 fals...

Normal 0 false false false EN-US X-NONE X-NONE

Program to calculate the average sales for each employee , There are 2...

There are 25 employees in a business. Each employee has 5 sales each day of the month (Assume there are 30 days in each month of the year). Draw a flowchart for a pr

Array-based Lists and Array-based Queues, Objectives: The objective of this...

Objectives: The objective of this assignment is to use C++ to queue students into an array-based queue for BCS registration. Students have the option of taking five different cours

How do i allocate multidimensional arrays by new? , Can I free() pointers a...

Can I free() pointers allocated  along with new? Can I delete pointers allocated along with malloc()? A: No. It is completely legal, moral, and wholesome to employ malloc() a

If i wish a local to "die" before the close} of the scope, What if I wish a...

What if I wish a local to "die" before the close} of the scope wherein it was created? Can I call a destructor on a local if I want to?

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