C++ Help
My assignment is to convert cartesian points to polar. I was wondering if someone can help me with my errors.
this is how far i have gotten.
class declaration file
class VecC2
{
public:
double x;
double y;
};
class VecP2
{
public:
double phi;
double r;
};
VecP2 Polar2(VecC2);
class implementation file
VecP2 Polar2(VecC2 vc)
{
VecP2 polar;
polar.phi = atan(vc.y/vc.x);
polar.r = sqrt(vc.x*vc.x+vc.y*vc.y);
return(polar);
}
Main.cpp : implementation file
int i;
int numdata = 0;
VecC2 vc[10];
for(i = 0;i < 10 && !inFile.eof(); i++)
{
inFile >> vc.x >> vc.y;
}
for(i = 0;i < numdata; i++)
{
VecP2 polar;
outFile << "Element " << i << " = "<< vc.x << " " << vc.y << endl;
outFile << "Polar Conversion" << polar.r << " " << polar.phi << endl;
}
this is how far i have gotten.
class declaration file
class VecC2
{
public:
double x;
double y;
};
class VecP2
{
public:
double phi;
double r;
};
VecP2 Polar2(VecC2);
class implementation file
VecP2 Polar2(VecC2 vc)
{
VecP2 polar;
polar.phi = atan(vc.y/vc.x);
polar.r = sqrt(vc.x*vc.x+vc.y*vc.y);
return(polar);
}
Main.cpp : implementation file
int i;
int numdata = 0;
VecC2 vc[10];
for(i = 0;i < 10 && !inFile.eof(); i++)
{
inFile >> vc.x >> vc.y;
}
for(i = 0;i < numdata; i++)
{
VecP2 polar;
outFile << "Element " << i << " = "<< vc.x << " " << vc.y << endl;
outFile << "Polar Conversion" << polar.r << " " << polar.phi << endl;
}
0
Comments
2) post code inside [php] [/php] tags to aid in readability.
If it's the math, read this.
If it's the C++, look up math functions. tan(), sin(), etc.
If you have any problems after reading that page and looking up the related functions, post back and someone will gladly assist you.
outFile << "Element " << i << " = "<< vc.x << " " << vc.y << endl;
outFile << "Polar Conversion" << polar.r << " " << polar.phi << endl;
You never change what polar is. I assume that you wanted to call polar = Polar2(vc); at some point