Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #ifndef __PRECISION_HPP__
  2. #define __PRECISION_HPP__
  3. #include <iomanip>
  4. #include "base.hpp"
  5. using namespace std;
  6. class PrecisionOp : public Op {
  7. private: double value;
  8. int numDecimals;
  9. public: PrecisionOp() {};
  10. PrecisionOp(double userVal, int inputDecimals) {
  11. value = userVal;
  12. numDecimals = inputDecimals;
  13. }
  14. string stringify() {
  15. ostringstream strStream;
  16. strStream << fixed << setprecision(numDecimals) << value;
  17. string returnStr = strStream.str();
  18. return returnStr;
  19. }
  20. };
  21.  
  22. class PrecisionRand : public Rand {
  23. private: double value;
  24. int numDecimals;
  25. public: PrecisionRand() {};
  26. PrecisionRand(int amtPrecision) {
  27. value = rand() % 100;
  28. numDecimals = amtPrecision;
  29. }
  30. string stringify() {
  31. ostringstream strStream;
  32. strStream << fixed << setprecision(numDecimals) << value;
  33. string returnStr = strStream.str();
  34. return returnStr;
  35. }
  36. };
  37. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement