Simple C++ rect2polar program @KTSI

1–2 minutes
No comments on Simple C++ rect2polar program @KTSI

This is another simple C++ program done for KTSI. This one converts rectangular to polar coordinates.

#include 
#include 

using namespace std;

void rect2polar(double &value, double &angle, double x, double y) {
    value = sqrt(pow(x, 2) + pow(y, 2));
    angle = 180 / M_PI * atan2(y,x);
}

int main(){
    double value;
    double angle;
    double x = 4;
    double y = 3;
	
    rect2polar(value, angle, x, y);
	
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
    cout << "value = " << value << endl;
    cout << "angle = " << angle << endl;
    //system("PAUSE");
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.