Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Arek on 2019-12-15.
- //
- #ifndef INC_09_DANE_H
- #define INC_09_DANE_H
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- template <class T>
- class Dane {
- private:
- public:
- T* t;
- int N;
- Dane(const int n,const T MAX);
- Dane(const Dane<T>& d);
- ~Dane();
- friend ostream& operator<< (ostream& os,const Dane<T>& d)
- {
- os << "[";
- for(int i = 0;i<d.N;++i)
- {
- os << " " << d[i];
- }
- os << " ]";
- return os;
- }
- T& operator[] (const int index) const
- {
- return t[index];
- }
- T& operator() (const int index) const
- {
- return t[index];
- }
- };
- template <class T>
- class Suma{
- public:
- Suma() {}
- T operator()(const Dane<T>& a) const
- {
- T suma = 0;
- for(int i = 0; i < a.N ; i++)
- {
- suma+=a.t[i];
- }
- return suma;
- }
- };
- template <class T>
- Dane<T>::Dane(int n, T MAX)
- {
- t = new T[n];
- N = n;
- for (int i = 0; i < n; ++i)
- {
- t[i] = ((double)rand()/RAND_MAX)*MAX;
- }
- }
- template <class T>
- Dane<T>::Dane(const Dane<T>& d)
- {
- this->N = d.N;
- copy(d.t,d.t+d.N,t);
- }
- template <class T>
- Dane<T>::~Dane()
- {
- delete[] t;
- }
- template <class T>
- T oblicz(const Dane<T>& a,const Suma<T>& f)
- {
- return f(a);
- }
- #endif //INC_09_DANE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement