//*********************************************************************** // Float_error2.h // // this is program experiments with floating point computations and // the limitations of the digital representations of floating point // numbers. // //*********************************************************************** // INPUTS: an initial floating point value in input from the keyboard // // OUTPUTS: the computational results are displayed on the screen // //*********************************************************************** // WARNING: none // //*********************************************************************** // IMPLEMENTATION NOTE: none // //*********************************************************************** // created by: j. aleshunas // created on: 2 jun 04 // modified on: 2 jun 04 // // © 2004 John Aleshunas // //*********************************************************************** #include #include using namespace std; //*********************************************************************** // class Float_store declaration //*********************************************************************** class Float_store { // private class variables float fInital_value; // storage for the initial numeric value float fWorking_value; // storage for the results of a computation vector vfStorage; // storage for the computed numeric value // private methods public: // public methods Float_store(float fValue); // class constructor void Square(void); void Root(void); float Display_value(void); }; // class Float_store //*********************************************************************** // class Float_store method declarations //*********************************************************************** // private class method //*********************************************************************** // the class constructor Float_store::Float_store(float fValue){ // set the initial value of the floating point number fInital_value = fValue; fWorking_value = fValue; // save the initial value of the floating point number vfStorage.push_back(fValue); return; } // Float_store::Float_store(float fValue) //*********************************************************************** void Float_store::Square(void){ fWorking_value = fWorking_value * vfStorage.back(); // save the new value of the floating point number vfStorage.push_back(fWorking_value); return; } // Float_store::Square(void) //*********************************************************************** void Float_store::Root(void){ if (1 < vfStorage.size()) { // test to prevent underflow of vector storage // discard the last value of the floating point number vfStorage.pop_back(); // calculate the root of the floating point number fWorking_value = fWorking_value / vfStorage.back(); }else cout << "Can not use Root any more" << endl << endl; return; } // Float_store::Root(void) //*********************************************************************** float Float_store::Display_value(void){ return fWorking_value; } // Float_store::Display_value(void) //***********************************************************************