Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit653bd0b31519cf279e402fd177a40bafbcffc897 (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-10-28 17:37:38 +0300
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-10-28 17:37:38 +0300
Files6357e5f739027eb5c77e405e0b273449cadda0b9
Introduction_to_programming_FMI-653bd0b31519cf279e402fd177a40bafbcffc897.tar
Introduction_to_programming_FMI-653bd0b31519cf279e402fd177a40bafbcffc897.tar.gz
Introduction_to_programming_FMI-653bd0b31519cf279e402fd177a40bafbcffc897.zip
Parent00f15aa8d69a53c3ffa55661283aa06a6d6bd30f (diff)
Update Pract 01-03. Rename
diff --git a/pract_SI/Pract. 01/Solutions/task1.cpp b/pract_SI/Pract. 01/Solutions/task1.cpp
new file mode 100644
index 0000000..54a1902
--- /dev/null
+++ b/pract_SI/Pract. 01/Solutions/task1.cpp
@@ -0,0 +1,12 @@
+#include<iostream>
+#include<string>
+using namespace std;
+int main()
+{
+ string name;
+ cout << "What is your name?\n";
+ cin >> name;
+ cout << "Hello, " << name << endl;
+
+ return 0;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 01/Solutions/task2.cpp b/pract_SI/Pract. 01/Solutions/task2.cpp
new file mode 100644
index 0000000..554653d
--- /dev/null
+++ b/pract_SI/Pract. 01/Solutions/task2.cpp
@@ -0,0 +1,17 @@
+#include<iostream>
+using namespace std;
+int main()
+{
+ double x, y;
+
+ cout << "First side: ";
+ cin >> x;
+
+ cout << "Second side: ";
+ cin >> y;
+
+ cout << "Parameter: " << 2 * (x + y) << endl;
+ cout << "Area: " << x * y << endl;
+
+ return 0;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 01/Solutions/task3.cpp b/pract_SI/Pract. 01/Solutions/task3.cpp
new file mode 100644
index 0000000..830348b
--- /dev/null
+++ b/pract_SI/Pract. 01/Solutions/task3.cpp
@@ -0,0 +1,16 @@
+#include<iostream>
+using namespace std;
+int main()
+{
+ double a, b;
+
+ cout << "First number: ";
+ cin >> a;
+
+ cout << "Second number: ";
+ cin >> b;
+
+ cout << boolalpha << (a < b) << endl;
+
+ return 0;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 01/Solutions/task4.cpp b/pract_SI/Pract. 01/Solutions/task4.cpp
new file mode 100644
index 0000000..b4829b4
--- /dev/null
+++ b/pract_SI/Pract. 01/Solutions/task4.cpp
@@ -0,0 +1,23 @@
+#include<iostream>
+#include<cmath>
+using namespace std;
+int main()
+{
+ double x1, y1, x2, y2;
+
+ cout << "x1: ";
+ cin >> x1;
+
+ cout << "y1: ";
+ cin >> y1;
+
+ cout << "x2: ";
+ cin >> x2;
+
+ cout << "y2: ";
+ cin >> y2;
+
+ cout << round(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) * 100) / 100 << endl;
+
+ return 0;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 01/Solutions/task5.cpp b/pract_SI/Pract. 01/Solutions/task5.cpp
new file mode 100644
index 0000000..931178d
--- /dev/null
+++ b/pract_SI/Pract. 01/Solutions/task5.cpp
@@ -0,0 +1,16 @@
+#include<iostream>
+#include<string>
+#include<iomanip>
+using namespace std;
+int main()
+{
+ string card_number;
+
+ cout << "Card number: ";
+ cin >> card_number;
+
+ cout << "Hidden card number: " << setfill('X') << setw(13)
+ << card_number[12] << card_number[13] << card_number[14] << card_number[15] << endl;
+
+ return 0;
+} \ No newline at end of file
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