Last active
November 19, 2025 15:50
-
-
Save XoLinA/f801cb84dbed170c1b7d5f12fc118fa6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| class IOutput | |
| { | |
| virtual void Show(string info) = 0; | |
| virtual void Show() = 0; | |
| }; | |
| class IMath | |
| { | |
| virtual int Max() = 0; | |
| virtual int Min() = 0; | |
| virtual float Avg() = 0; | |
| virtual bool Search(int value) = 0; | |
| }; | |
| class ISort | |
| { | |
| virtual void SortAsc() = 0; | |
| virtual void SortDesc() = 0; | |
| virtual void SortByParam(bool isAsc) = 0; | |
| }; | |
| class Array : public IOutput, public IMath, public ISort | |
| { | |
| protected: | |
| int* ptr; | |
| int size; | |
| public: | |
| Array(int sizeT) | |
| { | |
| size = sizeT; | |
| ptr = new int[size]; | |
| for (int i = 0; i < size; i++) | |
| { | |
| ptr[i] = rand() % 100 + 1; | |
| } | |
| } | |
| ~Array() | |
| { | |
| delete[] ptr; | |
| } | |
| void Show() override | |
| { | |
| cout << "Array elements: ------------------------------------\n"; | |
| for (int i = 0; i < size; i++) | |
| { | |
| cout << ptr[i] << " "; | |
| } | |
| cout << endl; | |
| } | |
| void Show(string info) override | |
| { | |
| cout << info << endl; | |
| Show(); | |
| } | |
| int Max() override | |
| { | |
| int temp = ptr[0]; | |
| for (int i = 1; i < size; i++) | |
| { | |
| if (temp < ptr[i]) | |
| { | |
| temp = ptr[i]; | |
| } | |
| } | |
| return temp; | |
| } | |
| int Min() override | |
| { | |
| int temp = ptr[0]; | |
| for (int i = 1; i < size; i++) | |
| { | |
| if (temp > ptr[i]) | |
| { | |
| temp = ptr[i]; | |
| } | |
| } | |
| return temp; | |
| } | |
| float Avg() override | |
| { | |
| int temp =0; | |
| for (int i = 0; i < size; i++) | |
| { | |
| temp += ptr[i]; | |
| } | |
| return temp/size; | |
| } | |
| bool Search(int value) override | |
| { | |
| bool temp = 0; | |
| for (int i = 0; i < size; i++) | |
| { | |
| if (value == ptr[i]) | |
| { | |
| temp = 1; | |
| } | |
| } | |
| return temp; | |
| } | |
| void SortAsc() | |
| { | |
| for (int i = 0; i < size - 1; i++) | |
| { | |
| for (int j = 0; j < size - 1 - i; j++) | |
| { | |
| if (ptr[j] > ptr[j + 1]) | |
| { | |
| int temp = ptr[j]; | |
| ptr[j] = ptr[j + 1]; | |
| ptr[j + 1] = temp; | |
| } | |
| } | |
| } | |
| } | |
| void SortDesc() | |
| { | |
| for (int i = 0; i < size - 1; i++) | |
| { | |
| for (int j = 0; j < size - 1 - i; j++) | |
| { | |
| if (ptr[j] < ptr[j + 1]) | |
| { | |
| int temp = ptr[j]; | |
| ptr[j] = ptr[j + 1]; | |
| ptr[j + 1] = temp; | |
| } | |
| } | |
| } | |
| } | |
| void SortByParam(bool isAsc) | |
| { | |
| if (isAsc == 0) | |
| { | |
| for (int i = 0; i < size - 1; i++) | |
| { | |
| for (int j = 0; j < size - 1 - i; j++) | |
| { | |
| if (ptr[j] < ptr[j + 1]) | |
| { | |
| int temp = ptr[j]; | |
| ptr[j] = ptr[j + 1]; | |
| ptr[j + 1] = temp; | |
| } | |
| } | |
| } | |
| } | |
| else | |
| { | |
| for (int i = 0; i < size - 1; i++) | |
| { | |
| for (int j = 0; j < size - 1 - i; j++) | |
| { | |
| if (ptr[j] > ptr[j + 1]) | |
| { | |
| int temp = ptr[j]; | |
| ptr[j] = ptr[j + 1]; | |
| ptr[j + 1] = temp; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| int main() | |
| { | |
| Array d(10); | |
| d.Show(); | |
| d.Show("vivod array"); | |
| cout << endl; | |
| cout << "Max= " << d.Max() << endl << "Min= " << d.Min() << endl << "Avg= " << d.Avg() << endl << "Search 11 (0/1)= " << d.Search(11); | |
| cout << endl << "SortAsc: "; | |
| d.SortAsc(); | |
| d.Show(); | |
| cout << endl << "SortDesc: "; | |
| d.SortDesc(); | |
| d.Show(); | |
| cout << endl << "SortByParam(1): "; | |
| d.SortByParam(1); | |
| d.Show(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment