diff --git a/cmake-build-debug/CMakeFiles/clion-log.txt b/cmake-build-debug/CMakeFiles/clion-log.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d42288c2858bf86370a5778a7c897de4b0d935f --- /dev/null +++ b/cmake-build-debug/CMakeFiles/clion-log.txt @@ -0,0 +1 @@ +CMakeLists.txt not found in /home/liza/2sem/hw1 Select CMakeLists.txt diff --git a/hw1_pt1/cmake-build-debug/.ninja_deps b/hw1_pt1/cmake-build-debug/.ninja_deps index 838da3edf67f3b17419700ef81396799b21b0368..d8d49fbda38e49696b1edfc9f5c01b1847c82a55 100644 Binary files a/hw1_pt1/cmake-build-debug/.ninja_deps and b/hw1_pt1/cmake-build-debug/.ninja_deps differ diff --git a/hw1_pt1/cmake-build-debug/.ninja_log b/hw1_pt1/cmake-build-debug/.ninja_log index 438fa9f61e54b9c9ef46c2f9da38fac59c6121f5..8eb86204d522c31d77623ee79e6c11bc1d7f6a3c 100644 --- a/hw1_pt1/cmake-build-debug/.ninja_log +++ b/hw1_pt1/cmake-build-debug/.ninja_log @@ -2,3 +2,11 @@ 1 670 1639691704191458936 CMakeFiles/hw1_pt1.dir/funcs.cpp.o 1318eee7ad6aedd5 0 1105 1639691704627511111 CMakeFiles/hw1_pt1.dir/main.cpp.o a8c766f6a8f90a18 1105 1231 1639691704755526429 hw1_pt1 ed062b5b87a784b0 +2 846 1641602643807632454 CMakeFiles/hw1_pt1.dir/funcs.cpp.o 1318eee7ad6aedd5 +1 677 1641603118215888432 CMakeFiles/hw1_pt1.dir/funcs.cpp.o 1318eee7ad6aedd5 +2 597 1641603380083991205 CMakeFiles/hw1_pt1.dir/funcs.cpp.o 1318eee7ad6aedd5 +0 5 0 clean 4b7a79aec941ac6f +2 1116 1641603574043392273 CMakeFiles/hw1_pt1.dir/funcs.cpp.o 1318eee7ad6aedd5 +1 530 1641603635372818284 CMakeFiles/hw1_pt1.dir/funcs.cpp.o 1318eee7ad6aedd5 +1 985 1641603635824828269 CMakeFiles/hw1_pt1.dir/main.cpp.o a8c766f6a8f90a18 +985 1100 1641603635940830832 hw1_pt1 ed062b5b87a784b0 diff --git a/hw1_pt1/cmake-build-debug/2.txt b/hw1_pt1/cmake-build-debug/2.txt index e80ae14138e3bc61d1e6c836a95753283de39cf0..53c4a2962062f7b3c4c036e3af13dbe3af246183 100644 --- a/hw1_pt1/cmake-build-debug/2.txt +++ b/hw1_pt1/cmake-build-debug/2.txt @@ -1 +1 @@ --47 44 1 -1 -34 46 -35 46 31 16 -9 -12 -14 -2 -43 -9 19 -6 -42 -29 -15 12 5 30 -25 17 -41 -31 25 -47 26 -20 0 -22 29 -32 26 -4 -35 7 -38 -42 -3 -50 -42 4 -8 -20 0 0 1 36 -38 8 -32 39 27 29 11 2 -15 39 32 35 -33 11 5 -5 9 20 4 22 -20 -49 22 -11 -42 16 -29 8 -34 22 46 31 33 -35 -28 10 -4 -15 -37 31 -25 45 -32 44 -41 24 -10 18 \ No newline at end of file +2 -24 -12 -21 46 9 38 -45 21 12 23 49 26 1 -24 -38 0 -43 4 -33 46 39 43 -42 -24 17 10 34 2 -9 31 6 -31 -31 -13 -35 -20 -25 -30 3 -10 -5 2 -34 47 -20 -21 -3 -12 33 -34 36 -26 11 44 1 31 -43 37 35 -50 18 -8 -31 -11 -19 -15 19 7 -43 -28 47 3 -24 -37 -48 7 44 -49 -3 -20 -33 -17 4 -20 30 7 -39 37 47 47 37 15 41 8 -45 -28 -5 -24 -19 \ No newline at end of file diff --git a/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/funcs.cpp.o b/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/funcs.cpp.o index 2c3d09bd4552d45b5c9b4d53a14ddae77dd02d05..36698d6faccea10724fb4b2fb339202dcceae31a 100644 Binary files a/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/funcs.cpp.o and b/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/funcs.cpp.o differ diff --git a/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/main.cpp.o b/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/main.cpp.o index db05c720e74fced1fb6c62a290f6e4b0e9d1abd9..ed56815bf9cf94378f6931f6441b7d758d7128f2 100644 Binary files a/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/main.cpp.o and b/hw1_pt1/cmake-build-debug/CMakeFiles/hw1_pt1.dir/main.cpp.o differ diff --git a/hw1_pt1/cmake-build-debug/Testing/Temporary/LastTest.log b/hw1_pt1/cmake-build-debug/Testing/Temporary/LastTest.log index 7f4b2c4b5f53198483dd38f769630cbcfc57ef78..07b090113696ae1bef359aa8072f706713f85e1d 100644 --- a/hw1_pt1/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/hw1_pt1/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Jan 08 02:13 MSK +Start testing: Jan 08 04:01 MSK ---------------------------------------------------------- -End testing: Jan 08 02:13 MSK +End testing: Jan 08 04:01 MSK diff --git a/hw1_pt1/cmake-build-debug/hw1_pt1 b/hw1_pt1/cmake-build-debug/hw1_pt1 index b71d03459acf6a6ff65aacca66a6ce831aba5bf0..61b28e5d6c5432dbd14212a18fd24e6ab4f3518e 100755 Binary files a/hw1_pt1/cmake-build-debug/hw1_pt1 and b/hw1_pt1/cmake-build-debug/hw1_pt1 differ diff --git a/hw1_pt1/funcs.cpp b/hw1_pt1/funcs.cpp index ad8dafa368e1b1f53976726630cae371a237f01d..51f85141d725ff1ba8df1d0c9b6756bc9da1908b 100644 --- a/hw1_pt1/funcs.cpp +++ b/hw1_pt1/funcs.cpp @@ -9,13 +9,4 @@ fstream CreateData_1() f << dist(gen) << " "; return f; } -int RandomNumber () { return (-50 + rand()%100); } -fstream CreateData_2() -{ - fstream outf("2.txt");; - ostream_iterator intOut (outf , " " ); //!!! По заданию в функциях не должно быть предположений о типах. - vector tmp(100); - generate(tmp.begin(), tmp.end(), RandomNumber); - copy (tmp.begin(), tmp.end(), intOut); - return outf; -} + diff --git a/hw1_pt1/funcs.h b/hw1_pt1/funcs.h index d5f4a9d91f599e54dfd2cc9210f4960fd3909294..39c263cdfe14ff9a31e31c9b397c4b7644c6e18e 100644 --- a/hw1_pt1/funcs.h +++ b/hw1_pt1/funcs.h @@ -10,23 +10,36 @@ #include using namespace std; fstream CreateData_1(); -fstream CreateData_2(); + + +template +fstream CreateData_2() +{ + fstream outf("2.txt");; + ostream_iterator Out (outf , " " ); + vector tmp(100); + generate(tmp.begin(), tmp.end(), [] () {return (-50 + rand()%100);}); + copy (tmp.begin(), tmp.end(), Out); + return outf; +} template ContainerType LoadData_1(fstream &f) { + using value_type = typename ContainerType::value_type; ContainerType ans(100); f.seekg(ios_base::beg); - for (int& i : ans) //!!! По заданию в функциях не должно быть предположений о типах. Есть value_type. + for (value_type& i : ans) f >> i; return ans; } template ContainerType LoadData_2(fstream &f) { + using value_type = typename ContainerType::value_type; ContainerType l; f.seekg(ios_base::beg); - copy(istream_iterator(f), //!!! По заданию в функциях не должно быть предположений о типах. - istream_iterator(), //!!! По заданию в функциях не должно быть предположений о типах. + copy(istream_iterator(f), + istream_iterator(), back_inserter(l) ); return l; @@ -34,8 +47,9 @@ ContainerType LoadData_2(fstream &f) template void modify1(ContainerType& v) { - int m = *max_element(v.begin(), v.end()) / 2; //!!! По заданию в функциях не должно быть предположений о типах. - int n = v.size(), sum = 0; //!!! По заданию в функциях не должно быть предположений о типах. + using value_type = typename ContainerType::value_type; + value_type m = *max_element(v.begin(), v.end()) / 2; + value_type n = v.size(), sum = 0; v.resize(n + 2); /*for(auto x : v) { @@ -53,8 +67,9 @@ void modify1(ContainerType& v) template void modify3(ContainerType& v) { - int m = *max_element(v.begin(), v.end()) / 2; //!!! По заданию в функциях не должно быть предположений о типах. - for_each(v.begin(), v.end(), [m](int &x){return x /= m;}); //!!! По заданию в функциях не должно быть предположений о типах. + using value_type = typename ContainerType::value_type; + value_type m = *max_element(v.begin(), v.end()) / 2; + for_each(v.begin(), v.end(), [m](value_type &x){return x /= m;}); } template void modify2(Iterator b, Iterator e){ @@ -77,8 +92,9 @@ void modify2(Iterator b, Iterator e){ template void modify4(Container& v) { - int m = *max_element(v.begin(), v.end()) / 2; - transform(v.begin(), v.end(), v.begin(), [m](int &x){return x /= m;}); //!!! По заданию в функциях не должно быть предположений о типах. + using value_type = typename Container::value_type; + value_type m = *max_element(v.begin(), v.end()) / 2; + transform(v.begin(), v.end(), v.begin(), [m](int &x){return x /= m;}); } template fstream outputResult_1(const Container& x) @@ -91,8 +107,9 @@ fstream outputResult_1(const Container& x) template fstream outputResult_2(const Container& x) { + using value_type = typename Container::value_type; fstream outf("4.txt");; - ostream_iterator intOut (outf , " " ); //!!! По заданию в функциях не должно быть предположений о типах. + ostream_iterator intOut (outf , " " ); copy (x.begin(), x.end(), intOut); return outf; } @@ -112,8 +129,9 @@ Container menu1(fstream &outf) } template void menu2(Container& x){ - int s; //!!! По заданию в функциях не должно быть предположений о типах. - + using value_type = typename Container::value_type; + value_type s; + cout << "press 1 to modify data with template function (you will get sum and average at the end of container), "; cout << "press 2 to do it using iterators, press 3 to do it with for_each() or press 4 - with transform" << endl; cin >> s; diff --git a/hw1_pt1/main.cpp b/hw1_pt1/main.cpp index bf02cebe6134cb68162da301066413ffe7445f9a..ba9233d5a729f5878279747bea94ca2bdca3c27e 100644 --- a/hw1_pt1/main.cpp +++ b/hw1_pt1/main.cpp @@ -11,7 +11,7 @@ int main() { cin >> c; switch(c){ case 'f': outf = CreateData_1(); break; - case 'c': outf = CreateData_2(); break; + case 'c': outf = CreateData_2(); break; default: return 0; } cout << "press 1 to test vector, 2 to test list, 3 to test deque, press any other to exit." << endl; diff --git a/hw1_pt2/.idea/vcs.xml b/hw1_pt2/.idea/vcs.xml index b2bdec2d71b6a5ce4ae49efc37516809c50e4d5e..64713b81f3557f6879e5fe4965dcc1348e60fb9c 100644 --- a/hw1_pt2/.idea/vcs.xml +++ b/hw1_pt2/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/hw1_pt2/Sportik.cpp b/hw1_pt2/Sportik.cpp index dd3b480b5967109d63b17916bb937927ff4da6a6..ae6103fc9fa63649cd03a2da6827d0e8c2609edc 100644 --- a/hw1_pt2/Sportik.cpp +++ b/hw1_pt2/Sportik.cpp @@ -3,6 +3,7 @@ #include #include #include +#include void Sportik::to_txt() { std::ofstream file1(file + "_total.txt"); if (!file1.is_open()) { @@ -22,20 +23,22 @@ void Sportik::to_txt() { << std::setw(12) << x.second.sport << " |" << std::setw(12) << x.second.coach << " |" << std::setw(10) << x.second.duration << " |" - << std::setw(3) << x.second.start.tm_mday << "." << x.second.start.tm_mon << "." << x.second.start.tm_year << " |" + << std::setw(3) << x.second.day << "." << x.second.month << "." << x.second.year << " |" << std::setw(6) << x.second.price << " |" << std::endl; } } -std::map Sportik::find_by_client_surname(const std::string& surname){ +std::map Sportik::find_by_client_surname(const char surname[15]){ std::map ans; + std::string filename = surname; + filename += "_by_surname.bin"; for (auto x : clients) { if(x.second.client == surname){ ans.insert(x); } - std::ofstream file1(surname + "_by_surname.bin", std::ios::binary); + std::ofstream file1(filename, std::ios::binary); if (!file1.is_open()) { std::cerr << "Error: unable to open file" << std::endl; exit(0); @@ -47,14 +50,16 @@ std::map Sportik::find_by_client_surname(const std::string& surn } return ans; } -std::map Sportik::find_by_coach_surname(const std::string& surname){ +std::map Sportik::find_by_coach_surname(const char surname[15]){ std::map ans; - for (auto x : clients) //!!! Копирование на каждой итерации + std::string filename = surname; + filename += "_clients.bin"; + for (const auto& x : clients) { if(x.second.coach == surname){ ans.insert(x); } - std::ofstream file1(surname + "_clients.bin", std::ios::binary); + std::ofstream file1(filename, std::ios::binary); if (!file1.is_open()) { std::cerr << "Error: unable to open file" << std::endl; exit(0); @@ -66,14 +71,16 @@ std::map Sportik::find_by_coach_surname(const std::string& surna } return ans; } -std::map Sportik::find_by_sport(const std::string &sport) { +std::map Sportik::find_by_sport(const char sport[15]) { std::map ans; - for (auto x : clients) + std::string filename = sport; + filename += ".bin"; + for (const auto& x : clients) { if(x.second.sport == sport){ ans.insert(x); } - std::ofstream file1(sport + ".bin", std::ios::binary); + std::ofstream file1(filename, std::ios::binary); if (!file1.is_open()) { std::cerr << "Error: unable to open file" << std::endl; exit(0); @@ -88,7 +95,7 @@ std::map Sportik::find_by_sport(const std::string &sport) { std::map Sportik::find_by_experience_less(int exp){ std::map ans; - for (auto x : clients) //!!! Копирование на каждой итерации + for (const auto& x : clients) { if(x.second.duration < exp){ ans.insert(x); @@ -107,7 +114,7 @@ std::map Sportik::find_by_experience_less(int exp){ } std::map Sportik::find_by_experience_more(int exp){ std::map ans; - for (auto x : clients) //!!! Копирование на каждой итерации + for (const auto& x : clients) { if(x.second.duration > exp){ ans.insert(x); @@ -126,9 +133,9 @@ std::map Sportik::find_by_experience_more(int exp){ } std::map Sportik::find_by_date(int year, int month, int day){ std::map ans; - for (auto x : clients) //!!! Копирование на каждой итерации + for (const auto& x : clients) { - if((x.second.start.tm_year == year)&&(x.second.start.tm_mon == month)&&(x.second.start.tm_mday == day)){ + if((x.second.year == year)&&(x.second.month == month)&&(x.second.day == day)){ ans.insert(x); } std::string date = std::to_string(day) + "." + std::to_string(month) + "." + std::to_string(year); @@ -204,13 +211,13 @@ Sportsman::Sportsman() { std::cin >> duration; std::cout << std::endl << "Input year he started "; std::cin >> x; - start.tm_year = x; + year = x; std::cout << std::endl << "Input month he started "; std::cin >> x; - start.tm_mon = x; + month = x; std::cout << std::endl << "Input day he started "; std::cin >> x; - start.tm_mday = x; + day = x; std::cout << std::endl << "Input his tariff per minute "; std::cin >> price; } \ No newline at end of file diff --git a/hw1_pt2/Sportik.h b/hw1_pt2/Sportik.h index 8a9236f33f6935eef77ab3c9964a3415a9d1bf07..27781f44983dfd50f2b98492573f9f5e5a532f5a 100644 --- a/hw1_pt2/Sportik.h +++ b/hw1_pt2/Sportik.h @@ -7,16 +7,20 @@ #include struct Sportsman{ - std::string client; //!!! Для корректной работы с бинарными файлами нужно использовать статические массивы char + char client[15]; int sport_code; - std::string sport; //!!! Для корректной работы с бинарными файлами нужно использовать статические массивы char - std::string coach; //!!! Для корректной работы с бинарными файлами нужно использовать статические массивы char + char sport[15]; + char coach[15]; int duration; - std::tm start{}; ///!!! Типы должны быть простые + /*std::tm start{}; ///!!! Типы должны быть простые*/ + + int day; + int month; + int year; + float price; Sportsman(); - Sportsman(const std::string, int, const std::string /*!!! Почему строки по значению передаются?*/, const std::string, int, const tm*, int, float); }; class Sportik{ @@ -35,9 +39,9 @@ public: void add_creating(); void txt_statement(); void to_txt(); - std::map find_by_client_surname(const std::string& surname); - std::map find_by_coach_surname(const std::string& surname); - std::map find_by_sport(const std::string& surname); + std::map find_by_client_surname(const char surname[15]); + std::map find_by_coach_surname(const char surname[15]); + std::map find_by_sport(const char sport[15]); std::map find_by_experience_less(int exp); std::map find_by_experience_more(int exp); std::map find_by_date(int year, int month, int day); diff --git a/hw1_pt2/cmake-build-debug/.ninja_deps b/hw1_pt2/cmake-build-debug/.ninja_deps index 4a1e3349b3d74f94dda6d54e0e1116d6db7827c6..1e723710093aae600643a16c4b191b732e8dedf7 100644 Binary files a/hw1_pt2/cmake-build-debug/.ninja_deps and b/hw1_pt2/cmake-build-debug/.ninja_deps differ diff --git a/hw1_pt2/cmake-build-debug/.ninja_log b/hw1_pt2/cmake-build-debug/.ninja_log index 606abbe8bdaa364c1a113dceeeafdfa30181b9df..d58499fb8da3064770126100e5dfe588a128a418 100644 --- a/hw1_pt2/cmake-build-debug/.ninja_log +++ b/hw1_pt2/cmake-build-debug/.ninja_log @@ -5,3 +5,14 @@ 1 566 1639687977357308779 CMakeFiles/hw1.dir/main.cpp.o cbaa99001b1165bd 1 1159 1639687977949313343 CMakeFiles/hw1.dir/Sportik.cpp.o 9f3ce2b8e64b3b64 1159 1250 1639687978041314053 hw1 3dc4f3e46306eccb +1 3117 1641605834079381923 CMakeFiles/hw1.dir/Sportik.cpp.o 9f3ce2b8e64b3b64 +1 591 1641605889059281169 CMakeFiles/hw1.dir/main.cpp.o cbaa99001b1165bd +591 719 1641605889187280964 hw1 3dc4f3e46306eccb +1 1438 1641606352319186079 CMakeFiles/hw1.dir/main.cpp.o cbaa99001b1165bd +2 3228 1641606354107187571 CMakeFiles/hw1.dir/Sportik.cpp.o 9f3ce2b8e64b3b64 +3228 3443 1641606354323187752 hw1 3dc4f3e46306eccb +1 1256 1641606632427525452 CMakeFiles/hw1.dir/main.cpp.o cbaa99001b1165bd +1 3013 1641606634183528139 CMakeFiles/hw1.dir/Sportik.cpp.o 9f3ce2b8e64b3b64 +3013 3221 1641606634391528458 hw1 3dc4f3e46306eccb +1 1099 1641607846039259244 CMakeFiles/hw1.dir/Sportik.cpp.o 9f3ce2b8e64b3b64 +1099 1206 1641607846147255379 hw1 3dc4f3e46306eccb diff --git a/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/Sportik.cpp.o b/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/Sportik.cpp.o index d6dd436ac6703445b25791a80d62cdabc9c7ca9d..e741f42c3230dfc35d6feeec134f274c5fd57dcb 100644 Binary files a/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/Sportik.cpp.o and b/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/Sportik.cpp.o differ diff --git a/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/main.cpp.o b/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/main.cpp.o index 783c70077b79ca595a5a1503b9250f937247ba8d..b86256a43a30f8c4a21e099d401d3b82cfed92f3 100644 Binary files a/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/main.cpp.o and b/hw1_pt2/cmake-build-debug/CMakeFiles/hw1.dir/main.cpp.o differ diff --git a/hw1_pt2/cmake-build-debug/Testing/Temporary/LastTest.log b/hw1_pt2/cmake-build-debug/Testing/Temporary/LastTest.log index 4f716034d0e990cdb21c265478f95b2895c7a89b..402cb00ad1da7235f280b864f109853df41567ff 100644 --- a/hw1_pt2/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/hw1_pt2/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Dec 16 23:52 MSK +Start testing: Jan 08 05:10 MSK ---------------------------------------------------------- -End testing: Dec 16 23:52 MSK +End testing: Jan 08 05:10 MSK diff --git a/hw1_pt2/cmake-build-debug/_total.txt b/hw1_pt2/cmake-build-debug/_total.txt new file mode 100644 index 0000000000000000000000000000000000000000..b844e74f848cae8022a5ec242a2045a1b02ecedf --- /dev/null +++ b/hw1_pt2/cmake-build-debug/_total.txt @@ -0,0 +1,4 @@ + All clients + +| id | Client's name | code | activity | coach | duration | started on | price | +| 1 | natalina | 3 | handball | kravchenko | 2002020 | 25.4.2002 | 0 | diff --git a/hw1_pt2/cmake-build-debug/hw1 b/hw1_pt2/cmake-build-debug/hw1 index da9e8614a9a33ac30b663ac521de97d31aae16a5..80c21a3046371aa7f14cbad2a4cd9ed870c177ce 100755 Binary files a/hw1_pt2/cmake-build-debug/hw1 and b/hw1_pt2/cmake-build-debug/hw1 differ diff --git a/hw1_pt2/main.cpp b/hw1_pt2/main.cpp index 35785e63f593972cfa681ab704d18eeeb341f218..dc2485234c628184321092c2794e74dc3ca3ba73 100644 --- a/hw1_pt2/main.cpp +++ b/hw1_pt2/main.cpp @@ -5,7 +5,7 @@ int main() { int key = 1, code; int x, y, z; std::string filename; - std::string value; + char value[15]; std::cout << "Input filename" << std::endl; std::cin >> filename; Sportik fitness = Sportik(filename);