Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Help / guide / tutorial / Step2 / tutorial.cxx
1 // A simple program that computes the square root of a number
2 #include <cmath>
3 #include <iostream>
4 #include <string>
5
6 #include "TutorialConfig.h"
7
8 // TODO 11: Only include MathFunctions if USE_MYMATH is defined
9
10 // TODO 5: Include MathFunctions.h
11
12 int main(int argc, char* argv[])
13 {
14   if (argc < 2) {
15     // report version
16     std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
17               << Tutorial_VERSION_MINOR << std::endl;
18     std::cout << "Usage: " << argv[0] << " number" << std::endl;
19     return 1;
20   }
21
22   // convert input to double
23   const double inputValue = std::stod(argv[1]);
24
25   // TODO 12: Use mysqrt if USE_MYMATH is defined and sqrt otherwise
26
27   // TODO 6: Replace sqrt with mysqrt
28
29   // calculate square root
30   const double outputValue = sqrt(inputValue);
31   std::cout << "The square root of " << inputValue << " is " << outputValue
32             << std::endl;
33   return 0;
34 }