Tutorial.cxx 826 B

123456789101112131415161718192021222324252627282930313233343536
  1. // A simple program that computes the square root of a number
  2. #include <format>
  3. #include <iostream>
  4. #include <string>
  5. #include <MathFunctions.h>
  6. #ifdef TUTORIAL_USE_VENDORLIB
  7. # include <Vendor.h>
  8. #endif
  9. int main(int argc, char* argv[])
  10. {
  11. if (argc < 2) {
  12. std::cout << std::format("Usage: {} number\n", argv[0]);
  13. return 1;
  14. }
  15. int unused;
  16. // convert input to double
  17. double const inputValue = std::stod(argv[1]);
  18. // calculate square root
  19. double const outputValue = mathfunctions::sqrt(inputValue);
  20. std::cout << std::format("The square root of {} is {}\n", inputValue,
  21. outputValue);
  22. #ifdef TUTORIAL_USE_VENDORLIB
  23. if (CheckSqrt(inputValue, outputValue)) {
  24. std::cout << "Sqrt verified by vendor\n";
  25. } else {
  26. std::cout << "Sqrt rejected by vendor\n";
  27. }
  28. #endif
  29. }