You are on page 1of 7

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <fstream>
#include <string.h>
using namespace std;
#define pU 0.0018
#define pS 0.002
#define cost_faina_alba 0.0015
#define cost_faina_integrala 0.0020
#define cost_umplutura_mere 0.006
#define cost_umplutura_branza 0.007
#define cost_manopera 0.005
#define seminte_susan 0.0004
#define seminte_mac 0.0002

class Produs
{
protected:
char* nume;
float greutate;
float pret_vanzare;
float pret_productie;
public:
Produs()
{
nume = NULL;
greutate = 0;
pret_vanzare = 0;
pret_productie = 0;
}
Produs(char* nume, float greutate, float pret_vanzare)
{
if (nume)
{
this->nume = new char[strlen(nume) + 1];
if (!this->nume)
throw "Eroare la alocare";
strcpy(this->nume, nume);
}
this->greutate = greutate;
this->pret_vanzare = pret_vanzare;
}
Produs(const Produs &td)
{
if (td.nume)
{
this->nume = new char[strlen(td.nume) + 1];
if (!this->nume)
throw "Eroare la alocare";
strcpy(this->nume, td.nume);
}
this->greutate = td.greutate;
this->pret_vanzare = td.pret_vanzare;
}
Produs operator=(Produs &td)
{
if (this != &td)
{
if (td.nume)
{
this->nume = new char[strlen(td.nume) + 1];
if (!this->nume)
throw "Eroare la alocare";
strcpy(this->nume, td.nume);
}
this->greutate = td.greutate;
this->pret_vanzare = td.pret_vanzare;
}
return *this;
}

~Produs()
{
if (nume)
delete[] nume;
}

void afis()
{
cout << "nume produs=" << nume << " \n";
cout << "greutate=" << greutate << " \n";
cout << "pret_vanzare=" << pret_vanzare << "\n";
cout << "pret_productie=" << pret_productie << endl << endl;
}
virtual void cost_prod()
{
return;
}

float get_pret_vanzare()
{
return pret_vanzare;
}
float get_pret_productie()
{
return pret_productie;
}

};

class Paine_alba :public Produs


{
public:
Paine_alba() :Produs() {}
Paine_alba(char* nume1, float greutate1, float pret_productie1) :Produs(nume1,
greutate1, pret_productie1)
{
cost_prod();
}
void cost_prod()
{
pret_productie =(float) (greutate * cost_faina_alba);
pret_productie = (float)(pret_productie - 0.1*pret_productie);
pret_productie = (float)(pret_productie + 0.09*pret_productie);
}
};

class Paine_integrala :public Produs


{
public:
Paine_integrala() :Produs() {}
Paine_integrala(char* nume1, float greutate1, float pret_productie1) :Produs(nume1,
greutate1, pret_productie1)
{
cost_prod();
}
void cost_prod()
{
pret_productie = (float)(greutate * cost_faina_integrala);
pret_productie = (float)(pret_productie + 0.09*pret_productie);
}
};

class Covrigi_susan :public Produs


{
public:
Covrigi_susan() :Produs() {}
Covrigi_susan(char* nume1, float greutate1, float pret_productie1) :Produs(nume1,
greutate1, pret_productie1)
{
cost_prod();
}
void cost_prod()
{
pret_productie = (float)(greutate * cost_manopera + pS *
greutate*seminte_susan);
pret_productie = (float)(pret_productie + 0.19*pret_productie);
}
};

class Covrigi_mac :public Produs


{
public:
Covrigi_mac() :Produs() {}
Covrigi_mac(char* nume1, float greutate1, float pret_productie1) :Produs(nume1,
greutate1, pret_productie1)
{
cost_prod();
}
void cost_prod()
{
pret_productie = (float)(greutate * cost_manopera + pS * greutate*seminte_mac);
pret_productie = (float)(pret_productie + 0.19*pret_productie);
}
};

class Placinta_branza :public Produs


{
public:
Placinta_branza() :Produs() {}
Placinta_branza(char* nume1, float greutate1, float pret_productie1) :Produs(nume1,
greutate1, pret_productie1)
{
cost_prod();
}
void cost_prod()
{
pret_productie = (float)(greutate * cost_manopera + pU *
greutate*cost_umplutura_branza);
pret_productie = (float)(pret_productie + 0.19*pret_productie);
}
};

class Placinta_mere :public Produs


{
public:
Placinta_mere() :Produs() {}
Placinta_mere(char* nume1, float greutate1, float pret_productie1) :Produs(nume1,
greutate1, pret_productie1)
{
cost_prod();
}
void cost_prod()
{
pret_productie = (float)(greutate * cost_manopera + pU *
greutate*cost_umplutura_mere);
pret_productie = (float)(pret_productie + 0.19*pret_productie);
}
};

void afiseaza_vector(Produs** v, int n)


{
for (int i = 0; i < n; i++)
{
v[i]->afis();
}
}
float profit(Produs** v, int n)
{
float s = 0;
for (int i = 0; i < n; i++)
s = s + v[i]->get_pret_vanzare() - v[i]->get_pret_productie();
return s;
}

int main()
{
int cod;
char* nume1 = new char[30];
float greutate1, pret_vanzare1;
ifstream f("Dateintrare.txt");
int n;
cout << "Introduceti numarul de produse: "; cin >> n;
Produs** v = new Produs*[n];
int i = 0;
while (f >> cod)
{
if (cod == 1)
{
f >> nume1;
f >> greutate1 >> pret_vanzare1;
v[i] = new Paine_alba(nume1, greutate1, pret_vanzare1);
i++;
delete[] nume1;
nume1 = new char[30];
}
if (cod == 2)
{
f >> nume1;
f >> greutate1 >> pret_vanzare1;
v[i] = new Paine_integrala(nume1, greutate1, pret_vanzare1);
i++;
delete[] nume1;
nume1 = new char[30];
}
if (cod == 3)
{
f >> nume1;
f >> greutate1 >> pret_vanzare1;
v[i] = new Placinta_mere(nume1, greutate1, pret_vanzare1);
i++;
delete[] nume1;
nume1 = new char[30];

}
if (cod == 4)
{
f >> nume1;
f >> greutate1 >> pret_vanzare1;
v[i] = new Placinta_branza(nume1, greutate1, pret_vanzare1);
i++;
delete[] nume1;
nume1 = new char[30];
}
if (cod == 5)
{
f >> nume1;
f >> greutate1 >> pret_vanzare1;
v[i] = new Covrigi_susan(nume1, greutate1, pret_vanzare1);
i++;
delete[] nume1;
nume1 = new char[30];
}
if (cod == 6)
{
f >> nume1;
f >> greutate1 >> pret_vanzare1;
v[i] = new Covrigi_susan(nume1, greutate1, pret_vanzare1);
i++;
delete[] nume1;
nume1 = new char[30];
}
}
delete[] nume1;
afiseaza_vector(v, n);
f.close();
cout << endl;
cout << "profit=" << profit(v, n) << endl;
system("pause");
return 0;
}

You might also like