C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program that performs addition operation of 2 polar objects by + operator overloading.

Posted By: Easy Tutor     Category: C++ Programming     Views: 42942

Write a program that performs addition operation by overloading + operator. To perform addition operation below is the formula need to be implemented.

x = (r1 * cos(a1)) + (r2 * cos(a2))
y = (r1 * sin(a1)) + (r2 * sin(a2))

r = sqrt(x*x + y*y) -- New radius
a = atan(y/x) -- New angle

Code for Program that performs addition operation of 2 polar objects by + operator overloading. in C++ Programming

#include <iostream.h>
#include <math.h>
#include <conio.h>

class polar
  double radius;
  double angle;

  double getx()
    {return radius*cos(angle);} //These two functiondouble gety()                 //convert this polar objects
    {return radius*sin(angle);} //into x and y rectangular coordspublic:

   polar(float r,float a)

   void display()
      cout<<"("<<radius<<", "<<angle<<")";

  polar operator + (polar o2)
    double x=getx()+o2.getx();
    double y=gety()+o2.gety();
    double r=sqrt(x*x + y*y);   //converts x and y todouble a=atan(y/x);         //Polar co-ordinate.return polar(r,a);

void main()
 polar o1(10,2),o2(10,5),o3;


 cout<<"\no1 =";
 cout<<"\no2 =";
 cout<<"\no3 =";


Easy Tutor
Easy Tutor author of Program that performs addition operation of 2 polar objects by + operator overloading. is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Happy Programming :)

View All Articles

Related Articles and Code:

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

Sarat Kumar from Australia Comment on: Nov 15
Create a class MAT of size m*n. Define all possible matrix operations for MAT type objects. Use operator overloading functions

View All Comments