Debian Codegraph @

Help/guide/tutorial/Step4/Tutorial/Tutorial.cxx

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