Hello, I posted a program about converting furlongs to kilometers and other conversions concerning those 2 main units. These errors kept popping up:
error C2027: use of undefined type 'Kilometer'
see declaration of 'Kilometer'
error C2228: left of '.getkilometers' must have class/struct/union
error C2027: use of undefined type 'Kilometer'
see declaration of 'Kilometer'
error C2228: left of '.getmeters' must have class/struct/union
It was suggested to me that I declare the class kilometer before furlong but that did not work. I know that the errors are coming from using the class kilometer as a paramter type before it is declared and attempted to fix it but to no avail. I have absolutely no idea of how to fix this. Here is the 2 .h's and .cpp.
Furlong.h
#include "math.h"
#include<iostream>
using namespace std;
#define MILES_PER_FURLONG .125 ; //constants
#define YARDS_PER_FURLONG 220 ; //constants
#define FEET_PER_YARD 3 ; //constants
#define FEET_PER_FURLONG 660 ;
#define KILOMETERS_PER_FURLONG 0.201168 ; //constants
#define METERS_PER_KILOMETER 1000;
#define FURLONGS_PER_KILOMETER 4.97096954;
class Furlong{
private:
int furlongs;
int yards;
double feet;
public:
Furlong ()
{
furlongs=0;
yards=0;
feet=0.0;
};
Furlong(double f)//Basic type to User Defined type (class furlong type)
{
furlongs = (int)floor(f);//f works like d_furlongs since this is a direct conversion not needing to be multiplied by KILOMETERS_PER_FURLONG
double d_yards = (f - furlongs)*YARDS_PER_FURLONG;// d_yards(decimal yards) is the difference between f and the floored f
yards = (int)floor(d_yards); // miles the non-decimal value
feet = (d_yards - yards) * FEET_PER_YARD; // can be a decimal value for feet made to take all of the remainding value
};
int getfurlongs(){ //no explanation really needed I would hope
return furlongs;
}
int getyards(){
return yards;
}
double getfeet(){
return feet;
}
void display()
{cout<<"Furlongs: "<<furlongs<<endl<<"Yards: "<<yards<<endl<<"Feet: "<<feet<<endl;}//could call the get___() functions but would be unnecessary use of space
#ifndef KILOMETER_H
#define KILOMETER_H
#endif
Furlong(class Kilometer& kilo)
{
double k = kilo.getkilometers() + kilo.getmeters()/METERS_PER_KILOMETER;//so I dont have to tediously call the long function names over and over wasting code and memory space, combines kilometers with meters/1000 to create a total value for the total kilometers like f for the other constructor
double d_furlongs = k * KILOMETERS_PER_FURLONG; //decimal furlongs (d_furlongs) is the double version the kilometers * KILOMETERS_PER_FURLONG
furlongs = (int)floor(d_furlongs);//non-decimal version of the kilometers to furlong
double d_yards = (d_furlongs - furlongs) * YARDS_PER_FURLONG;// d_yards(decimal yards) is the difference between d_furlongs and the floored furlongs
yards = (int)floor(d_yards);//miles the non-decimal value
feet = d_yards - yards * FEET_PER_YARD; // can be a decimal value for feet made to take all of the remainding value
};
};
kilometer.h
#include<iostream>
#include<math.h>
using namespace std;
#define METERS_PER_KILOMETER 1000 ;
#define FURLONGS_PER_KILOMETER 4.97096954;
#define MILES_PER_FURLONG .125 ; //constants
#define YARDS_PER_FURLONG 220 ; //constants
#define FEET_PER_YARD 3 ; //constants
#define FEET_PER_FURLONG 660 ;
#define KILOMETERS_PER_FURLONG 0.201168 ;//constants
class Kilometer{
private:
int kilometers;
double meters;
public:
Kilometer ()
{
kilometers=0;
meters=0.0;
};
Kilometer (double k)
{
kilometers = (int)floor(k);//floored version of k
meters = (k-kilometers) * METERS_PER_KILOMETER;//the difference of the
};
int getkilometers(){ //no explanation needed
return kilometers;
};
double getmeters(){
return meters;
};
void display()
{cout<<endl<<"Kilmeters: "<<kilometers<<endl<<"meters: "<<meters<<endl;};
#ifndef FURLONG_H
#define FURLONG_H
#endif
Kilometer (Furlong& furl)
{
double f=furl.getfurlongs() + furl.getyards()/YARDS_PER_FURLONG + furl.getfeet()/FEET_PER_FURLONG;//so I dont have to tediously call the long function names over and over wasting code and memory space, combines furlongs with yards/220 with feet/660 to create a total value for the total furlongs similar to the double k for the other constructor
double d_kilometers = f*FURLONGS_PER_KILOMETER; //decimal furlongs (d_furlongs) is the double version the kilometers * fURLONGS_PER_KILOMETER
kilometers = (int)floor(d_kilometers);//non-decimal version of the kilometers to furlong
meters=(d_kilometers-kilometers) * METERS_PER_KILOMETER;
};
};
main.cpp
#include "Furlong.h"
#include "Kilometer.h"
#include<iostream> //not really needed to be in so I commented out, the linking of the Furlong.h and Kilometer.h includes #include<iostream>
using namespace std;
int main()
{
//double f=15;//furlong input initialized to zero for safety
//double k=34.3458;//kilometer input initialized to zero for safety
//class Furlong a(f);
//class Kilometer b(k);
//a.display();
//b.display();
//class Kilometer c(a);
//c.display();
system("pause");
return 0;
}
Thank you for any help.