Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
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°
}
double polar::convert(double t)
double x;
x=(PI/180)*t;
return(x);
double polar::revert(double t)
x=(180*t)/PI;
return (x);
void polar::getdata()
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°
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
A:1 cos 45° + 1 sin 45°
B:1 cos 45° + 1 sin 45°
After addition:
A + B = 2 cos 45° + 2 sin 45°
Various ways of initializing the Arrays. - The for loop initializes 10 elements with the value of their index. void main() { const in
A: By keeping along with the C++ tradition of "there's more than one method to do that" (translation: "give programmers options & tradeoffs so they can choose what's best for them
Write a C++ program to test the Bank Account class for 10 customers.
Question : (a) What is a structure? Provide a simple example of your own to illustrate this feature. (b) How does a structure differ from an array? (c) Describe a structu
why is count function used in c''
Define the Keywords of c language? C keeps a small set of keywords for its personal use. These keywords can't be used as identifiers in the program. Here is the list of keyword
limitations of increment operator
conceptual difference between big o,big thete and big omega
For this program you will add and test 2 new member functions to the IntSLList class posted on the website. The two member functions are: insertByPosn(int el, int pos) Assuming t
P o i n t er s to Members: In C a pointer is created to locate the address of another variable for faster access. Consider the following example. int x, *p; p =
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!
whatsapp: +1-415-670-9521
Phone: +1-415-670-9521
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd