for the part one I wrote #include <iostream> #include <cmath> #include <iomanip>
ID: 3791500 • Letter: F
Question
for the part one I wrote
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void)
{
float a, b, x, y, m, ang, pi;
char c;
cout << "Enter The coordinates Followed By R/r or P/p :" <<endl;
cin >> a >> b >> c; //reading the coordinates and character following them
if (c == 'r' || c == 'R') //check whether to see the character indicate rectangular coordinates
{
x = a;
y = b;
pi = 3.14159;
//calculate polar coordinates
m = sqrt((x*x) + (y*y));
ang = atan(y / x) * 180 / pi;
if (x < 0 ) //for the adjustment when x is less than 0
{
ang = 180 + ang;
}
//print the cooordinates
cout << "Rectangular (" << x << "," << y << ")" << endl;
cout << "polar coordinates (" << m << " & " << ang << ")" <<endl;
}
else if (c == 'p' || c == 'P') //check if the character represent polar coordinates
{
pi = 3.14159;
m = a;
ang = b ;
//calculate the rectangular coordinates
x = m*cos(ang * pi / 180);
y = m*sin(ang * pi / 180);
//print the coordinates
cout << "Rectangular (" << x << "," << y << ")" <<endl;
cout << "polar coordinates (" << m << " @ " << ang << ")" <<endl;
}
else //if the input format mismatch print the message to user
cout << "Illegal input format";
system("pause");
return (0);
}
And I need help with part two. Thank you.
Program Requirements: Part 1: Polar Rectangular Conversation A location (point) in the two-dimensional Cartesian Coordinate System can be represented in two ways, by its Polar Coordinates or its Rectangular Coordinates. In the Polar Coordinate representation, the location is in the form M 0, where M is the distance from the origin to the point, and e is the angle measured from the X-axis to the point. In the Rectangular Coordinate representation, the location is in the form C. Y) where X and Y are the horizontal and vertical distances from their respective axes (X, Y) M To convert a location from the Polar Coordinates to the Rectangular Coordinates M cos (0) Y M sin (0) To convert a location from the Rectangular Coordinates to the Polar Coordinates. X2 Y 0 tanExplanation / Answer
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class Rectangle
{
private:
float x[4];
float y[4];
public:
Rectangle(){
x[0] = x[1] = x[2] = x[3] = y[0] = y[1] = y[2] = y[3] = 0.0f;
}
void setX_cor(float var0,float var1, float var2, float var3){
x[0] = var0;
x[1] = var1;
x[2] = var2;
x[3] = var3;
}
void setY_cor(float var0, float var1, float var2, float var3){
y[0] = var0;
y[1] = var1;
y[2] = var2;
y[3] = var3;
}
float getX(int pos){
return x[pos];
}
float getY(int pos){
return y[pos];
}
};
void rectToPol(float x, float y, float* m,float* ang ){
float pi = 3.14159;
*m = sqrt((x*x) + (y*y));
*ang = atan(y / x) * 180 / pi;
if (x < 0 )
{
*ang = 180 + *ang;
}
}
void polToRect(float m,float ang, float* x , float* y)
{
float pi = 3.14159;
*x = m*cos(ang * pi / 180);
*y = m*sin(ang * pi / 180);
}
int main()
{
Rectangle r, rotated_r;
float width = 0.0f ,height = 0.0f;
float half_width = 0.0f, half_height = 0.0f;
float x0,x1,x2,x3;
float y0,y1,y2,y3;
float m , ang, rotation;
m = ang = 0.0f;
x0 = x1 = x2 = x3 = y0 = y1 = y2 = y3 = 0.0f;
cout<<"Enter the Width of the Image : ";
cin >>width;
cout<<"Enter the Height of the Image : ";
cin >>height;
cout<<"Enter the angle of rotation : ";
cin>> rotation;
half_width = width /2;
half_height = height / 2;
r.setX_cor(-1*half_width, half_width, half_width, -1 * half_width);
r.setY_cor(-1*half_height, -1* half_height, half_height, half_height);
x0 = x3 = (-1*half_width);
x1 = x2 = (half_width);
y0 = y1 = (-1*half_height);
y2 = y3 = (half_height);
// Conversion for CO
rectToPol(x0,y0,&m,&ang);
ang = ang + rotation;
polToRect(m,ang,&x0,&y0);
// Conversion for C1
rectToPol(x1,y1,&m,&ang);
ang = ang + rotation;
polToRect(m,ang,&x1,&y1);
// Conversion for C2
rectToPol(x2,y2,&m,&ang);
ang = ang + rotation;
polToRect(m,ang,&x2,&y2);
// Conversion for C3
rectToPol(x3,y3,&m,&ang);
ang = ang + rotation;
polToRect(m,ang,&x3,&y3);
rotated_r.setX_cor(x0,x1,x2,x3);
rotated_r.setY_cor(y0,y1,y2,y3);
cout<<"c0(" << r.getX(0) <<", "<< r.getY(0)<<")" << " " <<"D0(" << rotated_r.getX(0) <<", " << rotated_r.getY(0)<<")" <<" ";
cout<<"c1( " << r.getX(1) <<", "<< r.getY(1)<<")" << " " <<"D1(" << rotated_r.getX(1) <<", " << rotated_r.getY(1)<<")" <<" ";
cout<<"c2( " << r.getX(2) <<", "<< r.getY(2)<<")" << " " <<"D2(" << rotated_r.getX(2) <<", " << rotated_r.getY(2)<<")" <<" ";
cout<<"c3(" << r.getX(3) <<", "<< r.getY(3)<<")" << " " <<"D3(" << rotated_r.getX(3) <<", " << rotated_r.getY(3)<<")" <<" ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.