tutorial.cxx 788 B

1234567891011121314151617181920212223242526272829
  1. // A simple program that computes the square root of a number
  2. #include <cmath>
  3. #include <iostream>
  4. #include <string>
  5. // TODO 5: Include MathFunctions.h
  6. #include "TutorialConfig.h"
  7. int main(int argc, char* argv[])
  8. {
  9. if (argc < 2) {
  10. // report version
  11. std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
  12. << Tutorial_VERSION_MINOR << std::endl;
  13. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  14. return 1;
  15. }
  16. // convert input to double
  17. double const inputValue = std::stod(argv[1]);
  18. // TODO 6: Replace sqrt with mathfunctions::sqrt
  19. // calculate square root
  20. double const outputValue = sqrt(inputValue);
  21. std::cout << "The square root of " << inputValue << " is " << outputValue
  22. << std::endl;
  23. return 0;
  24. }