Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. //
  2. // Created by Arek on 2019-12-15.
  3. //
  4.  
  5. #ifndef INC_09_DANE_H
  6. #define INC_09_DANE_H
  7.  
  8. #include <iostream>
  9. #include <stdlib.h>
  10.  
  11. using namespace std;
  12.  
  13. template <class T>
  14. class Dane {
  15. private:
  16.  
  17. public:
  18. T* t;
  19. int N;
  20.  
  21. Dane(const int n,const T MAX);
  22. Dane(const Dane<T>& d);
  23. ~Dane();
  24.  
  25. friend ostream& operator<< (ostream& os,const Dane<T>& d)
  26. {
  27. os << "[";
  28. for(int i = 0;i<d.N;++i)
  29. {
  30. os << " " << d[i];
  31. }
  32. os << " ]";
  33. return os;
  34. }
  35. T& operator[] (const int index) const
  36. {
  37. return t[index];
  38. }
  39. T& operator() (const int index) const
  40. {
  41. return t[index];
  42. }
  43.  
  44. };
  45.  
  46. template <class T>
  47. class Suma{
  48. public:
  49. Suma() {}
  50. T operator()(const Dane<T>& a) const
  51. {
  52. T suma = 0;
  53. for(int i = 0; i < a.N ; i++)
  54. {
  55. suma+=a.t[i];
  56. }
  57. return suma;
  58. }
  59. };
  60.  
  61. template <class T>
  62. Dane<T>::Dane(int n, T MAX)
  63. {
  64. t = new T[n];
  65. N = n;
  66. for (int i = 0; i < n; ++i)
  67. {
  68. t[i] = ((double)rand()/RAND_MAX)*MAX;
  69. }
  70. }
  71. template <class T>
  72. Dane<T>::Dane(const Dane<T>& d)
  73. {
  74. this->N = d.N;
  75. copy(d.t,d.t+d.N,t);
  76. }
  77.  
  78. template <class T>
  79. Dane<T>::~Dane()
  80. {
  81. delete[] t;
  82. }
  83.  
  84. template <class T>
  85. T oblicz(const Dane<T>& a,const Suma<T>& f)
  86. {
  87. return f(a);
  88. }
  89.  
  90.  
  91.  
  92. #endif //INC_09_DANE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement