Last active
September 17, 2020 09:08
-
-
Save krysseltillada/caf95f4f018356cabbcf to your computer and use it in GitHub Desktop.
polar to cartesian converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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