tutorial.cxx 911 B

12345678910111213141516171819202122232425262728293031323334
  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. // TODO 11: Only include MathFunctions if USE_MYMATH is defined
  7. // TODO 5: Include MathFunctions.h
  8. int main(int argc, char* argv[])
  9. {
  10. if (argc < 2) {
  11. // report version
  12. std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
  13. << Tutorial_VERSION_MINOR << std::endl;
  14. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  15. return 1;
  16. }
  17. // convert input to double
  18. const double inputValue = std::stod(argv[1]);
  19. // TODO 12: Use mysqrt if USE_MYMATH is defined and sqrt otherwise
  20. // TODO 6: Replace sqrt with mysqrt
  21. // calculate square root
  22. const double outputValue = sqrt(inputValue);
  23. std::cout << "The square root of " << inputValue << " is " << outputValue
  24. << std::endl;
  25. return 0;
  26. }