You are on page 1of 3

#include<iostream>

#include<string>
using namespace std;

//meth virtuale + meth virtuale pure -- S12 -- recuperare


//clase template -- S13 10:30
//STL + test grila mare
//ex.

class ExceptieSumaNegativa :public exception {


public:
ExceptieSumaNegativa(string mesaj) :exception(mesaj.data())
{

}
};

class ExceptieSoldIndisponibil :public exception {


public:
ExceptieSoldIndisponibil(string mesaj) :exception(mesaj.data()) {

}
};

//clasa tip interfata ce contine metode virtuale pure


class ITranzactionabil {
public:
virtual void depunere(float suma) = 0;
virtual void retragere(float suma) = 0;
};

//cont bancar cu o interfata e relatie can do


class ContBancar :public ITranzactionabil {
private:
float sold;
string valuta;
public:
ContBancar() {
this->sold = 0;
}
ContBancar(float sold, string valuta) {
this->sold = sold;
this->valuta = valuta;
}
ContBancar(const ContBancar& c) {
this->sold = c.sold;
this->valuta = c.valuta;
}
void depunere(float suma)
{
if (suma > 0)
this->sold += suma;
else //throw exception("Suma este negativa");
throw ExceptieSumaNegativa("suma este negativa");
}
void retragere(float suma) {
if (suma <= this->sold)
this->sold -= suma;
else
//throw ExceptieSumaNegativa("suma este negativa");
throw ExceptieSoldIndisponibil("nu detinem bani");

float getSold() {
return this->sold;
}

void setSold(float soldNou)


{
if (soldNou > 0)
this->sold = soldNou;
}

ContBancar& operator-=(float suma)


{
this->sold -= suma;
return *this;
}

};

/*class ExceptieSumaNegativa {
private:
string mesaj;
public:
ExceptieSumaNegativa(string mesaj) {
this->mesaj = mesaj;
}

//echivalent meth what


string getMesaj() {
return this->mesaj;
}
};*/

//is a
class ContBancarOnline:public ContBancar {
public:
string token;

ContBancarOnline():ContBancar(){

ContBancarOnline(float s, string v, string t):ContBancar(s,v) {


this->token = t;
}

ContBancarOnline(const ContBancarOnline&c):ContBancar(c)//upcast+apel constr


copiere din cls de baza
{
this->token = c.token;
}

void retragere(float suma)


{
if (suma + 0.02*suma <= this->getSold())
//this->setSold(this->getSold() - suma * 1.02); //getsold e
soldul vechi
*this -= suma * 1.02; //*this e contbancaronline //face upcast
intr-un contbancar si apeleaza
}

};

class ContRevolut {
private:
ContBancarOnline* listaConturi[100]; //vector alocat static ce stocheaza
pointer la obiecte
int nrConturi;

public:
//to do
};

int main()
{
//ITranzactionabil obj; do not pt ca are metode virtuale pure
ITranzactionabil *pObj;
//ITranzactionabil vObj[100]; //do not
ITranzactionabil *pVObj[100];

//daca nu se implementeaza metodele depunere si retragere


//in ContBancar
ContBancar cb;
ContBancar *pCb;

//gestiune exceptii
ContBancar cb2(1400, "lei");
try {
cb2.depunere(200);
cb2.retragere(3000);
}
catch (exception ex) {
cout << ex.what();
};

ContBancarOnline cbo(2500, "euro", "1234");


cbo.depunere(100);
cbo.retragere(200);
cout << "\n sold rezultat:" << cbo.getSold();
}

You might also like