why doesn't the compiler recognize the class i created?

i wrote a small code to check if a real number is an integar or not...tried to use classes. Created three files-

----file 1---

#include <cstdlib>
#include <iostream>
#include "RealNumberProp"

int main(int argc, char *argv[])
{
RealNumberProp number;
number.getValue();
number.displayValue;
system("PAUSE");
return EXIT_SUCCESS;
}


file2 ---RealNumberProp.cpp---

#include <cstdlib>
#include <iostream>
#include "RealNumberProp"

int RealNumberProp::upperBound(double value)
{
return ceil(value);
}

int RealNumberProp::lowerbound(double value)
{
return floor(value);
}

bool RealNumberProp::isInteger(double value)
{
if((value==upperBound(value))&&(value==lowerBound(value)))
return true;
else
return false;
}

void RealNumberProp::getValue()
{
cout<<"Enter A Number";
cin>>mRealNumber;
}

void RealNumberProp::displayResult()
{
cout<<"The given number is a"<<isInteger(double mRealNumber)?cout<<"n Integer":cout<<" Non-Integar";
}





file 3-----RealNumberProp.h

#include <cstdlib>
#include <iostream>
#include <math>

class RealNumberProp
{
private:
double mRealNumber(0);
int upperBound(double);
int lowerbound(double);
bool isInteger;
public:
void getValue;
void displayResult;
}





NOW, WHEN I COMPILE THIS, i get an error:- RealNumberProp : No Such fiel or directory...

three of these files are placed under the same directory..what's the problem then...? m using dev c++...

Well first off the include must be #include "RealNumberProp.h" and then the functions you have in your class definition should be declared as regular prototypes, such as:

1
2
3
4
5
6
7
class RealNumberProp
{
...
public:
void getValue();
void displayResult();
};


And there should be a semicolon at the end of your class definition. The number.displayValue , did you mean number.displayResult()? You need to specify that the ceil() and floor() functions are part of the std namespace, by using std::ceil() and std::floor() or put a using declaration for them somewhere ahead of time and in scope with the function, such as using (insert appropriate function here); or just declare that you're using the whole namespace such asusing namespace std;. Although the second method is preferable.

Sorry if I didn't cover everything!
Last edited on
ya i made some silly mistakes and now the refined code looks like...



#include <cstdlib>
#include <iostream>
#include "RealNumberProp.h"

int main(int argc, char *argv[])
{
RealNumberProp number;
number.getValue();
number.displayResult();
system("PAUSE");
return EXIT_SUCCESS;
}






#include <cstdlib>
#include <iostream>
#include <math.h>

class RealNumberProp
{
private:
double mRealNumber;
int upperBound(double);
int lowerbound(double);
bool isInteger(double);
public:
void getValue();
void displayResult();
};











#include <cstdlib>
#include <iostream>
#include "RealNumberProp.h"

int RealNumberProp::upperBound(double value)
{
return ceil(value);
}

int RealNumberProp::lowerbound(double value)
{
return floor(value);
}

bool RealNumberProp::isInteger(double value)
{
if((value==upperBound(value))&&(value==lowerBound(value)))
return true;
else
return false;
}

void RealNumberProp::getValue()
{
cout<<"Enter A Number";
cin>>mRealNumber;
}

void RealNumberProp::displayResult()
{
cout<<"The given number is a"<<isInteger(double mRealNumber)?cout<<"n Integer":cout<<" Non-Integar";
}



now i get these linker errors:
have no idea why do the come up..


[Linker error] undefined reference to `RealNumberProp::getValue()'

[Linker error] undefined reference to `RealNumberProp::displayResult()'
had it fixed !!!
Topic archived. No new replies allowed.