Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 05 / Interval
diff options
context:
space:
mode:
Commit8cf1283a4ffb9fe1901c29c087fa376de82726af (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Filesabdfe6bf526100dcce87a88563100e02adf7605e /Sem. 05/Interval
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar.gz
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.zip
Parentd73a7ec225516657dec74472a0491330e9999217 (diff)
clean up
3 files changed, 0 insertions, 180 deletions
-rw-r--r--Sem. 05/Interval/Interval.cpp133
-rw-r--r--Sem. 05/Interval/Interval.h32
-rw-r--r--Sem. 05/Interval/Source.cpp15
diff --git a/Sem. 05/Interval/Interval.cpp b/Sem. 05/Interval/Interval.cpp
deleted file mode 100644
index c3f11cf..0000000
--- a/Sem. 05/Interval/Interval.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-#include <iostream>
-#include <algorithm>
-#include "Interval.h"
-
-bool isPrime(int n)
-{
- double temp = sqrt(n);
- for (int i = 2; i <= temp; i++)
- {
- if (n % i == 0)
- return false;
- }
- return true;
-}
-
-bool isPalindorme(int n)
-{
- int reversed = 0;
-
- while (n != 0)
- {
- int lastDigit = n % 10;
- (reversed *= 10) += lastDigit;
- n /= 10;
- }
- return n == reversed;
-}
-bool containsOnlyDistinctNumbers(int n)
-{
- bool digits[10];
- for (int i = 0; i < 10; i++)
- digits[i] = false;
-
- while (n != 0)
- {
- int lastDigit = n % 10;
- if (digits[lastDigit])
- return false;
- digits[n % 10] = true;
- n /= 10;
- }
- return true;
-}
-
-size_t Interval::countNumbersInIntervalCondition(bool(*pred)(int)) const
-{
- size_t count = 0;
- for (int i = a; i <= b; i++)
- {
- if (pred(i))
- count++;
- }
- return count;
-}
-
-Interval::Interval() : Interval(0, 0) {}
-
-Interval::Interval(int a, int b)
-{
- if (a > b)
- a = b = 0;
-
- this->a = a;
- this->b = b;
-}
-
-int Interval::getA() const
-{
- return a;
-}
-
-int Interval::getB() const
-{
- return b;
-}
-void Interval::setA(int a)
-{
- if (a > b)
- return;
- this->a = a;
-}
-
-void Interval::setB(int b)
-{
- if (b < a)
- return;
- this->b = b;
-}
-
-size_t Interval::getLength() const
-{
- return b - a + 1;
-}
-
-bool Interval::isMemberOfInterval(int x) const
-{
- return (a <= x && x <= b);
-}
-
-size_t Interval::calcPrimeNumbersInTheInterval() const
-{
- return countNumbersInIntervalCondition(isPrime);
-}
-
-size_t Interval::calcPalindromicNumbersInTheInterval() const
-{
- return countNumbersInIntervalCondition(isPalindorme);
-}
-
-size_t Interval::calcDiffrentDigitNumbersInTheInverval() const
-{
- return countNumbersInIntervalCondition(containsOnlyDistinctNumbers);
-}
-
-bool Interval::areStartAndEndPowersOfTwo() const
-{
- return (a == 0 || (a & a - 1) == 0) && (b == 0 || (b & b - 1) == 0);
-}
-
-Interval Interval::intersect(const Interval& other) const
-{
- if (b < other.getA() || a > other.getB())
- return Interval(0, 0);
-
- int newA = std::max(a, other.getA());
- int newB = std::min(b, other.getB());
-
- return Interval(newA, newB);
-}
-bool Interval::isSuperInterval(const Interval& other) const
-{
- return a <= other.getA() && b >= other.getB();
-} \ No newline at end of file
diff --git a/Sem. 05/Interval/Interval.h b/Sem. 05/Interval/Interval.h
deleted file mode 100644
index c8fcbc7..0000000
--- a/Sem. 05/Interval/Interval.h
+++ /dev/null
@@ -1,32 +0,0 @@
-
-class Interval
-{
- int a;
- int b;
-
- size_t countNumbersInIntervalCondition(bool(*pred)(int)) const;
-
-public:
-
- Interval();
- Interval(int a, int b);
-
- int getA() const;
- int getB() const;
-
- void setA(int a);
- void setB(int b);
-
- size_t getLength() const;
- bool isMemberOfInterval(int x) const;
-
- size_t calcPrimeNumbersInTheInterval() const;
- size_t calcPalindromicNumbersInTheInterval() const;
- size_t calcDiffrentDigitNumbersInTheInverval() const;
-
- bool areStartAndEndPowersOfTwo() const;
-
- Interval intersect(const Interval& other) const;
-
- bool isSuperInterval(const Interval& other) const;
-};
diff --git a/Sem. 05/Interval/Source.cpp b/Sem. 05/Interval/Source.cpp
deleted file mode 100644
index 7e6b3e1..0000000
--- a/Sem. 05/Interval/Source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <iostream>
-#include "Interval.h"
-
-using namespace std;
-
-
-int main()
-{
- Interval i(1, 11);
-
- cout << i.calcDiffrentDigitNumbersInTheInverval() << endl;
-
- cout << i.getLength() << endl;
-
-} \ No newline at end of file