Professional Documents
Culture Documents
#include<string>
using namespace std;
//clasa template
template<class T>
class Colectie
{
//vector alocat dinamic int/float/Student/...
private:
T* v; //T v[100] alocare statica. asta nu se seteaza pe null
//int* v; //alocare dinamica
int nr;//dimensiune vector
public:
//constructor fara parametrii, cu param, de copiere, destructor,
ostream(op<<)
Colectie()
{
this->v = NULL;
this->nr = 0;
}
Colectie(const Colectie&c)
{
this->nr = c.nr;
this->v = new T[this->nr];
for (int i = 0; i < this->nr; i++)
this->v[i] = c.v[i];
}
~Colectie()
{
delete[]this->v;
}
int sort_ASC()
{
T aux;
for(int i=0;i<this->nr;i++)
for(int j=i+1;j<this->nr;j++)
if (v[i] > v[j])
{
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
};
class Erou {
private:
int varsta;
int health;
public:
Erou()
{
this->varsta = 0;
this->health = 0;
}
Erou(int n, int h)
{
this->varsta = n;
this->health = h;
}
Erou(const Erou&e)
{
this->varsta = e.varsta;
this->health = e.health;
}
Erou&operator=(const Erou&e)
{
this->varsta = e.varsta;
this->health = e.health;
return*this;
}
Erou&operator+=(const Erou&e)
{
this->varsta += e.varsta;
this->health += e.health;
return*this;
}
};
void main() {
//colectii ce stocheaza vectori de tip generic
//declara o colectie de int
//Colectie<int> colectieInt;
//cout << colectieInt;
//colectie de float
//Colectie<float> colectieFloat;
//to do
//alegere o clasa cu 2 atribute
//implementati tot ce este nevoie
//astfel incat sa avem o colectie de ...
//de 10:
//Student s;
//colectieStudenti += s;
Erou e1;
//int vector2[] = { 10,20,40 };
//Colectie<Erou>colectieErou(vector2, 3);
//cout << colectieErou;
Colectie<Erou> colectieErou;
cout << colectieErou;
colectieErou += e1;
}