Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- using namespace std;
- class Produs
- {
- protected:
- char* nume;
- double pret;
- int cantitate;
- Produs()
- {
- nume = NULL;
- pret = 0;
- cantitate = 0;
- }
- public:
- Produs(char* x, double y, int z)
- {
- nume = new char[strlen(x) + 1];
- strcpy(nume, x);
- pret = y;
- cantitate = z;
- }
- ~Produs()
- {
- nume = NULL;
- delete[] nume;
- }
- virtual double recalcularepret() = 0;
- virtual double calcularetotal() = 0;
- virtual char* numex() = 0;
- virtual int cantitatex() = 0;
- virtual double pretx() = 0;
- };
- class Carne:public Produs
- {
- protected:
- Carne() :Produs() {}
- public:
- Carne(char* x, double y, int z) :Produs(x, y, z) {}
- double recalcularepret()
- {
- pret = pret + 0.15*pret;
- if (cantitate >= 10 && cantitate < 20)
- {
- pret = 0.9*pret;
- }
- else
- if (cantitate >= 20)
- pret = 0.8*pret;
- return pret;
- }
- double calcularetotal()
- {
- double total = 0;
- total = pret*cantitate;
- return total;
- }
- char* numex()
- {
- return nume;
- }
- int cantitatex()
- {
- return cantitate;
- }
- double pretx()
- {
- return pret;
- }
- };
- class Lactate :public Produs
- {
- protected:
- Lactate() :Produs() {}
- public:
- Lactate(char* x, double y, int z) :Produs(x, y, z) {}
- double recalcularepret()
- {
- pret = pret + 0.09*pret;
- if (cantitate >= 10 && cantitate < 20)
- {
- pret = 0.9*pret;
- }
- else
- if (cantitate >= 20)
- pret = 0.8*pret;
- if (strstr(nume, "bio"))
- {
- pret = pret + 0.18*pret;
- }
- return pret;
- }
- double calcularetotal()
- {
- double total = 0;
- total = pret*cantitate;
- return total;
- }
- char* numex()
- {
- return nume;
- }
- int cantitatex()
- {
- return cantitate;
- }
- double pretx()
- {
- return pret;
- }
- };
- class Legume :public Produs
- {
- protected:
- Legume() :Produs() {}
- public:
- Legume(char* x, double y, int z) :Produs(x, y, z) {}
- double recalcularepret()
- {
- pret = pret + 0.15*pret;
- if (cantitate >= 10 && cantitate < 20)
- {
- pret = 0.9*pret;
- }
- else
- if (cantitate >= 20)
- pret = 0.8*pret;
- if (strstr(nume, "bio"))
- {
- pret = pret + 0.18*pret;
- }
- return pret;
- }
- double calcularetotal()
- {
- double total = 0;
- total = pret*cantitate;
- return total;
- }
- char* numex()
- {
- return nume;
- }
- int cantitatex()
- {
- return cantitate;
- }
- double pretx()
- {
- return pret;
- }
- };
- class Fructe :public Produs
- {
- protected:
- Fructe() :Produs() {}
- public:
- Fructe(char* x, double y, int z) :Produs(x, y, z) {}
- double recalcularepret()
- {
- pret = pret + 0.2*pret;
- if (cantitate >= 10 && cantitate < 20)
- {
- pret = 0.9*pret;
- }
- else
- if (cantitate >= 20)
- pret = 0.8*pret;
- return pret;
- }
- double calcularetotal()
- {
- double total = 0;
- total = pret*cantitate;
- return total;
- }
- char* numex()
- {
- return nume;
- }
- int cantitatex()
- {
- return cantitate;
- }
- double pretx()
- {
- return pret;
- }
- };
- void functie(Produs *x[10])
- {
- for (int i = 0; i < 10; i++)
- {
- x[i]->recalcularepret();
- cout << x[i]->numex() << endl;
- cout << x[i]->pretx() << " * " << x[i]->cantitatex() << " = " << x[i]->calcularetotal() << endl;
- }
- double prettotal = 0;
- for (int i = 0; i < 10; i++)
- {
- prettotal = prettotal + x[i]->calcularetotal();
- }
- if (prettotal > 100 && prettotal < 200)
- {
- cout << "Pretul total al bonului este:" << prettotal << " si a-ti primit si o jucarie gratis." << endl;
- }
- if (prettotal > 200 && prettotal < 300)
- {
- prettotal = prettotal*0.9;
- cout << "Pretul total al bonului este:" << prettotal;
- }
- if (prettotal > 300)
- {
- prettotal = prettotal*0.8;
- cout << "Pretul total al bonului este:" << prettotal;
- }
- }
- int main()
- {
- Produs *Bon[10];
- Bon[0] = new Fructe("Mar", 1, 6);
- Bon[1] = new Fructe("Portocala", 2, 9);
- Bon[2] = new Fructe("Avocado bio", 3, 3);
- Bon[3] = new Lactate("Lapte Batut", 12, 1);
- Bon[4] = new Lactate("Branza", 12, 2);
- Bon[5] = new Lactate("Cascaval", 20, 1);
- Bon[6] = new Legume("Morcov", 1, 2);
- Bon[7] = new Legume("Porumb bio", 5, 3);
- Bon[8] = new Legume("Rosie", 7, 3);
- Bon[9] = new Carne("Carne Porc", 18, 2);
- functie(Bon);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement