Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

#include<iostream>

#include <conio.h>
#include<stdio.h>
#include<string.h>

using namespace std;

class cursaAeriana
{
private:
const int codZbor;
char* destinatie;
int durataZbor;
static int nrZbor;

public:

//get si set
char* get_destinatie()
{
return this->destinatie;
}

void set_destinatie(char* destinatie)

{
if (strlen(destinatie))
{
delete[] this->destinatie;
this->destinatie = new char[strlen(destinatie) + 1];
strcpy(this->model, destinatie);
}
}

//constructor fara parametri


cursaAeriana ():codZbor (0)
{
cout << endl << "Constructor fara parametri";

this->destinatie=new char[strlen(destinatie)+1];
strcpy(strlen(destinatie)+1,"destinatie");
this->durataZbor = 0;
nrZbor++

}
//constructor cu parametri

cursaAeriana (int codZbor,char* destinatie,int durataZbor):codZbor(c)


{
cout << endl << "Constructor cu parametri";

this->destinatie=new char[strlen(destinatie)+1];
strcpy(strlen(destinatie)+1,destinatie);
this->durataZbor = durataZbor;
nrZbor++;

//constructor de copiere

cursaAeriana (cursaAeriana & temp):codZbor(temp.codZbor)


{
cout << endl << "Constructor de copiere";
this->codZbor = temp.codZbor;
this->destinatie=new char[strlen(destinatie)+1];
strcpy(strlen(destinatie)+1,temp.destinatie);
this->durataZbor = temp.durataZbor;
nrZbor++;
}

//destructor

~cursaAeriana()
{

if (this->destinatie)
delete[] this->destinatie;
nrZbor--;
}

// operator <<
friend ostream&operator<<(ostream&iesire, cursaAeriana ca) //
{
iesire << ca.destinatie << endl;
iesire << ca.durataZbor << endl;

return iesire;
}

friend istream&operator>>(istream&intrare, cursaAeriana &ca)


{
cout << "destinatie: ";
delete[]ca.destinatie;
intrare >> ca.destinatie;
cout << "Durata zbor : ";
intrare >> ca.durataZbor;
return intrare;
}
//supraincarcarea operatorului =
cursaAeriana& operator = (const cursaAeriana& temp) {

{
delete[] this->destinatie;

this->destinatie = new char[strlen(temp.destinatie) + 1];


strcpy(this->destinatie, temp.destinatie);
this->durataZbor = temp.durataZbor;
return *this;

//operator <

bool operator < (const cursaAeriana& temp)


{
return (destinatie < temp.destinatie);

//operator ++ fara parametri (implicit are setat this)


cursaAeriana operator++()
{
this->durata++;
return *this;
}

//oper++ cu param postincrementare


cursaAeriana operator++(int ca)
{
cursaAeriana temp=*this;
this->durata++;
return temp;
}
};

You might also like