tutorial.cxx 904 B

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