main.cc 718 B

12345678910111213141516171819202122232425262728
  1. // A simple program that outputs the square root of a number
  2. #include <iostream>
  3. #include <string>
  4. #include "Addition.h"
  5. #include "SquareRoot.h"
  6. int main(int argc, char* argv[])
  7. {
  8. if (argc < 2) {
  9. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  10. return 1;
  11. }
  12. // convert input to double
  13. const double inputValue = std::stod(argv[1]);
  14. // calculate square root
  15. const double sqrt = MathFunctions::sqrt(inputValue);
  16. std::cout << "The square root of " << inputValue << " is " << sqrt
  17. << std::endl;
  18. // calculate sum
  19. const double sum = MathFunctions::add(inputValue, inputValue);
  20. std::cout << inputValue << " + " << inputValue << " = " << sum << std::endl;
  21. return 0;
  22. }