diff options
Rename change
9 files changed, 296 insertions, 0 deletions
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task1.cpp | 20 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task2.cpp | 29 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp | 23 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp | 24 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task4.cpp | 26 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task5.cpp | 51 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task6.cpp | 42 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Solutions/task7.cpp | 44 | ||||
| -rw-r--r-- | pract_SI/Pract. 02/Tasks_2.txt | 37 |
diff --git a/pract_SI/Pract. 02/Solutions/task1.cpp b/pract_SI/Pract. 02/Solutions/task1.cpp new file mode 100644 index 0000000..3a60fad --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task1.cpp @@ -0,0 +1,20 @@ +#include<iostream> +using namespace std; +int main() +{ + int year; + + cout << "Enter an year to check: "; + cin >> year; + + cout << year << " is"; + + if (!(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))) + { + cout << " not"; + } + + cout << " leap!\n"; + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task2.cpp b/pract_SI/Pract. 02/Solutions/task2.cpp new file mode 100644 index 0000000..a1ddcf8 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task2.cpp @@ -0,0 +1,29 @@ +#include<iostream> +using namespace std; +int main() +{ + char inputCharacter; + + cout << "Enter a character to test: "; + cin >> inputCharacter; + + cout << inputCharacter << " is "; + if (inputCharacter == 'a' || inputCharacter == 'e' || inputCharacter == 'i' || inputCharacter == 'o' || inputCharacter == 'u' || + inputCharacter == 'A' || inputCharacter == 'E' || inputCharacter == 'I' || inputCharacter == 'O' || inputCharacter == 'U') + { + cout << "a vowel!\n"; + } + else + { + if ((inputCharacter >= 'a' && inputCharacter <= 'z') || (inputCharacter >= 'A' && inputCharacter <= 'Z')) + { + cout << "a consonant!\n"; + } + else + { + cout << "is not a letter from the English alphabet!\n"; + } + } + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp new file mode 100644 index 0000000..6c9f832 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp @@ -0,0 +1,23 @@ +#include<iostream> +#include<cmath> +using namespace std; +int main() +{ + double x, y; + + cout << "Enter the first number: "; + cin >> x; + + cout << "Enter the second number: "; + cin >> y; + + if (fabs(x - y) < 0.000001) + { + cout << "Numbers must be different!\n"; + return 1; + } + + cout << (x < y ? y : x) << " is the greater number!\n"; + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp new file mode 100644 index 0000000..dcd5f88 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp @@ -0,0 +1,24 @@ +#include <iostream> +#include <cmath> +using namespace std; + +int main() +{ + double num1, num2; + + cout << "Enter the first number: "; + cin >> num1; + + cout << "Enter the second number: "; + cin >> num2; + + if (fabs(num1 - num2) <= DBL_EPSILON * fabs(num1)) + { + cout << "Numbers must be different!\n"; + return 1; + } + + cout << (num1 > num2 ? "First" : "Second") << " is the greater number!\n"; + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task4.cpp b/pract_SI/Pract. 02/Solutions/task4.cpp new file mode 100644 index 0000000..acb471c --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task4.cpp @@ -0,0 +1,26 @@ +#include<iostream> +using namespace std; +int main() +{ + double a, b, c; + + cout << "First side: "; + cin >> a; + + cout << "Second side: "; + cin >> b; + + cout << "Third side: "; + cin >> c; + + if ((a + b > c) && (a + c > b) && (b + c > a)) + { + cout << "Triangle is valid.\n"; + } + else + { + cout << "Triangle is not valid.\n"; + } + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task5.cpp b/pract_SI/Pract. 02/Solutions/task5.cpp new file mode 100644 index 0000000..419d6d4 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task5.cpp @@ -0,0 +1,51 @@ +#include<iostream> +#include<cmath> +using namespace std; +int main() +{ + double a, b, c; + double root1, root2, imaginary; + double discriminant; + + cout << "Finding the root of the equation a * x^2 + b * x + c = 0\n"; + + cout << "Enter the value of a: "; + cin >> a; + + if (a < 0.00000001) + { + cout << "If a is 0, then this is not a quadratic equation!\n"; + return 1; + } + + cout << "Enter the value of b: "; + cin >> b; + + cout << "Enter the value of c: "; + cin >> c; + + discriminant = (b * b) - (4 * a * c); + + if (discriminant > 0) + { + root1 = (-b + sqrt(discriminant)) / (2 * a); + root2 = (-b - sqrt(discriminant)) / (2 * a); + + cout << "Two distinct and real roots exist: " << root1 << " and " << root2 << endl; + } + else if (discriminant == 0) + { + root1 = root2 = -b / (2 * a); + + cout << "Two equal and real roots exist: " << root1 << " and " << root2 << endl; + } + else if (discriminant < 0) + { + root1 = root2 = -b / (2 * a); + imaginary = sqrt(-discriminant) / (2 * a); + + cout << "Two distinct complex roots exist: " << root1 << "+" << imaginary << "i and " << root2 << "-" << imaginary << "i\n"; + } + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task6.cpp b/pract_SI/Pract. 02/Solutions/task6.cpp new file mode 100644 index 0000000..a7484b2 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task6.cpp @@ -0,0 +1,42 @@ +#include<iostream> +using namespace std; +int main() +{ + double a, b; + char operation; + + cout << "Enter the first number: "; + cin >> a; + + cout << "Enter the second number: "; + cin >> b; + + cout << "Choose operation: +, -, / or *: "; + cin >> operation; + + switch (operation) + { + case '+': + cout << "Result: " << a + b << endl; + break; + case '-': + cout << "Result: " << a - b << endl; + break; + case '*': + cout << "Result: " << a * b << endl; + break; + case '/': + if (b < 0.0000001) + { + cout << "You can not divide by zero!\n"; + return 1; + } + cout << "Result: " << a / b << endl; + break; + default: + cout << "Invalid operation!\n"; + break; + } + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task7.cpp b/pract_SI/Pract. 02/Solutions/task7.cpp new file mode 100644 index 0000000..3c22a83 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task7.cpp @@ -0,0 +1,44 @@ +#include<iostream> +using namespace std; +int main() +{ + // you can use int as well, but do you really need something as big as int? + short number; + unsigned char digit1, digit2, digit3, digit4, number1, number2; + + cout << "Enter a 4-digit number: "; + cin >> number; + + if (number < 1000 || number > 10000) + { + cout << "The input must be a 4-digit number!\n"; + return 1; + } + + digit1 = number / 1000; + digit2 = number / 100 % 10; + digit3 = number / 10 % 10; + digit4 = number % 10; + + number1 = digit1 * 10 + digit4; + number2 = digit2 * 10 + digit3; + + if (number1 < number2) + { + cout << "less (" << (int)number1 << " < " << (int)number2 << ")\n"; + } + else + { + if (number1 == number2) + { + cout << "equal (" << (int)number1 << " = " << (int)number2 << ")\n"; + } + else + { + cout << "greater (" << (int)number1 << " > " << (int)number2 << ")\n"; + } + } + + + return 0; +}
\ No newline at end of file diff --git a/pract_SI/Pract. 02/Tasks_2.txt b/pract_SI/Pract. 02/Tasks_2.txt new file mode 100644 index 0000000..a419241 --- /dev/null +++ b/pract_SI/Pract. 02/Tasks_2.txt @@ -0,0 +1,37 @@ +#Никола Светославов - task2 + +## Задачи + +1. Напишете програма,която проверява дали въведена от потребителя година е високосна. + **Проверете сами кои години се считат за високосни** + +2. Напишете програма, която приема един символ от входа и проверява дали: + + * този символ е буква от латинската азбука; + * ако да, дали тази буква е гласна или съгласна. + + **Програмата да работи както за малки, така и за главни букви** + +3. Напишете програма, която приема две **различни** числа и казва кое е по голямо. + **Използвайте тернарен оператор** + +4. Напишете програма, която приема от входа три числа - страни на триъгълник. + Програмата да проверява дали това е валиден триъгълник. + +5. Напишете програма, която намира корените на квадратно уравнение. + За целта потребителя да въведе коефицентите на уравнението - *a*, *b*, и *c* + при уравнение с вид *a \* x^2 + b \* x + c = 0*. + +6. Напишете прост калкулатор, който поддържа операциите +, -, *, / на две реални числа. + **Внимавайте с делението на 0** + +7. Да се състави програма, чрез която се въвежда 4-цифренo естествено число от интервала [1000.. 9999]. + От това число се формират 2 нови 2-цифрени числа. Първото число се формира от 1-та и 4-та цифра на въведеното + число. Второто число се формира от 2-рa - 3-та цифра на въведеното число.На екрана да се изведе дали + 1-то ново число e по-малко <, равно = или по-голямо от 2-то число. + Използвайте проверка на логическо условие - оператор if. + //Задачата е взета от [тук](http://1001zadachi.com/оператор_if_сравняване_числа.html). + + **Пример: 3332 Изход: less (32<33) + **Пример: 1144 Изход: equal (14=14) + **Пример: 9875 Изход: greater (95>87) |
