Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Last active September 17, 2020 09:08
Show Gist options
  • Select an option

  • Save krysseltillada/caf95f4f018356cabbcf to your computer and use it in GitHub Desktop.

Select an option

Save krysseltillada/caf95f4f018356cabbcf to your computer and use it in GitHub Desktop.
polar to cartesian converter
/// this is just some code snippets i do in some exercise in the book i'vs studied i thought it could be useful to some people
/// about this class
/// object.CoordDisplay(); - displays the converted values
/// object.conToCartesian(); - converts the following argument values into cartesian values
/// you can edit this code if you want
//// declare a class Coord before using one of the class methods..
#include <iostream>
#include <cmath>
using namespace std;
class Coord{
private:
double xval;
double yval;
public:
Coord(double x = 0, double y = 0)
{xval = x; yval = y;}
void CoordDisplay();
void convToCartesian(double, double);
};
void Coord::CoordDisplay()
{
cout << "cartesian coordinates"
<< "\nx: " << xval
<< "\ny: " << yval << endl;
return;
}
void Coord::convToCartesian(double r, double theta)
{
xval = r * cos(theta);
yval = r * sin(theta);
return;
}
int main()
{
Coord a;
a.convToCartesian(12,12);
a.CoordDisplay();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment