Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. //#include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Zbior
  6. {
  7. public:
  8. Zbior(): r(0), tab(NULL)
  9. {}
  10. bool czy_jest(int v);
  11. int rozmiar() const
  12. {
  13. return r;
  14. }
  15. Zbior & operator << (int element);
  16. int operator[](int n)
  17. {
  18. return tab[n];
  19. }
  20. private:
  21. int * tab;
  22. int r;
  23. };
  24.  
  25. bool Zbior::czy_jest(int v)
  26. {
  27. for (int i = 0; i < r; i++)
  28. {
  29. if (tab[i] == v)
  30. {
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36.  
  37. Zbior & Zbior::operator << (int element)
  38. {
  39. int i, * nowa = new int[r+1];
  40. for (i = 0; i < r; i++)
  41. {
  42. nowa[i] = tab[i];
  43. }
  44. nowa[i] = element;
  45. r++;
  46. delete [] tab;
  47. tab = nowa;
  48. return (*this);
  49. }
  50.  
  51. int main()
  52. {
  53. Zbior a;
  54. a << 15;
  55. a << 30;
  56. a << 45;
  57.  
  58. cout << "\nZbior a:\n";
  59.  
  60. for (int i = 0; i < a.rozmiar(); i++)
  61. {
  62. cout << a[i] << " ";
  63. }
  64.  
  65. bool wynik = a.czy_jest(10);
  66. bool wynik2 = a.czy_jest(30);
  67.  
  68. cout << "\n\nCzy istnieje 10 - " << wynik << endl;
  69. cout << "Czy istnieje 30 - " << wynik2 << endl;
  70.  
  71. /* cout << "\n\nCzy istnieje 10 - ";
  72. if (a.czy_jest(10) == true)
  73. {
  74. cout << "jest\n";
  75. }
  76. else
  77. {
  78. cout << "nie ma\n";
  79. }
  80.  
  81. cout << "Czy istnieje 30 - ";
  82. if (a.czy_jest(30) == true)
  83. {
  84. cout << "jest\n";
  85. }
  86. else
  87. {
  88. cout << "nie ma\n";
  89. }
  90. */
  91. //cin.get();
  92. system("PAUSE");
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement