43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
|
/* CSCI 200: Lab 2C (Coordinate Conversion By Pointer): Tyler Beckman
|
||
|
*
|
||
|
* Author: Tyler Beckman
|
||
|
*
|
||
|
* TODO
|
||
|
*/
|
||
|
#include "coordinate_conversion.h"
|
||
|
|
||
|
#include <iostream>
|
||
|
|
||
|
int main(void) {
|
||
|
char direction = 'P';
|
||
|
|
||
|
std::cout << "Which coordinate system would you like to convert to? [P]olar - (x, y) -> (r, θ), or [C]artesian - (r, θ) -> (x, y)? ";
|
||
|
std::cin >> direction;
|
||
|
|
||
|
double radius = 0;
|
||
|
double angle = 0;
|
||
|
double xCoordinate = 0;
|
||
|
double yCoordinate = 0;
|
||
|
|
||
|
switch (direction) {
|
||
|
case 'P':
|
||
|
std::cout << "Please enter the (x, y) coordinates, separated by a space: ";
|
||
|
std::cin >> xCoordinate >> yCoordinate;
|
||
|
|
||
|
cartesian_to_polar(xCoordinate, yCoordinate, &radius, &angle);
|
||
|
|
||
|
std::cout << "The result (r, θ) is: (" << radius << ", " << angle << ")";
|
||
|
break;
|
||
|
case 'C':
|
||
|
std::cout << "Please enter the (r, θ) coordinates, separated by a space: ";
|
||
|
std::cin >> radius >> angle;
|
||
|
|
||
|
polar_to_cartesian(radius, angle, &xCoordinate, &yCoordinate);
|
||
|
|
||
|
std::cout << "The result (x, y) is: (" << xCoordinate << ", " << yCoordinate << ")";
|
||
|
break;
|
||
|
default:
|
||
|
std::cout << "\"" << direction << "\" is not a valid option, exiting";
|
||
|
return 1;
|
||
|
}
|
||
|
}
|