From 4aa96664485e0ea730f270f8a3e7f73900fc11d9 Mon Sep 17 00:00:00 2001 From: r-1i Date: Mon, 11 May 2026 20:24:19 +0300 Subject: [PATCH 1/3] mini_hw_3_donegit statusgit status!))))) --- sem2/ReznikovIA/hw3/input.txt | 6 ++ sem2/ReznikovIA/hw3/main.cpp | 153 +++++++++++++++++++++++++++++++++ sem2/ReznikovIA/hw3/output.txt | 23 +++++ 3 files changed, 182 insertions(+) create mode 100644 sem2/ReznikovIA/hw3/input.txt create mode 100644 sem2/ReznikovIA/hw3/main.cpp create mode 100644 sem2/ReznikovIA/hw3/output.txt diff --git a/sem2/ReznikovIA/hw3/input.txt b/sem2/ReznikovIA/hw3/input.txt new file mode 100644 index 00000000..3f95ed8e --- /dev/null +++ b/sem2/ReznikovIA/hw3/input.txt @@ -0,0 +1,6 @@ +Hello world +C++ programming is fun +Lambda expressions +STL algorithms +Short +A very long string just for testing purposes \ No newline at end of file diff --git a/sem2/ReznikovIA/hw3/main.cpp b/sem2/ReznikovIA/hw3/main.cpp new file mode 100644 index 00000000..133ac85c --- /dev/null +++ b/sem2/ReznikovIA/hw3/main.cpp @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include + +void readAllData(std::vector& vec, const std::string& fileName); +void workWithVector(std::vector& vec); +void writeToFile(const std::vector& data, + const std::string& outputFileName); +void writeToFile(const std::string& data, const std::string& outputFileName); +void clearFile(const std::string& fileName); + +int main() { + std::string inputFileLocation = "input.txt"; + std::vector vec; + readAllData(vec, inputFileLocation); + workWithVector(vec); + return 0; +} + +void workWithVector(std::vector& vec) { + auto printVec = [&vec]() { + std::cout << "[] printVec: " << std::endl; + std::for_each(vec.cbegin(), vec.cend(), + [](const auto& line) { std::cout << line << std::endl; }); + std::cout << std::endl; + }; + auto removeWordsLessThanInput = [&vec]() { + std::cout << "[] removeWordsLessThanInput: " << std::endl; + int minLength = 0; + std::cout << "Input min word length (int): "; + std::cin >> minLength; + std::cout << "Entered number: " << minLength << std::endl; + auto newEnd = std::remove_if(vec.begin(), vec.end(), + [minLength](std::string& word) -> bool { + return word.length() < minLength; + }); + vec.erase(newEnd, vec.end()); + std::cout << std::endl; + }; + auto changeSpacesToUnderscores = [&vec]() { + std::cout << "[] changeSpacesToUnderscores: " << std::endl; + std::for_each(vec.begin(), vec.end(), [](std::string& line) { + std::replace(line.begin(), line.end(), ' ', '_'); + }); + std::cout << std::endl; + }; + auto findInputWord = [&vec]() -> std::string { + std::cout << "[] removeInputWord: " << std::endl; + std::string word; + std::cout << "Input word to find: "; + std::cin >> word; + std::cout << "Choosed word is: " << word << std::endl; + auto it = std::find_if(vec.cbegin(), vec.cend(), + [&word](const std::string& line) { + return line.find(word) != std::string::npos; + }); + if (it != vec.cend()) { + std::cout << "Found: " << *it << std::endl; + std::cout << std::endl; + return *it; + } else { + std::cout << "Not found!" << std::endl; + std::cout << std::endl; + return "Not found!"; + } + }; + auto countCharsWithoutUnderscores = [&vec]() -> int { + std::cout << "[] countCharsWithoutUnderscores: " << std::endl; + int totalChars = 0; + std::for_each( + vec.begin(), vec.end(), [&totalChars](const std::string& line) { + totalChars += std::count_if(line.cbegin(), line.cend(), + [](char ch) { return ch != '_'; }); + }); + std::cout << "Total count: " << totalChars << std::endl; + std::cout << std::endl; + return totalChars; + }; + auto createLinesLengthVector = [&vec]() -> std::vector { + std::cout << "[] createLinesLengthVector: " << std::endl; + std::vector lengthVec; + std::for_each(vec.cbegin(), vec.cend(), + [&lengthVec](const std::string& line) { + lengthVec.push_back(std::to_string(line.length())); + }); + std::cout << "Vector created!" << std::endl; + std::cout << std::endl; + return lengthVec; + }; + + std::string outputFileName = "output.txt"; + + clearFile(outputFileName); + + printVec(); + writeToFile(vec, outputFileName); + writeToFile("---", outputFileName); + + removeWordsLessThanInput(); + printVec(); + writeToFile(vec, outputFileName); + writeToFile("---", outputFileName); + + changeSpacesToUnderscores(); + printVec(); + writeToFile(vec, outputFileName); + writeToFile("---", outputFileName); + + writeToFile(findInputWord(), outputFileName); + writeToFile("---", outputFileName); + + writeToFile(std::to_string(countCharsWithoutUnderscores()), outputFileName); + writeToFile("---", outputFileName); + + writeToFile(createLinesLengthVector(), outputFileName); + writeToFile("---", outputFileName); +} + +void writeToFile(const std::string& line, const std::string& fileName) { + std::ofstream out(fileName, std::ios::app); + if (out.is_open()) { + out << line << std::endl; + } + out.close(); +} + +void writeToFile(const std::vector& data, + const std::string& outputFileName) { + std::for_each(data.cbegin(), data.cend(), + [&data, &outputFileName](const std::string& line) { + writeToFile(line, outputFileName); + }); +} + +void readAllData(std::vector& vec, const std::string& fileName) { + std::ifstream in(fileName); + if (in.is_open()) { + std::string line; + while (std::getline(in, line)) { + vec.push_back(line); + } + } + in.close(); +} + +void clearFile(const std::string& fileName) { + std::ofstream out(fileName); + if (out.is_open()) { + } + out.close(); +} diff --git a/sem2/ReznikovIA/hw3/output.txt b/sem2/ReznikovIA/hw3/output.txt new file mode 100644 index 00000000..d0c66996 --- /dev/null +++ b/sem2/ReznikovIA/hw3/output.txt @@ -0,0 +1,23 @@ +Hello world +C++ programming is fun +Lambda expressions +STL algorithms +Short +A very long string just for testing purposes +--- +C++ programming is fun +Lambda expressions +A very long string just for testing purposes +--- +C++_programming_is_fun +Lambda_expressions +A_very_long_string_just_for_testing_purposes +--- +A_very_long_string_just_for_testing_purposes +--- +73 +--- +22 +18 +44 +--- From d42d6da5a98b3764eea310fb29687a4be5a0f385 Mon Sep 17 00:00:00 2001 From: r-1i Date: Mon, 11 May 2026 21:18:48 +0300 Subject: [PATCH 2/3] add hw4 --- sem2/ReznikovIA/hw4/main.cpp | 108 +++++++++++++++++++++++++++++++++ sem2/ReznikovIA/hw4/output.txt | 53 ++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 sem2/ReznikovIA/hw4/main.cpp create mode 100644 sem2/ReznikovIA/hw4/output.txt diff --git a/sem2/ReznikovIA/hw4/main.cpp b/sem2/ReznikovIA/hw4/main.cpp new file mode 100644 index 00000000..f68fba45 --- /dev/null +++ b/sem2/ReznikovIA/hw4/main.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include + +std::vector generateVector(); +void workWithArray(std::vector& numbers); +void writeToFile(const std::vector& data, + const std::string& outputFileName); +void writeToFile(const std::string& data, const std::string& outputFileName); +void writeToFile(const double& data, const std::string& outputFileName); + +void clearFile(const std::string& fileName); + +int main() { + std::vector numbers = generateVector(); + workWithArray(numbers); + return 0; +} + +void workWithArray(std::vector& numbers) { + std::string fileName = "output.txt"; + clearFile(fileName); + + auto maxElemIt = std::max_element(numbers.cbegin(), numbers.cend()); + writeToFile("max: " + std::to_string((*maxElemIt)), fileName); + auto minElemIt = std::min_element(numbers.cbegin(), numbers.cend()); + writeToFile("min: " + std::to_string((*minElemIt)), fileName); + + std::sort(numbers.begin(), numbers.end()); + writeToFile("sorted", fileName); + writeToFile(numbers, fileName); + + int positiveCount = + std::count_if(numbers.cbegin(), numbers.cend(), + [](int number) -> bool { return number > 0; }); + writeToFile("+: " + std::to_string(positiveCount), fileName); + int negativeCount = + std::count_if(numbers.cbegin(), numbers.cend(), + [](int number) -> bool { return number < 0; }); + writeToFile("-: " + std::to_string(negativeCount), fileName); + + int zeroCount = std::count_if(numbers.cbegin(), numbers.cend(), + [](int number) -> bool { return number == 0; }); + writeToFile("0: " + std::to_string(zeroCount), fileName); + + double mean = std::accumulate(numbers.cbegin(), numbers.cend(), 0) / + static_cast(numbers.size()); + writeToFile("arithmetic mean: " + std::to_string(mean), fileName); + + auto newEnd = std::remove_if(numbers.begin(), numbers.end(), + [](int num) { return num % 2 == 0; }); + numbers.erase(newEnd, numbers.end()); + writeToFile("only odd", fileName); + writeToFile(numbers, fileName); + + std::sort(numbers.begin(), numbers.end()); + std::vector uniqueNumbers; + std::unique_copy(numbers.begin(), numbers.end(), + std::back_inserter(uniqueNumbers)); + writeToFile("sorted unique", fileName); + writeToFile(uniqueNumbers, fileName); +} + +std::vector generateVector() { + std::vector nums(20); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution dist(-50, 100); + + std::generate(nums.begin(), nums.end(), + [&dist, &gen]() { return dist(gen); }); + return nums; +} + +void clearFile(const std::string& fileName) { + std::ofstream out(fileName); + if (out.is_open()) { + } + out.close(); +} + +void writeToFile(const std::string& data, const std::string& fileName) { + std::ofstream out(fileName, std::ios::app); + if (out.is_open()) { + out << data << std::endl; + } + out.close(); +} + +void writeToFile(const double& data, const std::string& fileName) { + std::ofstream out(fileName, std::ios::app); + if (out.is_open()) { + out << data << std::endl; + } + out.close(); +} + +void writeToFile(const std::vector& data, + const std::string& outputFileName) { + std::for_each(data.cbegin(), data.cend(), + [&data, &outputFileName](const int num) { + writeToFile(std::to_string(num), outputFileName); + }); +} diff --git a/sem2/ReznikovIA/hw4/output.txt b/sem2/ReznikovIA/hw4/output.txt new file mode 100644 index 00000000..ce5976eb --- /dev/null +++ b/sem2/ReznikovIA/hw4/output.txt @@ -0,0 +1,53 @@ +max: 85 +min: -49 +sorted +-49 +-47 +-46 +-38 +-23 +-19 +-15 +1 +18 +22 +29 +32 +37 +56 +57 +58 +63 +70 +77 +85 ++: 13 +-: 7 +0: 0 +arithmetic mean: 18.400000 +only odd +-49 +-47 +-23 +-19 +-15 +1 +29 +37 +57 +63 +77 +85 +sorted unique +-49 +-47 +-23 +-19 +-15 +1 +29 +37 +57 +63 +77 +85 From 3217f3e7158b28b3c4d451ee418c08ea12a24ce0 Mon Sep 17 00:00:00 2001 From: r-1i Date: Mon, 11 May 2026 21:25:17 +0300 Subject: [PATCH 3/3] rm hw3 files --- sem2/ReznikovIA/hw3/input.txt | 6 -- sem2/ReznikovIA/hw3/main.cpp | 153 --------------------------------- sem2/ReznikovIA/hw3/output.txt | 23 ----- 3 files changed, 182 deletions(-) delete mode 100644 sem2/ReznikovIA/hw3/input.txt delete mode 100644 sem2/ReznikovIA/hw3/main.cpp delete mode 100644 sem2/ReznikovIA/hw3/output.txt diff --git a/sem2/ReznikovIA/hw3/input.txt b/sem2/ReznikovIA/hw3/input.txt deleted file mode 100644 index 3f95ed8e..00000000 --- a/sem2/ReznikovIA/hw3/input.txt +++ /dev/null @@ -1,6 +0,0 @@ -Hello world -C++ programming is fun -Lambda expressions -STL algorithms -Short -A very long string just for testing purposes \ No newline at end of file diff --git a/sem2/ReznikovIA/hw3/main.cpp b/sem2/ReznikovIA/hw3/main.cpp deleted file mode 100644 index 133ac85c..00000000 --- a/sem2/ReznikovIA/hw3/main.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include -#include -#include -#include -#include - -void readAllData(std::vector& vec, const std::string& fileName); -void workWithVector(std::vector& vec); -void writeToFile(const std::vector& data, - const std::string& outputFileName); -void writeToFile(const std::string& data, const std::string& outputFileName); -void clearFile(const std::string& fileName); - -int main() { - std::string inputFileLocation = "input.txt"; - std::vector vec; - readAllData(vec, inputFileLocation); - workWithVector(vec); - return 0; -} - -void workWithVector(std::vector& vec) { - auto printVec = [&vec]() { - std::cout << "[] printVec: " << std::endl; - std::for_each(vec.cbegin(), vec.cend(), - [](const auto& line) { std::cout << line << std::endl; }); - std::cout << std::endl; - }; - auto removeWordsLessThanInput = [&vec]() { - std::cout << "[] removeWordsLessThanInput: " << std::endl; - int minLength = 0; - std::cout << "Input min word length (int): "; - std::cin >> minLength; - std::cout << "Entered number: " << minLength << std::endl; - auto newEnd = std::remove_if(vec.begin(), vec.end(), - [minLength](std::string& word) -> bool { - return word.length() < minLength; - }); - vec.erase(newEnd, vec.end()); - std::cout << std::endl; - }; - auto changeSpacesToUnderscores = [&vec]() { - std::cout << "[] changeSpacesToUnderscores: " << std::endl; - std::for_each(vec.begin(), vec.end(), [](std::string& line) { - std::replace(line.begin(), line.end(), ' ', '_'); - }); - std::cout << std::endl; - }; - auto findInputWord = [&vec]() -> std::string { - std::cout << "[] removeInputWord: " << std::endl; - std::string word; - std::cout << "Input word to find: "; - std::cin >> word; - std::cout << "Choosed word is: " << word << std::endl; - auto it = std::find_if(vec.cbegin(), vec.cend(), - [&word](const std::string& line) { - return line.find(word) != std::string::npos; - }); - if (it != vec.cend()) { - std::cout << "Found: " << *it << std::endl; - std::cout << std::endl; - return *it; - } else { - std::cout << "Not found!" << std::endl; - std::cout << std::endl; - return "Not found!"; - } - }; - auto countCharsWithoutUnderscores = [&vec]() -> int { - std::cout << "[] countCharsWithoutUnderscores: " << std::endl; - int totalChars = 0; - std::for_each( - vec.begin(), vec.end(), [&totalChars](const std::string& line) { - totalChars += std::count_if(line.cbegin(), line.cend(), - [](char ch) { return ch != '_'; }); - }); - std::cout << "Total count: " << totalChars << std::endl; - std::cout << std::endl; - return totalChars; - }; - auto createLinesLengthVector = [&vec]() -> std::vector { - std::cout << "[] createLinesLengthVector: " << std::endl; - std::vector lengthVec; - std::for_each(vec.cbegin(), vec.cend(), - [&lengthVec](const std::string& line) { - lengthVec.push_back(std::to_string(line.length())); - }); - std::cout << "Vector created!" << std::endl; - std::cout << std::endl; - return lengthVec; - }; - - std::string outputFileName = "output.txt"; - - clearFile(outputFileName); - - printVec(); - writeToFile(vec, outputFileName); - writeToFile("---", outputFileName); - - removeWordsLessThanInput(); - printVec(); - writeToFile(vec, outputFileName); - writeToFile("---", outputFileName); - - changeSpacesToUnderscores(); - printVec(); - writeToFile(vec, outputFileName); - writeToFile("---", outputFileName); - - writeToFile(findInputWord(), outputFileName); - writeToFile("---", outputFileName); - - writeToFile(std::to_string(countCharsWithoutUnderscores()), outputFileName); - writeToFile("---", outputFileName); - - writeToFile(createLinesLengthVector(), outputFileName); - writeToFile("---", outputFileName); -} - -void writeToFile(const std::string& line, const std::string& fileName) { - std::ofstream out(fileName, std::ios::app); - if (out.is_open()) { - out << line << std::endl; - } - out.close(); -} - -void writeToFile(const std::vector& data, - const std::string& outputFileName) { - std::for_each(data.cbegin(), data.cend(), - [&data, &outputFileName](const std::string& line) { - writeToFile(line, outputFileName); - }); -} - -void readAllData(std::vector& vec, const std::string& fileName) { - std::ifstream in(fileName); - if (in.is_open()) { - std::string line; - while (std::getline(in, line)) { - vec.push_back(line); - } - } - in.close(); -} - -void clearFile(const std::string& fileName) { - std::ofstream out(fileName); - if (out.is_open()) { - } - out.close(); -} diff --git a/sem2/ReznikovIA/hw3/output.txt b/sem2/ReznikovIA/hw3/output.txt deleted file mode 100644 index d0c66996..00000000 --- a/sem2/ReznikovIA/hw3/output.txt +++ /dev/null @@ -1,23 +0,0 @@ -Hello world -C++ programming is fun -Lambda expressions -STL algorithms -Short -A very long string just for testing purposes ---- -C++ programming is fun -Lambda expressions -A very long string just for testing purposes ---- -C++_programming_is_fun -Lambda_expressions -A_very_long_string_just_for_testing_purposes ---- -A_very_long_string_just_for_testing_purposes ---- -73 ---- -22 -18 -44 ----