I wrote a programm that asks the user for three values and then calculates other values out of them.
But somehow it returns trash. For example this:
Track.h
class Track : public World
{
public:
friend class Vehicle;
Track();
virtual ~Track();
float GetLenght() {return m_Lenght;}
float GetSlope() {return m_Slope;}
void SetSlope(float value) {m_Slope = value;}
float GetAcceleration();
protected:
private:
const float m_Lenght = 2; //m
float m_Slope;
float m_TrackAcceleration;
};
Track.cpp
#include "Track.h"
#include "World.h"
#include <math.h>
#include "Vehicle.h"
#define PI 3.14159265359
[...]
float Track::GetAcceleration() {
World *Earth = new World();
Vehicle *Car = new Vehicle();
m_TrackAcceleration = Earth->Accelerate(Car->GetWeight())*sin(1*PI/180);
return m_TrackAcceleration;
}
main.cpp
int main()
{
World *Earth = new World();
Track *Track1 = new Track();
Vehicle *Car = new Vehicle();
Mass *Mass1 = new Mass();
float MassWeight, VehicleWeight, Slope;
cout << "Mass Weight:"; cin >> MassWeight;
cout << "Vehicle Weight:"; cin >> VehicleWeight;
cout << "Slope:"; cin >> Slope;
Mass1->SetWeight(MassWeight);
Car->SetWeight(VehicleWeight);
Track1->SetSlope(Slope);
cout << "Acceleration Force:" << Track1->GetAcceleration() << endl << endl;
};
Vehicle.h
class Vehicle : public World
{
public:
friend class Track;
Vehicle();
virtual ~Vehicle();
float GetWeight() {return m_VehicleWeight;}
void SetWeight(float value) {m_VehicleWeight = value;}
float GetSpeed(float seconds);
float GetAcceleration();
float GetDistance(float seconds);
protected:
private:
float m_VehicleWeight;
float m_Speed;
float m_Distance;
float m_VehicleAcceleration;
};
World.h
class World
{
public:
World();
virtual ~World();
float GetGravity (){return m_Gravity;}
float Accelerate (float mass);
protected:
private:
const float m_Gravity = 9.81; // m/s^2
float m_WorldAcceleration;
};
should return 0,171208....
, but it returns 1.91825e-039
with Mass Weight=1
,Vehicle Weight=1
and Slope=1
.
any idea on this?