Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- class Zamowienie{
- private:
- string wymiar;
- string material;
- string kolor;
- string typ;
- public:
- void setwymiar(const string& s)
- {
- this->wymiar = s;
- }
- void setmaterial(const string& s)
- {
- this->material = s;
- }
- void setkolor(const string& s)
- {
- this->kolor = s;
- }
- void settyp(const string& s)
- {
- this->typ = s;
- }
- void show(){
- cout <<endl;
- cout << typ << ": " <<endl;
- cout << "Dlugosc = " << wymiar << endl;
- cout << "Material = " << material << endl;
- cout << "Kolor = " << kolor <<endl;
- }
- Zamowienie(){}
- ~Zamowienie(){}
- };
- class Builder{
- public:
- virtual void BuildWymiar()=0;
- virtual void BuildMaterial()=0;
- virtual void BuildKolor()=0;
- virtual void BuildTyp()=0;
- virtual Zamowienie* GetProduct()=0;
- Builder(){}
- virtual ~Builder(){}
- };
- class BMarynarka:public Builder{
- public:
- BMarynarka(){
- this->m_zam = new Zamowienie();
- }
- ~BMarynarka(){
- }
- virtual void BuildWymiar(){
- int k;
- while(true)
- {
- cout << "Wybierz wymiar marynarki: (1) 50 cm, (2) 100 cm , (3) 150 cm" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "50 cm";
- else if (k==2) wyb = "100 cm";
- else if (k==3) wyb = "150 cm";
- this->m_zam->setwymiar(wyb);
- }
- virtual void BuildMaterial(){
- int k;
- while(true)
- {
- cout << "Wybierz material marynarki: (1) Welna, (2) Bawelna , (3) Skora Krokodyla" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "Welna";
- else if (k==2) wyb = "Bawelna";
- else if (k==3) wyb = "Skora Krokodyla";
- this->m_zam->setmaterial(wyb);
- }
- virtual void BuildKolor(){
- int k;
- while(true)
- {
- cout << "Wybierz kolor marynarki: (1) Blue, (2) Black , (3) Pink" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "Blue";
- else if (k==2) wyb = "Black";
- else if (k==3) wyb = "Pink";
- this->m_zam->setkolor(wyb);
- }
- virtual void BuildTyp(){
- this->m_zam->settyp("Marynarka");
- }
- virtual Zamowienie* GetProduct(){
- return this->m_zam;
- }
- private:
- Zamowienie* m_zam;
- };
- class BSpodnie:public Builder{
- public:
- BSpodnie(){
- this->m_zam = new Zamowienie();
- }
- ~BSpodnie(){
- }
- virtual void BuildWymiar(){
- int k;
- while(true)
- {
- cout << "Wybierz wymiar spodni: (1) 50 cm, (2) 100 cm , (3) 150 cm" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "50 cm";
- else if (k==2) wyb = "100 cm";
- else if (k==3) wyb = "150 cm";
- this->m_zam->setwymiar(wyb);
- }
- virtual void BuildMaterial(){
- int k;
- while(true)
- {
- cout << "Wybierz material spodni: (1) Welna, (2) Bawelna , (3) Skora Krokodyla" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "Welna";
- else if (k==2) wyb = "Bawelna";
- else if (k==3) wyb = "Skora Krokodyla";
- this->m_zam->setmaterial(wyb);
- }
- virtual void BuildKolor(){
- int k;
- while(true)
- {
- cout << "Wybierz kolor spodni: (1) Blue, (2) Black , (3) Pink" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "Blue";
- else if (k==2) wyb = "Black";
- else if (k==3) wyb = "Pink";
- this->m_zam->setkolor(wyb);
- }
- virtual void BuildTyp(){
- this->m_zam->settyp("Spodnie");
- }
- virtual Zamowienie* GetProduct(){
- return this->m_zam;
- }
- private:
- Zamowienie* m_zam;
- };
- class BSpodnica:public Builder{
- public:
- BSpodnica(){
- this->m_zam = new Zamowienie();
- }
- ~BSpodnica(){
- }
- virtual void BuildWymiar(){
- int k;
- while(true)
- {
- cout << "Wybierz dlugosc spodnicy: (1) 50 cm, (2) 60 cm , (3) 70 cm" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "50 cm";
- else if (k==2) wyb = "100 cm";
- else if (k==3) wyb = "150 cm";
- this->m_zam->setwymiar(wyb);
- }
- virtual void BuildMaterial(){
- int k;
- while(true)
- {
- cout << "Wybierz material spodnicy: (1) Welna, (2) Bawelna , (3) Skora Krokodyla" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "Welna";
- else if (k==2) wyb = "Bawelna";
- else if (k==3) wyb = "Skora Krokodyla";
- this->m_zam->setmaterial(wyb);
- }
- virtual void BuildKolor(){
- int k;
- while(true)
- {
- cout << "Wybierz kolor spodnicy: (1) Blue, (2) Black , (3) Pink" << endl;
- cin >> k;
- if(k>0 && k<4)
- break;
- }
- string wyb;
- if (k==1) wyb = "Blue";
- else if (k==2) wyb = "Black";
- else if (k==3) wyb = "Pink";
- this->m_zam->setkolor(wyb);
- }
- virtual void BuildTyp(){
- this->m_zam->settyp("Spodnica");
- }
- virtual Zamowienie* GetProduct(){
- return this->m_zam;
- }
- private:
- Zamowienie* m_zam;
- };
- class Director
- {
- public:
- Director(Builder* pBuilder){
- this->m_pBuilder = pBuilder;
- }
- ~Director(){
- delete this->m_pBuilder;
- this->m_pBuilder = NULL;
- }
- void Construct(){
- this->m_pBuilder->BuildWymiar();
- this->m_pBuilder->BuildMaterial();
- this->m_pBuilder->BuildKolor();
- this->m_pBuilder->BuildTyp();
- }
- Builder* Build(){
- return m_pBuilder;
- }
- private:
- Builder* m_pBuilder;
- };
- int main(){
- list <Zamowienie*> lst;
- list <Zamowienie*>::iterator t;
- Director *d;
- int a;
- for(int i = 0; i<5; i++)
- {
- cout << "Wybierz produkt: (1) Marynarka, (2) Spodnie , (3) Spodnica" << endl;
- cin >> a;
- switch(a)
- {
- case 1:
- d = new Director(new BMarynarka());
- break;
- case 2:
- d= new Director(new BSpodnie());
- break;
- case 3:
- d = new Director(new BSpodnica());
- break;
- default:
- break;
- }
- d->Construct();
- lst.push_back(d->Build()->GetProduct());
- delete d;
- }
- for(t=lst.begin(); t!= lst.end(); ++t){
- (*t)->show();
- }
- for(list <Zamowienie*>::iterator temp, t=lst.begin(); t!=lst.end();){
- temp = t;
- t++;
- delete *temp;
- }
- lst.clear();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement