Menu

What's the prob with this code?

Anonymous
2008-08-15
2012-09-26
  • Anonymous

    Anonymous - 2008-08-15

    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++...

     
    • ioda69

      ioda69 - 2008-08-22

      Ok just keep trying ;o)

      I'm not a C++ GURU but my advice is go slowly and be carreful what you write !

      I'm will do not talk about your strategy to reach the goal, it's not the subject !
      Here the code I can compile and run with devcpp : Hope this help ;o)

      main.cpp
      8<-------------------------------

      include <cstdlib>

      include <iostream>

      include "RealNumberProp.h"

      using namespace std;

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

      RealNumberProp.h
      8<-------------------------------

      include <cstdlib>

      include <iostream>

      include <math.h>

      class RealNumberProp
      {
      private:
      double mRealNumber;
      double upperBound(double);
      double lowerBound(double);
      bool isInteger(double);
      public:
      void getValue();
      void displayResult();
      };
      8<-------------------------------

      RealNumberProp.cpp
      8<-------------------------------

      include <cstdlib>

      include <iostream>

      include "RealNumberProp.h"

      using namespace std;

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

      double 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 an" << (isInteger(mRealNumber) ? " Integer":" Non-Integer") << endl;
      8<-------------------------------

       

Log in to post a comment.