Written by 11:10 am School

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;
}

Tags: , , , , , , , , , , , Last modified: July 5, 2019
Close Search Window
Close