Sunteți pe pagina 1din 6

// ConsoleApplication8.cpp : This file contains the 'main' function.

Program
execution begins and ends there.
//

#include "pch.h"
#include <iostream>
#include<string>
using namespace std;

class IstoricCumparaturi {
private:

const int codProd;


static int pctFidelitate;
string denProdus;
int nrProd;
float *pret;
bool transpGratuit;

public:

int get_codProd() {

return this->codProd;

string get_denProdus() {

return this->denProdus;

int get_nrProd() {

return this->nrProd;
}

float* get_pret() {

if (this->pret != NULL)
return this->pret;;
}

bool get_transport() {

return this->transpGratuit;
}

void set_denumire(string den) {

if (den.length() > 1)
this->denProdus = den;
}

void set_nrproduse(int nr) {


this->nrProd = nr;

void set_pret(float*pret, int nr) {

if (pret != NULL)
delete[]pret;
pret = new float[nr];
for (int i = 0; i < nr; i++)
this->pret[i] = pret[i];

void set_transport(bool transp) {

if (transp == 0)
cout << "Transportul nu este gratuit";
else
if(transp==1)
cout << "trasportul este gratuit";

IstoricCumparaturi() :codProd(2000) {

this->denProdus = "";
this->nrProd = 0;
this->pret = NULL;
this->transpGratuit = false;

IstoricCumparaturi(int id) :codProd(id) {

this->denProdus = "***";
this->nrProd = 0;
this->pret = NULL;
this->transpGratuit = false;

IstoricCumparaturi(int id, string den, int nr, float* pret, bool transp)
:codProd(id) {

this->denProdus = den;
this->nrProd = nr;
if (this->pret != NULL)
delete[]this->pret;
this->pret = new float[this->nrProd];
for (int i = 0; i < this->nrProd; i++)
this->pret[i] = pret[i];
this->transpGratuit = transp;

}
IstoricCumparaturi(int id, string den, int nr, float* pret) :codProd(id) {

this->denProdus = den;
this->nrProd = nr;
if (this->pret != NULL)
delete[]this->pret;
this->pret = new float[this->nrProd];
for (int i = 0; i < this->nrProd; i++)
this->pret[i] = pret[i];

IstoricCumparaturi(const IstoricCumparaturi&ic) :codProd(ic.codProd) {

this->denProdus = ic.denProdus;
this->nrProd = ic.nrProd;
if (this->pret != NULL)
delete[]this->pret;
this->pret = new float[this->nrProd];
for (int i = 0; i < this->nrProd; i++)
this->pret[i] = ic.pret[i];
this->transpGratuit = ic.transpGratuit;
}

IstoricCumparaturi&operator=(const IstoricCumparaturi&ic) {

this->denProdus = ic.denProdus;
this->nrProd = ic.nrProd;
if (this->pret != NULL)
delete[]this->pret;
this->pret = new float[this->nrProd];
for (int i = 0; i < this->nrProd; i++)
this->pret[i] = ic.pret[i];
this->transpGratuit = ic.transpGratuit;
return *this;

~IstoricCumparaturi() {

if (this->pret != NULL)
delete[]this->pret;

friend ostream&operator<<(ostream &out, IstoricCumparaturi&ic);


friend istream&operator>>(istream&in, IstoricCumparaturi&ic);

void TotalCumparaturi() {

float total = 0;
this->pret = new float[nrProd];
for (int i = 0; i < this->nrProd; i++)
total +=pret[i];
cout << total;

}
//operator +
IstoricCumparaturi &operator+(float n) {

if (this->pret != NULL)
for (int i = 0; i < this->nrProd; i++)
this->pret[i] += n;

return *this;

//operator +=
IstoricCumparaturi &operator+=(float pretNou) {

IstoricCumparaturi copie = *this;


float *vectorNou = new float[copie.nrProd + 10];
for (int i = 0; i < copie.nrProd; i++) {
vectorNou[i] = copie.pret[i];
}
vectorNou[copie.nrProd] = pretNou;
if (copie.pret != NULL)
delete[]copie.pret;
copie.pret= vectorNou;
copie.nrProd += 1;
return copie;

//operator *

IstoricCumparaturi &operator*(int m) {

this->nrProd = nrProd * m;

return *this;

};
ostream&operator<<(ostream &out, IstoricCumparaturi&ic) {

out << "\nCodul produsului : " << ic.codProd;


out << "\nDenumire Produs : " << ic.denProdus;
out << "\nNumarul produselor : " << ic.nrProd;
if (ic.pret != NULL)
{
out << "\nPreturile sunt : ";
for (int i = 0; i < ic.nrProd; i++)
out << ic.pret[i] << " ";
}
out << "\nTranport gratuit: " << ic.transpGratuit;

return out;
}

istream&operator>>(istream&in, IstoricCumparaturi&ic) {

cout << "\nIntroduceti numele produsului :";


in.ignore();
getline(in, ic.denProdus);
cout << "\nIntroduceti nr de produse :";
in >> ic.nrProd;
cout << "\nPreturile : ";
if (ic.pret != NULL)
delete[]ic.pret;
ic.pret = new float[ic.nrProd];
for (int i = 0; i < ic.nrProd; i++)
in >> ic.pret[i];
cout << "\nTransport gratuit(DA/NU): ";
in >> ic.transpGratuit;

return in;

}
int main()
{

IstoricCumparaturi i1;
cout << i1;
IstoricCumparaturi i2;
cin >> i2;
cout << i2 << endl;
IstoricCumparaturi i3(2001);
IstoricCumparaturi i4(2002, "Sampon", 3, new float[3]{ 12.5, 13, 17 }, false);
IstoricCumparaturi i5(2003, "Vopsea", 1, new float[1]{ 31 });
cout << i3 << i4 << i5 << endl;
i5 = i2;
cout << i5 << endl;
i5.set_transport(1);
cout << endl;
//cout << "Totalul este : ";
//i4.TotalCumparaturi();
//cout << endl;

IstoricCumparaturi i6(2005, "Fard de obraz", 2, new float[2]{ 36.5, 28 });


cout << i6 << endl;
i6 = i4 + 10;
cout << i6 << endl;

IstoricCumparaturi i7;
float vectorPreturi[2]{ 22.8, 34.5 };
i7 = i2;
i7 = i7 * 2;
//i7 +=
cout << i7;
}