Tasks This project consists of 3 tasks: Task 1 Write a method that takes as inpu
ID: 3674710 • Letter: T
Question
Tasks
This project consists of 3 tasks:
Task 1
Write a method that takes as input parameters a pair of Cartesian coordinates and which sets as output parameters a pair of polar coordinates corresponding to the same point as the input Cartesian coordinates. Use degrees for output angles.
Task 2
Write a main program that:
prompts a user to input several pairs of positive Cartesian coordinates, one pair per line and separated by spaces. The user may enter up to 50 pairs, and the user will say he/she is done by inputting the coordinate pair (0, 0). Store the pairs in a pair of parallel arrays as you read them in.
shifts all coordinates to the right by 4 units and up by 7 units.
converts all shifted coordinate pairs to polar coordinates by calling the method you wrote.
prints lines showing both the input coordinates and output coordinates as ordered pairs in the style of this example: (4, 1) ---> (11.3137, 45)
Task 3
After successfully compiling and testing your program, change it to accept up to 100 coordinate pairs instead of up to 50. Also change the coordinate shift to be up 6 and to the right by 2.))))))
This is a sample interaction for the program before doing Task 3: Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 4 1 Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 1 4 Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 10 12 Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 1.1 4.5 Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 3 10.3 Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 10 7 Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: 0 0 Coordinates [inputs ---> polar]:
================================
(4, 1) ---> (11.3137, 45)
(1, 4) ---> (12.083, 65.556)
(10, 12) ---> (23.6008, 53.6156)
(1.1, 4.5) ---> (12.5801, 66.0838)
(3, 10.3) ---> (18.6625, 67.9705)
(10, 7) ---> (19.799, 45)
Explanation / Answer
TASK 1
double polar(double x, double y)
// method that takes as input parameters a pair of Cartesian coordinates
{ // and returns the polar co-ordinate
const double toDegrees = 180.0/3.141593;
double polar = atan(y/x) * toDegrees;
return polar;
}
TASK 2
#include <iostream>
#include <math.h>
using namespace std;
double getrec(double x[], double y[])
{ int count = 0;
while(count < 50) // 50 inputs for task 2 or 0 0 to break the input
{
cout << "Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: ";
cin >> x[count]>> y[count];
if(x[count] == 0 && y[count] == 0) break;
count++;
}
return count;
}
double polar(double x, double y) // method that takes as input parameters a pair of Cartesian coordinates
{ // and returns the polar co-ordinate
const double toDegrees = 180.0/3.141593;
double polar = atan(y/x) * toDegrees;
return polar;
}
int main()
{
const int SIZE = 50;
double x[SIZE];
double y[SIZE];
double distance;
double angle;
double count = getrec(x,y); // getting input
cout<< " Coordinates [inputs ---> polar]: ";
cout<< "================================= ";
for(int i =0; i < count; i++)
{
double radius = sqrt((pow(x[i]+4,2))+(pow(y[i]+7,2))); // in task 2 , 4 is added to x co-ordinate and 7 to y
double angle = polar(x[i]+4, y[i]+7);
cout<< "(" << x[i]<<", "<<y[i]<<") "<<"----> "<<"( "<<radius<<", "<<angle<<")"<< endl;
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TASK 3
#include <iostream>
#include <math.h>
using namespace std;
double getrec(double x[], double y[])
{ int count = 0;
while(count < 100) // 100 inputs for task 3 or 0 0 to break the input
{
cout << "Enter a pair of positive x, then y coordinates, separated by spaces, or '0 0' to stop: ";
cin >> x[count]>> y[count];
if(x[count] == 0 && y[count] == 0) break;
count++;
}
return count;
}
double polar(double x, double y) // method that takes as input parameters a pair of Cartesian coordinates
{ // and returns the polar co-ordinate
const double toDegrees = 180.0/3.141593;
double polar = atan(y/x) * toDegrees;
return polar;
}
int main()
{
const int SIZE = 100;
double x[SIZE];
double y[SIZE];
double distance;
double angle;
double count = getrec(x,y); // getting input
cout<< " Coordinates [inputs ---> polar]: ";
cout<< "================================= ";
for(int i =0; i < count; i++)
{
double radius = sqrt((pow(x[i]+2,2))+(pow(y[i]+6,2))); // in task 3 , 2 is added to x co-ordinate and 6 to y
double angle = polar(x[i]+2, y[i]+6);
cout<< "(" << x[i]<<", "<<y[i]<<") "<<"----> "<<"( "<<radius<<", "<<angle<<")"<< endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.