Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include<cmath>
  3. #include<fstream>
  4. #include<iomanip>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12.  
  13. class Array
  14.  
  15. {
  16.  
  17.    
  18. public:
  19.     int n;
  20.     int* mas;
  21.     Array();
  22.     Array(int* mass);
  23.     Array(Array& M);
  24.     void print();
  25.     void clear();
  26.     void razm();
  27.     void get();
  28.     friend istream& operator>>(istream& s, Array& a);
  29.     friend ostream& operator<<(ostream& s, const Array& a);
  30.  
  31. };
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. istream& operator>>(istream& s, Array& a)
  40. {
  41.     cout << "enter point\n";
  42.     s >> a.x >> a.y;
  43.     return s;
  44. }
  45.  
  46.  
  47. Array::Array() {
  48.     n = 5;
  49. }
  50.  
  51. Array::Array(int* mass) {
  52.     mass = mas;
  53. }
  54.  
  55. Array::Array(Array& M) {
  56.     mas = M.mas;
  57. }
  58.  
  59. void Array::get() {
  60.     cout << "enter length ";
  61.     cin >> n;
  62.     int* k = new int[n];
  63.     mas = k;
  64.     for (int i = 0; i < n; i++) {
  65.         cout << "enter num ";
  66.         cin >> mas[i];
  67.  
  68.     }
  69. }
  70. void Array::print() {
  71.     for (int i = 0; i < n; i++)
  72.     {
  73.         cout << mas[i] << " " << endl;
  74.     }
  75. }
  76.  
  77. void Array::razm()
  78. {
  79.     cout << "razmer: " << n << endl;
  80. }
  81. void Array::clear() {
  82.     delete[]mas;
  83.     cout << "Массив после очищения: ";
  84. }
  85.  
  86.  
  87. istream& operator>>(istream& s, Array& a)
  88. {
  89.  
  90.     for (int i = 0; i < a.n; i++)
  91.     {
  92.         s >> a.mas[i];
  93.  
  94.     }
  95.     return s;
  96. }
  97.  
  98. ostream& operator<<(ostream& s, const Array& a)
  99. {
  100.     for (int i = 0; i < 5; i++) {
  101.         s << a.mas[i] << " ";
  102.         s << endl;
  103.     }
  104.  
  105.     return s;
  106. }
  107.  
  108.  
  109. int main() {
  110.     Array a;
  111.     Array b(a);
  112.     int* arr;
  113.     Array c(arr);
  114.  
  115.     c.get();
  116.     c.print();
  117.     c.razm();
  118.     c.clear();
  119.     c.print();
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement