Hello,
I am having problems with reading from a .h file to .cpp file it gives me a strange error i have gone over this thing 1000 times and can not figure out whats wrong. Could someone please help me? I am using dev.c++ compiler. I should mention i am new at this class thing:cheesy:
ERROR
2 C:\Documents and Settings\MACHINE\Desktop\DAVID\w.cpp In file included from C:\Documents and Settings\MACHINE\Desktop\DAVID\w.cpp
THIS IS THE .H FILE
// FILE w.h
#ifndef SHIP_STATE
#define SHIP_STATE
class ship_state
{
public:
ship_state(double h, double v, double f);
double height();
double velocity();
double fuel();
int landed();
ship_state& update(double rate);
void print(ostream& os);
double dt const;
double gravity const;
double engine_strength const;
double safe_velocity const;
char burn_key const;
private:
double height_;
double velocity_;
double fuel_;
};
#endif
THIS IS THE .CPP FILE
#include "w.h"
#include <iostream>
using namespace std;
ship_state::ship_state(double h, double v, double f)
{
height_ = h;
velocity_ = v;
fuel_ = f;
}
double ship_state::height() {return height_;}
double ship_state::velocity(){return velocity_;}
double ship_state::fuel() {return fuel_;}
int ship_state::landed()
{
if (height_<=0)
return 1;
return 0;
}
void ship_state:print(ostream& os)
{
os<<"Velocity :"<<velocity_<<endl;
os<<"Height :"<<height_<<endl;
os<<"Fuel :"<<fuel_<<endl;
}
ship_state& ship_state::update(double rate)
{
double dh;
double dv;
if (fuel_<=0) {
fuel_=0;
rate=0;
}
dh=velocity_*dt;
dv=engine_strength*rate-gravity;
fuel_ -= (rate*dt);
height_ += dh;
velocity_+=dv;
return *this;
}
void end_game(ship_state&s);
double get_burn_rate();
void lander_loop(ship_state& s)
{
s.print(cout);
if (s.landed())
end_game(s);
else
lander_loop(s.update(get_burn_rate()));
}
void end_game(ship_state& s)
{
double v=s.velocity();
cout<<"Final velocity: "<<v;
if (v>=safe_velocity)
cout<<"...good landing!\n";
else
cout<<"...you crashed!\n";
}
double get_burn_rate()
{
cout<<"Enter "<<burn_key<<" to burn fuel, any other to float :";
char ch;
cin>>ch;
if (ch==burn_key)
return 1.0;
else
return 0.0;
}
double dt=1.0 const;
double gravity=0.5 const;
double engine_strength=1.0 const;
double safe_velocity = -0.5 const;
char burn_key='b'const;