Sunteți pe pagina 1din 5

#include<iostream>

#include<string>
#include<fstream>
using namespace std;

class AgentieAeriana{
protected:
int id;
string nume;
float nr_pasageri;
int nr_zboruri;
int* durata;
public:
void afisare();
AgentieAeriana() {
this->id = 0;
this->nume = "Anonim";
this->nr_pasageri = NULL;
this->nr_zboruri = 0;
this->durata = new int[nr_zboruri];
for (int i = 0; i < nr_zboruri;i++)
this->durata[i] = i + 1;
}
AgentieAeriana(int v_id, string v_nume, float v_nrp, int v_nrz, int*
v_durata) {
this->id = v_id;
if (v_nume.length() > 0) {
this->nume = v_nume;

}
else {
this->nume = "Anonim";
}
this->nr_pasageri = v_nrp;
this->nr_zboruri = v_nrz;
if (this->nr_zboruri > 0&& v_durata!=NULL) {
this->durata = new int[nr_zboruri];
for (int i = 0;i < nr_zboruri;i++)
this->durata[i] = v_durata[i];
}
}
AgentieAeriana(const AgentieAeriana& copie) {
this->id = copie.id;
this->nume = copie.nume;
this->nr_pasageri = copie.nr_pasageri;
this->nr_zboruri = copie.nr_zboruri;
if (nr_zboruri > 0) {
this->durata = new int[nr_zboruri];
for (int i = 0; i < this->nr_zboruri;i++) {
this->durata[i] = copie.durata[i];
}
}
}
~AgentieAeriana() {
if (this->durata != NULL && nr_zboruri > 0)
delete[]this->durata;
cout << "Se afiseaza destructorul" << endl;
}
AgentieAeriana &operator=(const AgentieAeriana &op) {
this->id = op.id;
this->nume = op.nume;
this->nr_pasageri = op.nr_pasageri;
this->nr_zboruri = op.nr_zboruri;
if (this->durata != NULL) {
delete[] this->durata;
}
this->durata = new int[nr_zboruri];
for (int i = 0;i < this->nr_zboruri;i++) {
this->durata[i] = op.durata[i];
}

return *this;
cout << "Se afiseaza operatorul egal" << endl;
}
void setNrPasageri(float v_nrp) {
this->nr_pasageri = v_nrp;
}
int getPasageri() {
return nr_pasageri;
}

void setNrZboruri(int v_nrz) {


this->nr_zboruri = v_nrz;
}
int getZboruri() {
return nr_zboruri;
}
int getSuma() {
int Suma = 0;
for (int i = 0;i < nr_zboruri;i++) {
Suma += this->durata[i];
}

return Suma;
}
int getProdus() {
int p = nr_zboruri;
for (int i = 0;i < nr_zboruri;i++)
p *= this->nr_zboruri;
return p;
}
int getmax() {
int max = this->durata[0];
for (int i = 0;i < nr_zboruri;i++) {
if (this->durata[i] > max)
max > this->durata[i];
}
return max;
}
AgentieAeriana& operator ++() {

this->nr_pasageri += this->nr_pasageri;

return *this;
}
friend ostream &operator<< (ostream& out, AgentieAeriana& os) {
out << "Se afiseaza ostream :D" << endl;
out <<"ID: "<< os.id << endl;
out <<"Nume"<<os.nume << endl;
out << "Numar pasa: " << os.nr_pasageri << endl;
out << "numar zboruri: " << os.nr_zboruri << endl;
if (os.durata != NULL) {
for (int i = 0;i < os.nr_zboruri;i++)
out << "durata" << i + 1 <<" : "<< os.durata[i] << endl;
}
return out;
}
friend istream &operator >> (istream &in, AgentieAeriana & da) {
cout << "Id: ";
in >> da.id;
cout <<"Nume: ";
in >> da.nume;
in.ignore();
cout << "Numar pasager: " ;
in >> da.nr_pasageri;
cout << endl << "NR zboruri: " ;
in >> da.nr_pasageri;
cout << "Durata: ";
if (da.durata != NULL) {
delete[] da.durata;
}
da.durata = new int[da.nr_zboruri];
for (int i = 0; i < da.nr_zboruri;i++) {
in >> da.durata[i];
}

return in;
}
friend ifstream & operator >> (ifstream & in, AgentieAeriana& das) {
cout << "Id: ";
in >> das.id;
cout << "Nume: ";
in >> das.nume;

cout << "Numar pasager: ";


in >> das.nr_pasageri;
cout << endl << "NR zboruri: ";
in >> das.nr_pasageri;
cout << "Durata: ";
if (das.durata != NULL) {
delete[] das.durata;
}
das.durata = new int[das.nr_zboruri];
for (int i = 0; i < das.nr_zboruri;i++) {
in >> das.durata[i];
}
in.ignore();
return in;
}

friend ofstream &operator<< (ofstream& out, AgentieAeriana& os) {


out << "Se afiseaza oFtream :D" << endl;
out << "ID: " << os.id << endl;
out << "Nume" << os.nume << endl;
out << "Numar pasa: " << os.nr_pasageri << endl;
out << "numar zboruri: " << os.nr_zboruri << endl;
if (os.durata != NULL) {
for (int i = 0;i < os.nr_zboruri;i++)
out << "durata" << i + 1 << " : " << os.durata[i] << endl;
}
return out;
}
};
class Angajat : public AgentieAeriana {
int varsta;
public:
Angajat() {
this->varsta = 0;
}
Angajat(int v_varsta, int v_id, string v_nume, float v_nrp, int v_nrz, int*
v_durata) :AgentieAeriana(v_id, v_nume, v_nrp,v_nrz, v_durata) {
this->varsta = v_varsta;
}
Angajat& operator=(const Angajat& eg) {
this->varsta = eg.varsta;
}
friend ostream& operator<<(ostream& out, Angajat &ou) {
out << "Se afiseaza Clasa Angajat " << endl;
out << "Se afiseaza varsta flacaului: " << ou.varsta << endl;

return out;

}
};
void AgentieAeriana::afisare() {

cout << "<--------------Se afiseaza Agentia Aeriana---------------->" <<


endl;
cout << "ID: " << this->id << endl;
cout << "Nume: " << this->nume << endl;
cout << "Numar Pasageri: " << this->nr_pasageri << endl;
cout << "Numar zboruri: " << this->nr_zboruri << endl;
cout << "Durata de zbor: " << this->durata << endl;
}
int main() {
AgentieAeriana aa;
//aa.afisare();
//int d[2] = { 1, 2 };
int nrz = 3;
int* durata = new int[nrz];
for (int i = 0; i < nrz; i++) {
durata[i] = i+ 11;
}
//int durata[4] = { 20,40,70,120 };
//int durata1[5] = { 10,23,95,43,11 };
AgentieAeriana aa1(11, "Henry Coanda", 12, 2, durata);
//aa1.afisare();
AgentieAeriana aa2 = aa1;
//aa2.afisare();
aa2 = aa1;

AgentieAeriana* aa3 = new AgentieAeriana(7, "My Computer", 12, 3, durata);


//aa3->afisare();
//char nume[20];
//strcpy(nume, "Otopeni");
string nume = "Otopeni";
AgentieAeriana aa4(11, nume, 324, 3,durata);
//aa4.afisare();
cout << endl << "Testam operatorul = " << endl;
aa4 = *aa3;
//aa4.afisare();
aa4.setNrPasageri(4);
aa4.setNrZboruri(2);
cout << "Se afiseaza numarul pasagerilor: " << aa4.getPasageri() << endl;
cout << "Se afisseaza numarul zborurilor: " << aa4.getZboruri() << endl;
cout << "Se afiseaza suma: " << aa4.getSuma() << endl;
cout << "Se afiseaza maxim: " << aa4.getmax() << endl;
cout << "Se afiseaza produs: " << aa4.getProdus() << endl;
cout << aa4;
AgentieAeriana aa5(11, nume, 22, 2,durata);
++aa5;
cout << "SUASDASDASDASD: " << aa5.getSuma() << endl;;
cout << aa5;
cin >> aa1;
Angajat ag1;
cout << ag1;
Angajat ag2(25, 1, "Sergiu", 21, 2, durata);
cout << ag2;
//

ifstream fisierIn2;
fisierIn2.open("agentie.txt", ifstream::in);
cout << "Citire fisier text( agentie) " << endl;
/*if (fisierIn2.is_open()) {
while (!fisierIn2.eof()) {
AgentieAeriana temp;
fisierIn2 >> temp;
cout << temp;
}

}*/
fisierIn2.close();

AgentieAeriana casa[3] = { aa1, aa2, aa };


ofstream fisierOut1;
fisierOut1.open("casa.txt", ofstream::out);
cout << "Afisare text (casa) " << endl;
for (int i = 0; i < 3; i++) {
fisierOut1 << casa[i];
}

fisierOut1.close();
}