diff --git a/Hw1/task1.cpp b/Hw1/task1.cpp index 77cc301..ae2e3ec 100644 --- a/Hw1/task1.cpp +++ b/Hw1/task1.cpp @@ -3,8 +3,7 @@ using namespace std; -class Student -{ +class Student { uint number; string first_name; string second_name; @@ -19,8 +18,7 @@ public: uint first_var(uint num_of_vars) { - if (num_of_vars == 0) - { + if (num_of_vars == 0) { return 0; } @@ -28,22 +26,21 @@ public: } uint second_var(uint num_of_vars) { - if (num_of_vars == 0) - { + if (num_of_vars == 0) { return 0; } return (uint)first_name.front() % num_of_vars; } uint third_var(uint num_of_vars) { - if (num_of_vars == 0) - { + if (num_of_vars == 0) { return 0; } return (uint)second_name.front() % num_of_vars; } - void print_name () { + void print_name() + { cout << number << ". " << first_name << " " << second_name << "\n"; } }; @@ -58,7 +55,7 @@ int main() cout << "Первый тип варианта: " << a.first_var(num_of_vars) << "\n"; cout << "Второй тип варианта: " << a.second_var(num_of_vars) << "\n"; cout << "Третий тип варианта: " << a.third_var(num_of_vars) << "\n"; - + Student b = Student(4, "Иван", "Олегович"); b.print_name(); cout << "Первый тип варианта: " << b.first_var(num_of_vars) << "\n"; diff --git a/Hw1/task2.cpp b/Hw1/task2.cpp index 5a92212..9f04167 100644 --- a/Hw1/task2.cpp +++ b/Hw1/task2.cpp @@ -5,42 +5,37 @@ using namespace std; void part1(uint N, uint M) { - for (uint n = 0; n < N; n++) - { - for (uint m = 0; m < M; m++) - { - cout << "*"; - } - cout << "\n"; - } - cout << "\n"; + for (uint n = 0; n < N; n++) { + for (uint m = 0; m < M; m++) { + cout << "*"; + } + cout << "\n"; + } + cout << "\n"; } void part2(uint N, uint M) { - for (uint n = 0; n < N; n++) - { - if (n < M) - for (uint i = 0; i < M-n; i++) - { - cout << " "; - } - for (uint j = 0; j < n*2; j++) - { - cout << "*"; - } - cout << "\n"; - } - cout << "\n"; + for (uint n = 0; n < N; n++) { + if (n < M) + for (uint i = 0; i < M - n; i++) { + cout << " "; + } + for (uint j = 0; j < n * 2; j++) { + cout << "*"; + } + cout << "\n"; + } + cout << "\n"; } int main() { - uint N = 6; - uint M = 6; + uint N = 6; + uint M = 6; - part1(N, M); - part2(N, M); + part1(N, M); + part2(N, M); - return 0; + return 0; } diff --git a/Sem1/main.cpp b/Sem1/main.cpp index d997d1f..317576a 100644 --- a/Sem1/main.cpp +++ b/Sem1/main.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include using namespace std; @@ -14,22 +14,19 @@ using namespace std; y */ -class Image -{ +class Image { uint mx; uint my; - uint *data; + uint* data; public: Image(uint tmx, uint tmy) { // Должен инициализировать изображение 0 mx = tmx; my = tmy; - data = (uint *)malloc(sizeof(uint) * mx * my); - for (uint y = 0; y < my; y++) - { - for (uint x = 0; x < mx; x++) - { + data = (uint*)malloc(sizeof(uint) * mx * my); + for (uint y = 0; y < my; y++) { + for (uint x = 0; x < mx; x++) { data[mx * y + x] = 27; } } @@ -52,10 +49,8 @@ public: void show() { // Должен выдавать на экран изображение при помощи printf или std::cout - for (uint y = 0; y < my; y++) - { - for (uint x = 0; x < mx; x++) - { + for (uint y = 0; y < my; y++) { + for (uint x = 0; x < mx; x++) { cout << "\033[48;5;" << data[mx * y + x] << "m \033[0m"; } cout << "\n"; @@ -70,52 +65,42 @@ public: void set(uint x, uint y, uint color) { - if (x >= mx) - { + if (x >= mx) { throw(x); } - if (y >= my) - { + if (y >= my) { throw(y); } data[mx * (y) + (x)] = color; } - void copy(Image &original) + void copy(Image& original) { freemem(); mx = original.getMx(); my = original.getMy(); - data = (uint *)malloc(sizeof(uint) * mx * my); - for (uint y = 0; y < my; y++) - { - for (uint x = 0; x < mx; x++) - { + data = (uint*)malloc(sizeof(uint) * mx * my); + for (uint y = 0; y < my; y++) { + for (uint x = 0; x < mx; x++) { data[mx * y + x] = original.get(x, y); } } } // Returns true if equal - bool compare(Image &original) + bool compare(Image& original) { - if (original.getMx() == mx && original.getMy() == my) - { - for (uint y = 0; y < my; y++) - { - for (uint x = 0; x < mx; x++) - { - if (data[mx * y + x] != original.get(x, y)) - { + if (original.getMx() == mx && original.getMy() == my) { + for (uint y = 0; y < my; y++) { + for (uint x = 0; x < mx; x++) { + if (data[mx * y + x] != original.get(x, y)) { cout << "Not equal: x = " << x << "; y = " << y << "\n"; return false; } } } return true; - } - else - { + } else { cout << "original size: " << original.getMx() << "x" << original.getMy() << "\n"; cout << "current size: " << mx << "x" << my << "\n"; return false; @@ -124,24 +109,20 @@ public: void draw_horizontal(uint y, uint color) { - if (y >= my) - { + if (y >= my) { throw(y); } - for (uint x = 0; x < mx; x++) - { + for (uint x = 0; x < mx; x++) { data[mx * y + x] = color; } } void draw_vertical(uint x, uint color) { - if (x >= mx) - { + if (x >= mx) { throw(x); } - for (uint y = 0; y < my; y++) - { + for (uint y = 0; y < my; y++) { data[mx * y + x] = color; } } @@ -150,22 +131,17 @@ public: { ofstream writefile; writefile.open(filename); - if (writefile.is_open()) - { + if (writefile.is_open()) { writefile << mx << "\n" << my << "\n"; - for (uint y = 0; y < my; y++) - { - for (uint x = 0; x < mx; x++) - { + for (uint y = 0; y < my; y++) { + for (uint x = 0; x < mx; x++) { writefile << data[mx * y + x] << "\n"; } } writefile << "\n"; writefile.close(); - } - else - { + } else { cerr << "saving to file failed\n"; } } @@ -175,32 +151,24 @@ public: string line; ifstream readfile; readfile.open(filename); - if (readfile.is_open()) - { - try - { + if (readfile.is_open()) { + try { getline(readfile, line); mx = stoi(line); getline(readfile, line); my = stoi(line); - for (uint y = 0; y < my; y++) - { - for (uint x = 0; x < mx; x++) - { + for (uint y = 0; y < my; y++) { + for (uint x = 0; x < mx; x++) { getline(readfile, line); data[mx * y + x] = stoi(line); } } - } - catch (const exception &e) - { + } catch (const exception& e) { cerr << e.what() << '\n'; } - } - else - { + } else { cerr << "reading file failed"; } readfile.close(); @@ -217,18 +185,14 @@ int main() cout << "Image b \n"; b.show(); b.copy(a); - if (b.compare(a) == true) - { + if (b.compare(a) == true) { cout << "a == b after copy\n"; - } - else - { + } else { cout << "a != b after copy!\n"; } b.set(4, 3, 20); - for (int i = 5; i < 9; i++) - { + for (int i = 5; i < 9; i++) { b.set(i, 5, 45); } b.set(9, 3, 20);