Excercise 2 - Step 1
This commit is contained in:
parent
e2564d1ea8
commit
7add9365b3
@ -11,15 +11,17 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|||||||
# to the source code
|
# to the source code
|
||||||
configure_file(TutorialConfig.h.in TutorialConfig.h)
|
configure_file(TutorialConfig.h.in TutorialConfig.h)
|
||||||
|
|
||||||
# TODO 2: Use add_subdirectory() to add MathFunctions to this project
|
add_subdirectory(MathFunctions)
|
||||||
|
|
||||||
# add the executable
|
# add the executable
|
||||||
add_executable(Tutorial tutorial.cxx)
|
add_executable(Tutorial tutorial.cxx)
|
||||||
|
|
||||||
# TODO 3: Use target_link_libraries to link the library to our executable
|
target_link_libraries(Tutorial PUBLIC MathFunctions)
|
||||||
|
|
||||||
# TODO 4: Add MathFunctions to Tutorial's target_include_directories()
|
target_include_directories(Tutorial PUBLIC
|
||||||
# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder!
|
"${PROJECT_BINARY_DIR}"
|
||||||
|
"${PROJECT_SOURCE_DIR}/MathFunctions"
|
||||||
|
)
|
||||||
|
|
||||||
# add the binary tree to the search path for include files
|
# add the binary tree to the search path for include files
|
||||||
# so that we will find TutorialConfig.h
|
# so that we will find TutorialConfig.h
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
# TODO 14: Remove mysqrt.cxx from the list of sources
|
# TODO 14: Remove mysqrt.cxx from the list of sources
|
||||||
|
|
||||||
# TODO 1: Add a library called MathFunctions with sources MathFunctions.cxx
|
|
||||||
# and mysqrt.cxx
|
add_library(MathFunctions MathFunctions.cxx mysqrt.cxx)
|
||||||
# Hint: You will need the add_library command
|
|
||||||
|
|
||||||
# TODO 7: Create a variable USE_MYMATH using option and set default to ON
|
# TODO 7: Create a variable USE_MYMATH using option and set default to ON
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// TODO 5: Include MathFunctions.h
|
#include "MathFunctions/MathFunctions.h"
|
||||||
#include "TutorialConfig.h"
|
#include "TutorialConfig.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
@ -19,10 +19,8 @@ int main(int argc, char* argv[])
|
|||||||
// convert input to double
|
// convert input to double
|
||||||
const double inputValue = std::stod(argv[1]);
|
const double inputValue = std::stod(argv[1]);
|
||||||
|
|
||||||
// TODO 6: Replace sqrt with mathfunctions::sqrt
|
|
||||||
|
|
||||||
// calculate square root
|
// calculate square root
|
||||||
const double outputValue = sqrt(inputValue);
|
const double outputValue = mathfunctions::sqrt(inputValue);
|
||||||
std::cout << "The square root of " << inputValue << " is " << outputValue
|
std::cout << "The square root of " << inputValue << " is " << outputValue
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user