Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==========
- main.cpp||
- ==========
- // Реализуйте функции в functions.cpp.
- // Не меняйте содержимое этого файла.
- // Тестируем версию int
- cout << "|100| = "s << ComputeAbs(100) << endl;
- cout << "|0| = "s << ComputeAbs(0) << endl;
- cout << "|-50| = "s << ComputeAbs(-50) << endl;
- // Тестируем версию float. Можно задать значение float
- // добавив после цифр букву f
- cout << "|3.141592f| = "s << ComputeAbs(3.141592f) << endl;
- cout << "|0.f| = "s << ComputeAbs(0.f) << endl;
- cout << "|-3.141592f| = "s << ComputeAbs(-3.141592f) << endl;
- // Тестируем версию double
- cout << "|3.141592| = "s << ComputeAbs(3.141592) << endl;
- cout << "|0| = "s << ComputeAbs(0) << endl;
- cout << "|-3.141592| = "s << ComputeAbs(-3.141592) << endl;
- // Тестируем версию vector
- int idx = 0;
- vector input_data = {10, 20, -30, -50, 100};
- for (int x : ComputeAbs(input_data)) {
- // Операция ++ увеличивает значение целочисленной переменной на 1.
- // Результатом операции ++ становится значение до увеличения.
- cout << "|"s << input_data[idx++] << "| = "s << x << endl;
- }
- ----------------------------------------------------------------------------------------------------------------------------
- ===============
- functions.cpp||
- ===============
- #include <iostream>
- #include <string>
- #include <vector>
- template<typename K>
- K ComputeAbs(K num){
- return abs(num);
- }
- std::vector<int> ComputeAbs(std::vector<int> num){
- std::vector<int>next_vec;
- for(const auto& n: num){
- next_vec.push_back(abs(n));
- }
- return next_vec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement