From 0ae4eb55525c12ded04992114ced638080703067 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Tue, 11 Jun 2024 10:48:26 +0300 Subject: [PATCH] Fix Lesson 1 --- Lesson_1/Task_1/main.cpp | 5 ++++- Lesson_1/Task_2/main.cpp | 12 +++++++----- Lesson_1/Task_3/main.cpp | 14 ++++++++------ Lesson_1/Task_4/main.cpp | 22 ++++++++++++---------- Lesson_1/Task_5/main.cpp | 24 +++++++++++++----------- Lesson_1/Task_6/main.cpp | 16 +++++++++------- Lesson_1/Task_7/main.cpp | 24 ++++++++++++------------ 7 files changed, 65 insertions(+), 52 deletions(-) diff --git a/Lesson_1/Task_1/main.cpp b/Lesson_1/Task_1/main.cpp index b851994..efa4f74 100644 --- a/Lesson_1/Task_1/main.cpp +++ b/Lesson_1/Task_1/main.cpp @@ -1,7 +1,10 @@ #include +using namespace std; + int main() { - std::cout << "Stanislav" << std::endl << "Mykhailenko" << std::endl; + cout << "Stanislav" << endl; + cout << "Mykhailenko" << endl; return 0; } diff --git a/Lesson_1/Task_2/main.cpp b/Lesson_1/Task_2/main.cpp index 7b353ca..402abcd 100644 --- a/Lesson_1/Task_2/main.cpp +++ b/Lesson_1/Task_2/main.cpp @@ -1,17 +1,19 @@ #include +using namespace std; + int main() { float firstNumber = 0; float secondNumber = 0; - std::cout << "Enter the first number: "; - std::cin >> firstNumber; + cout << "Enter the first number: "; + cin >> firstNumber; - std::cout << "Enter the second number: "; - std::cin >> secondNumber; + cout << "Enter the second number: "; + cin >> secondNumber; - std::cout << firstNumber + secondNumber << std::endl; + cout << firstNumber + secondNumber << endl; return 0; } diff --git a/Lesson_1/Task_3/main.cpp b/Lesson_1/Task_3/main.cpp index 1ee6afb..30dbb95 100644 --- a/Lesson_1/Task_3/main.cpp +++ b/Lesson_1/Task_3/main.cpp @@ -1,21 +1,23 @@ #include +using namespace std; + int main() { int money = 0; - std::cout << "How much money do you earn? "; - std::cin >> money; + cout << "How much money do you earn? "; + cin >> money; if (money < 1000) - std::cout << "Work more. "; + cout << "Work more. "; if (money > 1000) { if (money > 1000000) - std::cout << "You are a millionaire. "; + cout << "You are a millionaire. "; if (money < 1000000) - std::cout << "You work great. "; + cout << "You work great. "; } - std::cout << "You are doing great!" << std::endl; + cout << "You are doing great!" << endl; return 0; } diff --git a/Lesson_1/Task_4/main.cpp b/Lesson_1/Task_4/main.cpp index 6da8c35..09c05a5 100644 --- a/Lesson_1/Task_4/main.cpp +++ b/Lesson_1/Task_4/main.cpp @@ -1,20 +1,22 @@ #include +using namespace std; + int main() { float firstNumber = 0; float secondNumber = 0; float result = 0; - char operation; + char operation = 0; - std::cout << "Enter the first number: "; - std::cin >> firstNumber; + cout << "Enter the first number: "; + cin >> firstNumber; - std::cout << "Enter the second number: "; - std::cin >> secondNumber; + cout << "Enter the second number: "; + cin >> secondNumber; - std::cout << "Enter operation: "; - std::cin >> operation; + cout << "Enter operation: "; + cin >> operation; switch (operation) { case '+': @@ -28,18 +30,18 @@ int main() break; case '/': if (secondNumber == 0) { - std::cout << "Division by zero" << std::endl; + cout << "Division by zero" << endl; return 1; } result = firstNumber / secondNumber; break; default: - std::cout << "Unknown operation." << std::endl; + cout << "Unknown operation." << endl; return 2; break; } - std::cout << result << std::endl; + cout << result << endl; return 0; } diff --git a/Lesson_1/Task_5/main.cpp b/Lesson_1/Task_5/main.cpp index 56e981f..b90df32 100644 --- a/Lesson_1/Task_5/main.cpp +++ b/Lesson_1/Task_5/main.cpp @@ -2,6 +2,8 @@ #include #include +using namespace std; + int main() { float a = 0; @@ -9,24 +11,24 @@ int main() float c = 0; float D = 0; - std::cout << "Enter a: "; - std::cin >> a; + cout << "Enter a: "; + cin >> a; - std::cout << "Enter b: "; - std::cin >> b; + cout << "Enter b: "; + cin >> b; - std::cout << "Enter c: "; - std::cin >> c; + cout << "Enter c: "; + cin >> c; D = pow(b, 2) - 4 * a * c; - std::complex root = std::sqrt(std::complex(D)); + complex root = sqrt(complex(D)); - std::complex x1 = (-b + root) / (2 * a); - std::complex x2 = (-b - root) / (2 * a); + complex x1 = (-b + root) / (2 * a); + complex x2 = (-b - root) / (2 * a); - std::cout << "x1 = " << x1 << std::endl; - std::cout << "x2 = " << x2 << std::endl; + cout << "x1 = " << x1 << endl; + cout << "x2 = " << x2 << endl; return 0; } diff --git a/Lesson_1/Task_6/main.cpp b/Lesson_1/Task_6/main.cpp index c8c30c1..53313c4 100644 --- a/Lesson_1/Task_6/main.cpp +++ b/Lesson_1/Task_6/main.cpp @@ -1,25 +1,27 @@ #include +using namespace std; + int main() { int size = 0; - std::cout << "Enter size: "; - std::cin >> size; + cout << "Enter size: "; + cin >> size; for (int iteration = 0; iteration < size; ++iteration) { int spaces = size - iteration - 1; int asterisks = 1 + iteration * 2; for (int space = 0; space < spaces; ++space) - std::cout << " "; + cout << " "; for (int asterisk = 0; asterisk < asterisks; ++asterisk) - std::cout << "*"; - std::cout << std::endl; + cout << "*"; + cout << endl; } for (int space = 0; space < size - 1; ++space) - std::cout << " "; - std::cout << "*" << std::endl; + cout << " "; + cout << "*" << endl; return 0; } diff --git a/Lesson_1/Task_7/main.cpp b/Lesson_1/Task_7/main.cpp index 6a4ec3a..65b7db3 100644 --- a/Lesson_1/Task_7/main.cpp +++ b/Lesson_1/Task_7/main.cpp @@ -1,6 +1,8 @@ #include #include +using namespace std; + int main() { float x = 0; @@ -8,23 +10,21 @@ int main() float N = 0; float distance = 0; - std::cout << "x = "; - std::cin >> x; + cout << "Enter your x: "; + cin >> x; - std::cout << "y = "; - std::cin >> y; + cout << "Enter your y: "; + cin >> y; - std::cout << "N = "; - std::cin >> N; - - if (x > N || y > N) { - std::cout << "Beyond radius." << std::endl; - return 1; - } + cout << "Enter radius N: "; + cin >> N; distance = sqrt(pow(x, 2) + pow(y, 2)); - std::cout << distance << std::endl; + cout << distance << " from the center"; + if (distance > N) + cout << " (beyond radius)"; + cout << endl; return 0; }