tutorial.cxx 876 B

123456789101112131415161718192021222324252627282930313233343536
  1. // A simple program that computes the square root of a number
  2. #include <cmath>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6. #include "TutorialConfig.h"
  7. // should we include the MathFunctions header?
  8. #ifdef USE_MYMATH
  9. # include "MathFunctions.h"
  10. #endif
  11. int main(int argc, char* argv[])
  12. {
  13. if (argc < 2) {
  14. // report version
  15. std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
  16. << Tutorial_VERSION_MINOR << std::endl;
  17. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  18. return 1;
  19. }
  20. double inputValue = std::stod(argv[1]);
  21. // which square root function should we use?
  22. #ifdef USE_MYMATH
  23. double outputValue = mysqrt(inputValue);
  24. #else
  25. double outputValue = sqrt(inputValue);
  26. #endif
  27. std::cout << "The square root of " << inputValue << " is " << outputValue
  28. << std::endl;
  29. return 0;
  30. }