C++ Help

Status
Not open for further replies.

eXtensible

Baseband Member
Messages
37
Location
Earth
Hi eXtensible here,
I've recently started work on a Program that converts Polar Coordinates to Cartesian Coordinates. However I'm Having trouble

Here's the source:

Vector3D.h:
Code:
#ifndef VECTOR3D_H
#define VECTOR3D_H
#include <iostream>

using namespace std;

class Vector3D
{
public:
       
    Vector3D(float xIn, float yIn, float zIn = 0);
    void print();
    float x, y, z;
    
    ~Vector3D();      
};

#endif
Vector3D.cpp:
Code:
#include "Vector3D.h"
#include <iostream>
#include <cmath>

using namespace std;

// Constructor
Vector3D::Vector3D(float xIn, float yIn, float zIn)
{
    x = xIn;
    y = yIn;
    z = zIn;                         
}

void Vector3D::print()
{
    cout << x << "," << y << "," << z << endl;     
}

Vector3D::~Vector3D()
{
}
physics.h:
Code:
#ifndef PHYSICS_H
#define PHYSICS_H
#include "Vector3D.h"
#include <iostream>
#include <math.h>
// define pi so I can call it using "PI"
#define PI 3.14f
#define g 9.8f

Vector3D polarToCart(Vector3D polar)
{
    Vector3D x(0, 0);
    x.x = polar.x * cos(polar.y * PI / 180.0f);
    x.y = polar.x = sin(polar.y * PI / 180.0f);
    return x;
}

#endif
main.cpp:
Code:
#include <cstdlib>
#include <iostream>
#include "Vector3D.h"
#include "physics.h"
#include <cmath>

using namespace std;

int main()
{
float mag, dir;
cout << "Input magnitude: ";
cin >> mag;
cout << "Input direction: ";
cin >> dir;

Vector3D temp(mag, dir);
temp = Vector3D polarToCart();
temp.print();
}

the errors I keep getting are:
1. 18 C:\Dev-Cpp\main.cpp expected primary-expression before "polarToCart".
2. 18 C:\Dev-Cpp\main.cpp expected `;' before "polarToCart".

What am i doing wrong?
 
Status
Not open for further replies.
Back
Top Bottom