You are on page 1of 5

#include<iostream>

#include<string>
#include<vector>
#include<fstream>
#include<map>
using namespace std;
class Termo
{
char*eticheta;
float tempCitita;
float tempDorita;
public:
virtual float tempMedieCitita()
{
return(this->tempCitita + this->tempDorita) / 2;
}
char*get_eticheta()
{
return eticheta;
}
float get_tempCitita()
{
return tempCitita;
}
float get_tempDorita()
{
return tempDorita;
}
void set_tempCitita(float tempCitita)
{
if (this->tempCitita > 0)
this->tempCitita = tempCitita;
}
void set_tempDorita(float tempDorita)
{
if (this->tempDorita > 0)
this->tempDorita = tempDorita;
}
void set_eticheta(char*eticheta)
{
if (this->eticheta != NULL)
delete[]this->eticheta;
this->eticheta = new char[strlen(eticheta) + 1];
strcpy(this->eticheta, eticheta);
}
Termo()
{
this->eticheta = new char[strlen("Eti") + 1];
strcpy(this->eticheta, "Eti");
this->tempCitita = 10;
this->tempDorita = 16;
}
Termo(char*eticheta, float tempCitita, float tempDorita)
{
this->tempCitita = tempCitita;
this->tempDorita = tempDorita;
this->eticheta = new char[strlen(eticheta) + 1];
strcpy(this->eticheta, eticheta);
}

Termo(const Termo&a)
{
this->tempCitita = a.tempCitita;
this->tempDorita = a.tempDorita;
this->eticheta = new char[strlen(a.eticheta) + 1];
strcpy(this->eticheta, a.eticheta);
}
~Termo()
{
delete[]this->eticheta;
}
Termo& operator=(const Termo& temp)
{
this->tempCitita = temp.tempCitita;
this->tempDorita = temp.tempDorita;
delete[]this->eticheta;
this->eticheta = new char[strlen(temp.eticheta) + 1];
strcpy(this->eticheta, temp.eticheta);
return *this;
}
friend ostream& operator<<(ostream&out, Termo b)
{
out << "Eticheta" << b.eticheta << endl;
out << "Temperatura citita" << b.tempCitita << endl;
out << "Temperatura dorita" << b.tempDorita << endl;
return out;
}
friend istream&operator>>(istream&in, Termo& c)
{
cout << "TempC:" << endl;
in >> c.tempCitita;
cout << "TempD:" << endl;
in >> c.tempDorita;
cout << "Etcheta estE:" << endl;
char aux[30];
in >> aux;
delete[]c.eticheta;
c.eticheta = new char[strlen(aux) + 1];
strcpy(c.eticheta, aux);
return in;
}
Termo operator--()
{
this->tempDorita--;
return *this;
}
friend ifstream& operator>>(ifstream&in, Termo& a)
{
in.ignore();
char buffer[50];
in.getline(buffer, 50);
a.set_eticheta(buffer);
in >> a.tempCitita;
in >> a.tempDorita;
return in;
}
};
class biTermo :public Termo
{
private:float tempPardosealaCitita;

public: float tempMedieCitita()


{
return(this->get_tempCitita() + this->tempPardosealaCitita) / 2;
}
biTermo() :Termo()
{
tempPardosealaCitita = 20;
}
biTermo(char* eticheta, float tempCitita, float tempDorita, floa
t tempMedieCitita) :Termo(eticheta, tempCitita, tempDorita)
{
this -> tempPardosealaCitita = tempPardosealaCitita;
}
biTermo(const biTermo&a) :Termo(a)
{
this->tempPardosealaCitita = a.tempPardosealaCitita;
}
biTermo operator=(const biTermo& b)
{
Termo::operator=(b);
this->tempPardosealaCitita = b.tempPardosealaCitita;
return *this;
}
};
class UCC
{
private:
string locatie;
int nrTermoGestionate;
Termo* container;
public:
UCC()
{
locatie = "";
nrTermoGestionate = 0;
container = NULL;
}
UCC(string loc, int nr, Termo* container)
{
this->locatie = loc;
this->nrTermoGestionate = nr;
this->container = new Termo[nr];
for (int i = 0; i < nr; i++)
this->container[i] = container[i];
}
UCC(const UCC&a)
{
this->locatie = a.locatie;
this->nrTermoGestionate = a.nrTermoGestionate;
this->container = new Termo[nrTermoGestionate];
for (int i = 0; i < nrTermoGestionate; i++)
this->container[i] = a.container[i];
}
UCC operator=(const UCC& a)
{
this->locatie = a.locatie;
this->nrTermoGestionate = a.nrTermoGestionate;
delete[]this->container;

this->container = new Termo[a.nrTermoGestionate];


for (int i = 0; i < a.nrTermoGestionate; i++)
this->container[i] = a.container[i];
return *this;
}
friend ostream&operator<<(ostream&out, UCC a)
{
out << "Locatie:" << a.locatie << endl;
out << "Numar termo:" << a.nrTermoGestionate << endl;
out << "Containerul contine:" << endl;
for (int i = 0; i < a.nrTermoGestionate; i++)
out << a.container[i] << endl;
return out;
}
UCC operator+=(int a)
{
Termo b("asd", 12.2, 13.2);
Termo* op = new Termo[this->nrTermoGestionate];
for (int i = 0; i < nrTermoGestionate; i++)
op[i] = this->container[i];
delete[]this->container;
this->nrTermoGestionate += a;
this->container = new Termo[this->nrTermoGestionate];
for (int j = this->nrTermoGestionate - a; j < this->nrTermoGesti
onate; j++)
{
this->container[j] = b;
}
delete[]op;
return *this;
}
friend ofstream& operator<<(ofstream&out, UCC a)
{
out << a.locatie << endl;
out << a.nrTermoGestionate << endl;
for (int i = 0; i < a.nrTermoGestionate; i++)
out << a.container[i] << endl;
return out;
}
friend ifstream& operator>>(ifstream&in, UCC& a)
{
char buffer[50];
in.getline(buffer, 50);
a.locatie = buffer;
in >> a.nrTermoGestionate;
a.container = new Termo[a.nrTermoGestionate];
for (int i = 0; i < a.nrTermoGestionate;i ++)
{
in >> a.container[i];
}
return in;
}
};
void main()
{
Termo t1("dormitor 1", 22.5, 23.5);
Termo t2 = t1;
Termo t3; t3 = t1;
t3.set_eticheta("bucatarie");

Termo t4; t4 = t3;


Termo tx1[] = { t1, t2, t3, t4 };
Termo tx2[] = { t1, t2, t3 };
UCC u1("etaj1", 4, tx1);
UCC u2("etaj2", 3, tx2);
cout << "A2a parte" << endl << endl;
UCC u3(u2);
UCC u4;
u4 = u1;
cout << t3 << endl;
cout << u2 << endl;
cout << "A3a parte" << endl << endl;
--t1;
u2 += -2;
cout << t1;
cout << u2;
cout << "A4a parte" << endl << endl;
UCC U3;
cin >> t4;
cout << t4;
cout << "A5a parte" << endl << endl;
ofstream g("aha.txt");
g << u1;
g.close();
UCC u5;
ifstream f("fisierIN.txt");
f >> u5;
f.close();
cout << u5 << endl;
cout << "A6a parte" << endl << endl;
termo* pt = &t1;
cout << pt->tempMedieCitita() << endl;
biTermo t5(14.2, "baie", 12.2, 34.3);
biTermo t6 = t3;
pt = &t6;
cout << pt->tempMedieCitita() << endl;
cout << "A7a parte" << endl << endl;
map<string, biTermo>btMap;
pair<string, biTermo>element;
btMap.insert(pair<string, biTermo>(t4.get_eticheta(), t4));
map<string, biTermo>::iterator it;
for (it = btMap.begin(); it != btMap.end(); it++)
cout << (*it).first << "" << (*it).second;
}

You might also like