C++ Help

edited March 2007 in Internet & Media
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;
}

Comments

  • edited March 2007
    i can also post the whole files if it'll help the posted coding is just parts i am having problems with.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited March 2007
    1) What errors ore you getting?

    2) post code inside [php]
    
    [/php] tags to aid in readability.                        
  • a2jfreaka2jfreak Houston, TX Member
    edited March 2007
    You don't understand the math or don't know how to convert the math to C++?

    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.
  • edited March 2007
    The math coding is correct im just having problems returning values to the outfile its telling me i have an uninitialized variable 'polar' in my main. Ive tried reading back but i still am having no luck.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited March 2007
    VecP2 polar;

    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
Sign In or Register to comment.