You are on page 1of 6

LABORATOR BUN {

return -1;
#ifndef BAZA_H_INCLUDED }
#define BAZA_H_INCLUDED };
#include <iostream> #endif // PRODUS_H_INCLUDED
#include <string.h>
#include <assert.h>
using namespace std;
class baza
{
public:
virtual void afisare()=0;
virtual int getPret()=0;
virtual ~baza(){};
virtual int nrGauri()=0; #ifndef FLOARE_H_INCLUDED
}; #define FLOARE_H_INCLUDED
#endif // BAZA_H_INCLUDED #include "produs.h"
class floare:public produs
{
#ifndef PRODUS_H_INCLUDED protected:
#define PRODUS_H_INCLUDED char *nume;
#include "baza.h" bool plastic;
class produs:virtual public baza public:
{ floare(int = 0, const char[6]="", const char* = NULL, bool = false);
protected: ~floare();
int pret; floare(const floare&);
char cod[6]; floare& operator=(const floare&);
public: void afisare();
produs(int = 0, const char[6]=""); };
int getPret(); #endif // FLOARE_H_INCLUDED
void afisare();
int nrGauri()

pag. 1
#ifndef AMBALAJ_H_INCLUDED ~aranjament();
#define AMBALAJ_H_INCLUDED aranjament(const aranjament&);
#include "produs.h" aranjament& operator=(const aranjament&);
class ambalaj:public produs int getPret();
{ void afisare();
protected: int nrGauri();
int nrFlori; };
char *tip; #endif // ARANJAMENT_H_INCLUDED
public:
ambalaj(int=0, const char[6]="",int=0, const char* = NULL);
ambalaj(const ambalaj&);
ambalaj& operator=(const ambalaj&);
~ambalaj();
void afisare(); CPP:
int getNr() const; #include "produs.h"
}; produs::produs(int pret, const char cod[6])
#endif // AMBALAJ_H_INCLUDED {
this->pret = pret;
strcpy(this->cod, cod);
}
#ifndef ARANJAMENT_H_INCLUDED int produs::getPret()
#define ARANJAMENT_H_INCLUDED {
#include "floare.h" return this->pret;
#include "ambalaj.h" }
#include "baza.h" void produs::afisare()
class aranjament:virtual public baza {
{ cout << "Produs: "<<endl;
floare *v; //dimensiune vector = amb.nrFlori cout << "Pret: " << getPret() << endl;
ambalaj amb; cout << "Cod: " << cod <<endl;
public: }
aranjament(floare *v=NULL, ambalaj =
{0,"123",false,"nume"} );

pag. 2
#include "floare.h" this->nume = NULL;
floare::floare(int pret, const char cod[6], const char* nume, bool this->plastic = p.plastic;
plastic): this->pret = p.pret;
produs(pret, cod),plastic(plastic) strcpy(this->cod, p.cod);
{ }
if(nume != NULL) return *this;
{ }
this->nume = new char[strlen(nume) + 1]; floare::floare(const floare& f)
assert(this->nume != NULL); {
strcpy(this->nume, nume); this->nume = NULL;
} *this = f;
else }
this->nume = NULL; void floare::afisare()
} {
floare::~floare() cout << "Floare" << endl;
{ produs::afisare();
if(this->nume != NULL) cout << "Plastic: " << this->plastic << endl;
delete []nume; cout << "Nume: " << this->nume << endl;
} }
floare& floare::operator=(const floare& p)
{
if(this != &p)
{
if(this->nume != NULL)
delete []this->nume;
if(p.nume != NULL)
{
this->nume = new char[strlen(p.nume) + 1];
assert(this->nume != NULL);
strcpy(this->nume, p.nume);
}
else

pag. 3
#include "ambalaj.h" this->nrFlori = a.nrFlori;
strcpy(this->cod, a.cod);
}
ambalaj::ambalaj(int pret, const char cod[6], int nrFlori, const return *this;
char* tip): }
produs(pret, cod),nrFlori(nrFlori) ambalaj::~ambalaj()
{ {
if(tip != NULL) if(this->tip != NULL)
{ delete []this->tip;
this->tip = new char[strlen(tip) + 1]; }
assert(this->tip != NULL); ambalaj::ambalaj(const ambalaj& a)
strcpy(this->tip, tip); {
} this->tip = NULL;
else *this = a;
this->tip = NULL; }
} void ambalaj::afisare()
{
ambalaj& ambalaj::operator=(const ambalaj& a) cout << "Ambalaj " << endl;
{ produs::afisare();
if(this != &a) cout << "Nr flori: " << this->nrFlori << endl;
{ cout << "Tip: " << this->tip << endl;
if(this->tip != NULL) }
delete []this->tip; int ambalaj::getNr() const
if(a.tip != NULL) {
{ return this->nrFlori;
this->tip = new char[strlen(a.tip) + 1]; }
assert(this->tip != NULL);
strcpy(this->tip, a.tip);
}
else
this->tip = NULL;
this->pret = a.pret;

pag. 4
#include "aranjament.h" }
return *this;
aranjament::aranjament(floare *v, ambalaj a) }
{ aranjament::~aranjament()
this->v = new floare[a.getNr()]; {
for(int i = 0; i < a.getNr(); i++) if(this->v != NULL)
this->v[i] = v[i]; delete []v;
this->amb = a; }
} int aranjament::getPret()
aranjament::aranjament(const aranjament& a) {
{ int pret = 0;
this->v = NULL; for(int i = 0; i < this->amb.getNr(); i++)
*this = a; pret = pret + this->v[i].getPret();
} pret += this->amb.getPret();
return pret;
aranjament& aranjament::operator=(const aranjament& a) }
{
if(this != &a) void aranjament::afisare()
{ {
if(this->v != NULL) cout << "Aranjament" << endl;
delete []v; for(int i = 0; i < this->amb.getNr(); i++)
if(a.v != NULL && a.amb.getNr() > 0) this->v[i].afisare();
{ this->amb.afisare();
this->v = new floare[a.amb.getNr()]; cout << "Pret TOTAL: " << this->getPret()<< endl;
assert(this->v != NULL); }
for(int i = 0; i < a.amb.getNr(); i++) int aranjament::nrGauri()
this->v[i] = a.v[i]; {
return this->amb.getNr();
} }
else
this->v = NULL;
this->amb = a.amb;

pag. 5
#include "aranjament.h" {
#include <typeinfo> aux = v[i];
v[i] = v[j];
int main() v[j] = aux;
{ }
int n = 4,i, j, max1 = 0; cout<< "Afisare dupa ordonare:" <<endl << endl;
baza **v = new baza*[n]; for(i = 0; i < n; i++)
floare p[5]; v[i]->afisare();
for(i = 0; i < 5; i++)
p[i] = floare(20, "cod", "coodu", true); cout << "cele mai multe flori are = " << endl;
a->afisare();
assert(v != NULL); cout << max1 << endl;
v[1] = new floare(20, "cod2", "nume2", true); for(i = 0; i < n; i++)
v[2] = new ambalaj(124, "cod3", 4, "tip3"); delete v[i];
ambalaj amb(1200, "cod3", 5, "tip3"); delete v;
v[3] = new aranjament(p, *reinterpret_cast<ambalaj*>(v[2])); return 0;
v[0] = new aranjament(p, amb); }

baza *a;
for(i = 0; i < n; i++)
{
if(typeid(aranjament) == typeid(*v[i]) && v[i]->nrGauri() >
max1 )
{
max1 = v[i]->nrGauri();
a = v[i];
}
}
baza *aux;
for(i = 0; i < n; i++)
for(j = i+1; j < n; j++)
if(v[i]->getPret() < v[j]->getPret())

pag. 6

You might also like