1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
class TSeries{
public:
TSeries()
{
_size = 0;
_capacity = 0;
_tab = NULL;
}
TSeries(float *tab, const int size)
{
_tab = new float[size];
for(int i =0;i<size;i++) _tab[i] = tab[i];
_size = size;
}
~TSeries(){delete [] _tab;}
TSeries & operator+=(float value){return insert(value);}
TSeries & operator,(float value){return insert(value);}
TSeries & operator+(const TSeries & s)
{
// if(this->_size != s._size) std::cout<<"Size doesn't match!"<<std::endl;
/*else
{
std::cout<<"whee";
for(int i; i<this->_size;i++)
{
//this->_tab[i] += s._tab[i];
std::cout<<"nothing";
}
return *this;
}*/
//std::cout<<"sth";
}
TSeries & operator()(int position1, int position2)
{
// return *this;
}
TSeries & insert(float k)
{
if(_size >= _capacity) Enlarge();
_tab[_size++] = k;
return *this;
}
friend std::ostream & operator<<(std::ostream & out, const TSeries & s);
private:
int _size, _capacity;
float *_tab, *_itr;
static int _nr;
void Enlarge()
{
_capacity = 2 * _capacity + 1;
float *tmp = new float[_capacity];
for( int i=0;i<_size;++i)
{
tmp[i] = _tab[i];
}
delete [] _tab;
_tab = tmp;
}
};
std::ostream & operator<<(std::ostream & out, const TSeries & s)
{
int przedostatni = s._size - 1;
out<<"(";
for(int i =0;i<s._size;i++)
{
out<<(int)s._tab[i];
if(i != przedostatni)
out<<",";
}
out<<")"<<std::endl;
}
using namespace std;
int main(int argc, char **argv) {
TSeries series1;
series1 += 1.,2.,4.,2.;
cout<<"Series1: "<<series1<<endl;
const int size=7;
float tab[size] = {3.,3.,3.,4.,5.,1.,0.};
const TSeries series2(tab,size);
cout<<"Series2: "<<series2<<endl<<endl;
TSeries series3 = series1+series2;
cout<<"Series3: "<<series3<<endl<<endl;
series1+=1.,0.,3.;
series3=series1+series2;
cout<<" "<<series1<<endl;
cout<<" +"<<series2<<endl;
cout<<" ---------------------"<<endl;
cout<<"Series3: "<<series3<<endl<<endl;
TSeries series4=series1(2,4);
cout<<"Series4: "<<series3<<endl;
return 0;
}
|