Created
April 26, 2025 17:23
-
-
Save DO162/f5acc44b9c55a9fe5e30a341653a7d0f to your computer and use it in GitHub Desktop.
DZ_9_(03.04.25)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <windows.h> | |
using namespace std; | |
enum Color : short { | |
BLACK, DARKBLUE, DARKGREEN, TURQUOISE, DARKRED, | |
PURPLE, DARKYELLOW, GREY, DARKGREY, BLUE, GREEN, | |
CYAN, RED, PINK, YELLOW, WHITE | |
}; | |
//----------------- | |
void Line(int lenght, char symbol, int color, bool h_v = true) { | |
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(h, color); | |
if (h_v) // horizontal line | |
{ | |
for (int i = 0; i < lenght; i++) | |
{ | |
cout << symbol; | |
} | |
} | |
else // vertical line | |
{ | |
for (int i = 0; i < lenght; i++) | |
{ | |
cout << symbol << "\n"; | |
} | |
} | |
cout << "\n"; | |
SetConsoleTextAttribute(h, 7); | |
} | |
//----------------- | |
void Rectangle(int width, char symbol_on, char symbol_in, | |
Color color_on, Color color_in, int coord_X, int coord_Y) { | |
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | |
COORD coord; | |
coord.X = coord_X; | |
coord.Y = coord_Y; | |
SetConsoleCursorPosition(h, coord); | |
int pause = 1; | |
int height = width; | |
for (int y = 0; y < height; y++) { | |
for (int x = 0; x < width; x++) { | |
if (x == 0 || y == 0 || | |
x == width - 1 || y == height - 1 || | |
x == y || x + y == width - 1) { | |
SetConsoleTextAttribute(h, color_on); | |
cout << symbol_on; | |
} | |
else { | |
SetConsoleTextAttribute(h, color_in); | |
cout << symbol_in; | |
} | |
Sleep(pause); | |
} | |
coord.Y++; | |
SetConsoleCursorPosition(h, coord); | |
} | |
SetConsoleTextAttribute(h, 7); | |
} | |
//----------------- | |
double cube(double num) { | |
return num * num * num; | |
} | |
//----------------- | |
bool Prime_number(int num) { | |
if (num <= 1) { | |
return false; | |
} | |
for (int i = 2; i*i <= num; i++) { | |
if (num % i == 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
//----------------- | |
int main() | |
{ | |
cout << boolalpha; | |
//setlocale(0, ""); | |
SetConsoleOutputCP(1251); | |
//---------------------------------Задание 1----------------------------------- | |
cout << "Задание #1" << "\n\n"; | |
SetConsoleOutputCP(866); | |
Line(10, '@', 12, true); | |
cout << "\n"; | |
Line(10, '@', 12, false); | |
SetConsoleOutputCP(1251); | |
//---------------------------------Задание 2----------------------------------- | |
cout << "Задание #2" << "\n\n"; | |
SetConsoleOutputCP(866); | |
/*for (int i = 0; i < 256; i++) | |
{ | |
cout << (char)i << " - " << i << "\n"; | |
}*/ | |
Rectangle(20, 178, '*', Color::RED, Color::BLUE, 5, 17); | |
SetConsoleOutputCP(1251); | |
//---------------------------------Задание 3----------------------------------- | |
cout << "\nЗадание #3" << "\n\n"; | |
double n; | |
cout << "Введіть число: "; | |
cin >> n; | |
cout << "Куб числа " << n << ": " << cube(n) << "\n\n"; | |
//---------------------------------Задание 4----------------------------------- | |
cout << "Задание #4" << "\n\n"; | |
int a; | |
cout << "Введіть число: "; | |
cin >> a; | |
cout << "Чи просте число " << a << ": " << Prime_number(a) << "\n\n"; | |
int b; | |
cout << "Введіть число: "; | |
cin >> b; | |
cout << "Чи просте число " << b << ": " << Prime_number(b) << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment