Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CheltuieliAmenajare
- {
- float buget;
- char* nume; // numele produsului achizitionat de tip 'Amenajare', ex: pat, candela,dulap...
- float pret;
- float numar;//numarul de persoane care au contribuit la achizitionarea obiectului amenajer.
- float contributie[10];//cu cat a contribuit.
- public:
- CheltuieliAmenajare()
- {
- this->buget = 0;
- this->nume = NULL;
- this->pret = 0;
- this->numar = 0;
- for (int i = 0;i < 10;i++)
- {
- this->contributie[i] =0;
- }
- }
- CheltuieliAmenajare(float buget, char* nume, float pret, float numar, float contributie[10])
- {
- this->buget = buget;
- this->nume = new char[strlen(nume) + 1];
- strcpy(this->nume, nume);
- this->pret = pret;
- this->numar = numar;
- for (int i = 0;i < numar;i++)
- {
- this->contributie[i] = contributie[i];
- }
- }
- CheltuieliAmenajare(const CheltuieliAmenajare& a)
- {
- this->buget = a.buget;
- this->nume = new char[strlen(a.nume) + 1];
- strcpy(this->nume, a.nume);
- this->pret = a.pret;
- this->numar = a.numar;
- for (int i = 0;i < a.numar;i++)
- {
- this->contributie[i] = a.contributie[i];
- }
- }
- float getbuget()
- {
- return this->buget;
- }
- void setbuget(float noulbuget)
- {
- if (noulbuget>0)
- {
- this->buget = noulbuget;
- }
- else
- {
- cout << " Introduceti o alta valoare pentru buget" << endl;
- }
- }
- char* getnume()
- {
- return this->nume;
- }
- void setnume(char* noulnume)
- {
- if (this->nume)
- {
- delete[] this->nume;
- }
- this->nume = new char[strlen(noulnume) + 1];
- strcpy(this->nume, noulnume);
- }
- float getpret()
- {
- return this->pret;
- }
- void setpret(float noulpret)
- {
- if (noulpret > 0)
- {
- this->pret = noulpret;
- }
- else
- {
- cout << "Introduceti o valoare noua pentru pret" << endl;
- }
- }
- int getnumar()
- {
- return this->numar;
- }
- void setnumar(int noulnumar)
- {
- if (noulnumar > 0)
- {
- this->numar = noulnumar;
- }
- else
- {
- cout << " Va rugam introduceti o valoare noua pentru numar";
- }
- }
- float getcontributie()
- {
- return *this->contributie;
- }
- void setcontributie(float contributienou[10])
- {
- for (int i = 0;i < this->numar;i++)
- {
- this->contributie[i] = contributienou[i];
- }
- }
- void bugetramas()
- {
- float bugetramas;
- bugetramas = this->buget - this->pret;
- cout << " Bugetul ramas pentru obiectul curent este:" << bugetramas<<endl<<endl;
- }
- CheltuieliAmenajare& operator = (const CheltuieliAmenajare& a)
- {
- this->buget = a.buget;
- if (this->nume)
- {
- delete this->nume;
- }
- this->nume = new char[strlen(a.nume) + 1];
- strcpy(this->nume, a.nume);
- this->pret = a.pret;
- this->numar = a.numar;
- for (int i = 0;i < a.numar;i++)
- {
- this->contributie[i] = a.contributie[i];
- }
- return *this;
- }
- CheltuieliAmenajare operator + (CheltuieliAmenajare& s)
- {
- CheltuieliAmenajare temp = *this;
- temp.buget = temp.buget + s.buget;
- return temp;
- }
- CheltuieliAmenajare operator ++ ()
- {
- this->buget++;
- return *this;
- }
- CheltuieliAmenajare operator ++ (int i)
- {
- CheltuieliAmenajare temp = *this;
- this->buget++;
- return temp;
- }
- explicit operator int()
- {
- return buget / pret;
- }
- void operator ! ()
- {
- this->buget = 0;
- }
- bool operator>(CheltuieliAmenajare p)
- {
- if (this->buget > p.buget)
- {
- return true;
- }
- else
- return false;
- }
- bool operator==(CheltuieliAmenajare s)
- {
- if (this->buget == s.buget)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- friend ostream& operator << (ostream&, CheltuieliAmenajare);
- friend istream& operator >> (istream&, CheltuieliAmenajare&);
- ~CheltuieliAmenajare()
- {
- if (this->nume)
- {
- delete[] this->nume;
- }
- }
- };
- //float buget, char* nume, float pret, float numar, float contributie[10]
- ostream& operator << (ostream& out, CheltuieliAmenajare a )
- {
- out << endl;
- out << " Bugetul este: " << a.buget << endl;
- out << " Numele este: " << a.nume << endl;
- out << " Pretul este: " << a.pret << endl;
- out << " Numarul de persoane care au contribuit este: " << a.numar;
- out << endl;
- for (int i = 0;i < a.numar;i++)
- {
- out << " Persoana " << i << " a contribuit cu " << a.contributie[i]<<endl;
- }
- out << endl;
- return out;
- }
- istream& operator >> (istream& in , CheltuieliAmenajare& a)
- {
- cout << endl;
- cout << " Introduceti bugetul: ";
- in >> a.buget;
- char buffer[100];
- cout << " Introduceti numele: ";
- in >> buffer;
- if (strlen(buffer) > 0)
- {
- if (a.nume)
- {
- delete[] a.nume;
- }
- a.nume = new char[strlen(buffer) + 1];
- strcpy(a.nume, buffer);
- }
- cout << endl;
- cout << " Introduceti pretul: ";
- in >> a.pret;
- cout << endl;
- cout << " Introduceti numarul persoanelor contribuabile: ";
- in >> a.numar;
- cout << endl;
- for (int i = 0;i < a.numar;i++)
- {
- cout << " Persoana " << i << " a contribuit cu ";
- in >> a.contributie[i];
- }
- return in;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement