avr39ripe

PV024RefBasics

Dec 3rd, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void swapPtr(int* a, int* b)
  4. {
  5.     std::cout << "*a = " << *a << " *b= " << *b << '\n';
  6.     int tmp{ *a };
  7.     *a = *b;
  8.     *b = tmp;
  9.     std::cout << "*a = " << *a << " *b= " << *b << '\n';
  10. }
  11.  
  12. void swap(int& a, int& b)
  13. {
  14.     std::cout << "a = " << a << " b= " << b << '\n';
  15.     int tmp{ a };
  16.     a = b;
  17.     b = tmp;
  18.     std::cout << "a = " << a << " b= " << b << '\n';
  19. }
  20.  
  21. void calcArr(int* arr, int arrSize, int& zero, int& pos, int& neg)
  22. {
  23.     //for (int i{ 0 }; i < arrSize; ++i)
  24.     //{
  25.     //  if (arr[i] == 0) { ++(*zero); };
  26.     //  if (arr[i] > 0) { ++(*pos); };
  27.     //  if (arr[i] < 0) { ++(*neg); };
  28.     //}
  29.  
  30.     while (arrSize)
  31.     {
  32.         if (*arr == 0) { ++zero; };
  33.         if (*arr > 0) { ++pos; };
  34.         if (*arr < 0) { ++neg; };
  35.  
  36.         ++arr;
  37.         --arrSize;
  38.     }
  39. }
  40.  
  41. int main()
  42. {
  43.     int massSize{ 10 };
  44.     int* mass{ new int[massSize]{ 0,2,1,-3,0,2,-6,-1,0,5} };
  45.  
  46.     //int arr[10]{};
  47.  
  48.  
  49.     ////for (int i{ 0 }; i < massSize; ++i)
  50.     ////{
  51.     ////    arr[i] = mass[i];
  52.     ////    std::cout << arr[i] << ' ';
  53.     ////}
  54.  
  55.     //int* end{ mass + massSize };
  56.     //int* begin{ mass };
  57.     //int* dest{ arr };
  58.  
  59.     //while (begin < end)
  60.     //{
  61.     //  *dest++ = *begin++;
  62.     //  //*dest = *begin;
  63.     //  //++dest;
  64.     //  //++begin;
  65.  
  66.     //  std::cout << *(dest - 1) << ' ';
  67.     //}
  68.  
  69.     //delete[] mass;
  70.  
  71.     //return 0;
  72.  
  73.     int x{ 10 };//(100)[xxxx]
  74.     int y{ 20 };
  75.  
  76.     const int arrSize{ 10 };
  77.     const int* ptrI{ &arrSize };
  78.     const int& refI{ x };
  79.    
  80.  
  81.  
  82.  
  83.     //int n;
  84.     //int* const ptrInt{&x};
  85.     //
  86.  
  87.  
  88.     //int& refInt{ x }; //(100)
  89.     //refInt = 345;
  90.  
  91.     std::cout << "x = " << x << '\n';
  92.     int zCnt{ 0 };
  93.     int pCnt{ 0 };
  94.     int nCnt{ 0 };
  95.  
  96.     calcArr(mass, massSize, zCnt, pCnt, nCnt);
  97.  
  98.     std::cout << "Zeros: " << zCnt
  99.         << "\nPositives: " << pCnt
  100.         << "\nNegatives:" << nCnt << '\n';
  101.  
  102.     std::cout << "x = " << x << " y= " << y << '\n';
  103.     swap(x, y);
  104.     //swapPtr(&x, &y);
  105.     std::cout << "x = " << x << " y= " << y << '\n';
  106.  
  107. //  delete[] mass;
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment