Advertisement
spacerose

4_3_1

Apr 25th, 2020
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <iomanip>
  5. using namespace std;
  6. class Base
  7. {
  8. public:
  9.     int N;
  10.     int* arr;
  11. };
  12. class Cl1 : public Base
  13. {
  14. public:
  15.     void size(int n)
  16.     {
  17.         this->N=n;
  18.         arr = new int[n];
  19.     }  
  20. };
  21. class Cl2 : public Base
  22. {
  23. public:
  24.     void sort(int* arr, int n)
  25.     {
  26.         for (int i = 0; i < n - 1; i++) {
  27.             for (int j = 0; j < n - i - 1; j++) {
  28.                 if (arr[j] > arr[j + 1]) swap(arr[j], arr[j + 1]);
  29.             }
  30.         }
  31.     }
  32.     void out(int*arr,int n)
  33.     {
  34.         for (int i = 0; i < n; i++)
  35.             cout << setw(5)<<arr[i];
  36.     }
  37. };
  38. class Cl3 : public Cl1, public Cl2
  39. {
  40. public:
  41.     void input(int*arr,int n)
  42.     {
  43.        
  44.         for (int i = 0; i < n; i++)
  45.             cin >> arr[i];
  46.     }
  47.     void func(int*arr,int n)
  48.     {
  49.         input(arr,n);
  50.         cout << "Array dimension: "<<n<<endl;
  51.         cout << "The original array:";
  52.         out(arr,n);
  53.         sort(arr,n);
  54.         cout << "\nAn ordered array:";
  55.         out(arr,n);
  56.     }
  57. };
  58. int main()
  59. {
  60.     Cl3 b;
  61.     int N;
  62.     cin >> N;
  63.     b.size(N);
  64.  
  65.     int* mass=new int[N];
  66.    
  67.     b.func(mass,N);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement