From e55e9fb058a046f6f1e08da521660a8d98b1d5db Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Tue, 2 Nov 2021 16:23:53 +0200 Subject: Added Solutions --- pract_SI/Pract. 04/Solutions/task1.cpp | 34 +++++++++++++++++++++++ pract_SI/Pract. 04/Solutions/task2 - example1.cpp | 23 +++++++++++++++ pract_SI/Pract. 04/Solutions/task2 - example2.cpp | 25 +++++++++++++++++ pract_SI/Pract. 04/Solutions/task3.cpp | 8 ++++++ pract_SI/Pract. 04/Solutions/task4.cpp | 4 +++ pract_SI/Pract. 04/Solutions/task5.cpp | 20 +++++++++++++ pract_SI/Pract. 04/function overload.cpp | 16 +++++++++++ 7 files changed, 130 insertions(+) create mode 100644 pract_SI/Pract. 04/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task2 - example1.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task2 - example2.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task3.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 04/function overload.cpp diff --git a/pract_SI/Pract. 04/Solutions/task1.cpp b/pract_SI/Pract. 04/Solutions/task1.cpp new file mode 100644 index 0000000..3e8c1a3 --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task1.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int sum(const int a, const int b) +{ + /* + //First way + int sum = a + b; + return sum; + */ + + //Second way + return a + b; +} + +int main() +{ + int num1, num2; + cin >> num1 >> num2; + + //First way + cout << sum(num1, num2) << endl; //return as output on Console + + /* + //Second way + //int sumOfNumbers = sum(num1, num2); //create an int with value num1+num2; + //cout << sumOfNumbers << endl; + */ + + return 0; +} + + diff --git a/pract_SI/Pract. 04/Solutions/task2 - example1.cpp b/pract_SI/Pract. 04/Solutions/task2 - example1.cpp new file mode 100644 index 0000000..309e68d --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task2 - example1.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +bool isZero(const int number) +{ + return (number == 0); +} + +bool isEven(const int number) +{ + if (isZero(number)) + { + return false; + } + return !(number % 2); +} + +int main() +{ + int n; + cin >> n; + cout << boolalpha << isEven(n) << endl; + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task2 - example2.cpp b/pract_SI/Pract. 04/Solutions/task2 - example2.cpp new file mode 100644 index 0000000..0440873 --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task2 - example2.cpp @@ -0,0 +1,25 @@ +#include + +bool isEven(const int num) { + return !(num % 2); +} + +bool isZero(const int num) { + return num == 0; +} + +int main() { + int num; + std::cin >> num; + if (isZero(num)) { + std::cout << "The number is not ever or odd!"; + } + else { + if (isEven(num)) { + std::cout << "Even"; + return 0; + } + std::cout << "Odd"; + } + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task3.cpp b/pract_SI/Pract. 04/Solutions/task3.cpp new file mode 100644 index 0000000..bc85d3a --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task3.cpp @@ -0,0 +1,8 @@ +bool isPositive(const int num) +{ + if (num <= 0) + { + return false; + } + return true; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task4.cpp b/pract_SI/Pract. 04/Solutions/task4.cpp new file mode 100644 index 0000000..771550b --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task4.cpp @@ -0,0 +1,4 @@ +int abs(int num1, int num2) +{ + return ((num1 - num2) >= 0 ? (num1 - num2) : (num2 - num1)); +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task5.cpp b/pract_SI/Pract. 04/Solutions/task5.cpp new file mode 100644 index 0000000..fc5552e --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task5.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +void print(const int N, const char S = ' ') + { + for (size_t i = 0; i < N; i++) + { + cout << S; + } + } + +int main() +{ + int N; + char S; + cin >> N >> S; + print(N); + cout<< "Error!" << endl; + print(N, S); + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/function overload.cpp b/pract_SI/Pract. 04/function overload.cpp new file mode 100644 index 0000000..7e0bdfa --- /dev/null +++ b/pract_SI/Pract. 04/function overload.cpp @@ -0,0 +1,16 @@ +void print() //print - arguments: 0 +{ + cout << "Hello World!\n"; +} + +void print(int number) //print - arguments: 1 + //int +{ + cout << "Hello World N" << number << endl; +} + +void print(double number) //print - arguments: 1 + //double +{ + cout << "Hello World N" << number << endl; +} -- cgit v1.3.1-23-gd82d