Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp: Określa punkt wejścia dla aplikacji konsoli.
- //
- #include <iostream>
- #include <list>
- #include <typeinfo>
- #include <string>
- #define _CRTDBG_MAP_ALLOC
- #include <stdlib.h>
- #include <crtdbg.h>
- // krawiec - marynarke spodnie spodniczke
- // produkt - zamowienie
- // zbieraniem zamowien zajmuje sie konkretny budowniczy
- // inny budowniczy dla marynarki, spodni i spodniczki
- // kazde zamowienie do listy produktow
- // krawiec zbiera: dlugosc spodni, obwod w pasie - po 2 wymiary
- // marynarka - kolniez i dlugosc rekawow
- // l - dlgosc w calach, w - szerokosc dla spodni
- // spodniczka - dlugosc, obwod
- // to wszystko w stringu - dlugosc:30, szerokosc:60
- // drugi parametr to z jakiego materialu - welniane, jedwab - zestaw materialow do wyboru dla krawca - jedne materialy nie nadaja sie dla marynarki
- // trzeci parametr: kolor
- // co ma byc? marynarka - tworzymy budowniczego od marynarki - wynik to zamowienie ktore zamiescimy na liste
- // na koniec lista z metoda do wypisania jej zawartosci na ekranie
- // tak zrobic zeby jak dodamy koszule nie bedzie trzeba nic modyfikowac
- // ustawic interfejs budowniczego - jakie metody
- // jakie czesci wspolne - rozmiary, material, kolor
- // w case trworzysz budowniczego
- // nastepnie tworzymy dyrektora
- // na dyrektorze construkt
- // getproduct
- // metoda statyccznna - mozna wywolac metode na samej klasie, bez obiektu
- /* w konstruktorze otworzyc plik w destruktorze zamknac do obserwatora*/
- using namespace std;
- class Product
- {
- private:
- string m_partName;
- string m_partA;
- string m_partB;
- string m_partC;
- public:
- void setPartName(const string& s); // metoda czysto wirtualna
- void setPartA(const string& s);
- void setPartB(const string& s);
- void setPartC(const string& s);
- Product();
- string Nazwa()
- {
- return m_partName;
- }
- string Rozmiar()
- {
- return m_partA;
- }
- string Material()
- {
- return m_partB;
- }
- string Kolor()
- {
- return m_partC;
- }
- void Wypisz()
- {
- cout << "Nr. zamowienia: " << ": " << m_partName << " - Rozmiar: " << m_partA << " Material: " << m_partB << " Kolor: " << m_partC << endl;
- }
- ~Product();
- };
- class Builder
- {
- public:
- virtual void BuildPartName() = 0;
- virtual void BuildPartA() = 0;
- virtual void BuildPartB() = 0;
- virtual void BuildPartC() = 0;
- virtual Product* GetProduct() = 0;
- Builder();
- virtual ~Builder();
- };
- class ConcreteBuilder1 :public Builder
- {
- public:
- ConcreteBuilder1();
- ~ConcreteBuilder1();
- virtual void BuildPartName();
- virtual void BuildPartA();
- virtual void BuildPartB();
- virtual void BuildPartC();
- virtual Product* GetProduct();
- private:
- Product* m_pProduct;
- };
- class ConcreteBuilder2 :public Builder
- {
- public:
- ConcreteBuilder2();
- ~ConcreteBuilder2();
- virtual void BuildPartName();
- virtual void BuildPartA();
- virtual void BuildPartB();
- virtual void BuildPartC();
- virtual Product* GetProduct();
- private:
- Product* m_pProduct;
- };
- class ConcreteBuilder3 :public Builder
- {
- public:
- ConcreteBuilder3();
- ~ConcreteBuilder3();
- virtual void BuildPartName();
- virtual void BuildPartA();
- virtual void BuildPartB();
- virtual void BuildPartC();
- virtual Product* GetProduct();
- private:
- Product* m_pProduct;
- };
- class Director
- {
- public:
- Director(Builder* pBuilder);
- ~Director();
- void Construct();
- Builder* Build()
- {
- return m_pBuilder;
- }
- private:
- Builder* m_pBuilder;
- };
- Product::~Product()
- {
- }
- Product::Product()
- {
- }
- void Product::setPartName(const string& s)
- {
- this->m_partName = s;
- }
- void Product::setPartA(const string& s)
- {
- this->m_partA = s;
- }
- void Product::setPartB(const string& s)
- {
- this->m_partB = s;
- }
- void Product::setPartC(const string& s)
- {
- this->m_partC = s;
- }
- Builder::Builder()
- {
- }
- Builder::~Builder()
- {
- }
- ConcreteBuilder1::ConcreteBuilder1()
- {
- this->m_pProduct = new Product();
- cout << endl << "Tworzenie marynarki" << endl;
- }
- void ConcreteBuilder1::BuildPartName()
- {
- this->m_pProduct->setPartName("Marynarka");
- }
- void ConcreteBuilder1::BuildPartA()
- {
- string temp = "";
- cout << endl << "Rozmiar kolnierzyka: ";
- cin >> temp;
- this->m_pProduct->setPartA(temp);
- cout << "Wprowadzony rozmiar kolnierzyka: " << temp << endl;
- }
- void ConcreteBuilder1::BuildPartB()
- {
- int temp = 0;
- bool menu = true;
- while (menu)
- {
- cout << endl << "1 - Bawelna" << endl << "2 - Skora" << endl << "3 - Powidla" << endl << "Wybierz material: ";
- cin >> temp;
- menu = false;
- switch (temp)
- {
- case 1:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Bawelna");
- cout << "Bawelna" << endl;
- break;
- }
- case 2:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Skora");
- cout << "Skora" << endl;
- break;
- }
- case 3:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Powidla");
- cout << "Powidla" << endl;
- break;
- }
- default:
- {
- cout << "Nie ma takiej opcji! Podaj material ponownie.";
- menu = true;
- break;
- }
- }
- }
- }
- void ConcreteBuilder1::BuildPartC()
- {
- string temp = "";
- cout << endl << "podaj kolor: ";
- cin >> temp;
- this->m_pProduct->setPartC(temp);
- cout << "Wprowadzono kolor: " << temp << endl;
- }
- Product* ConcreteBuilder1::GetProduct()
- {
- return this->m_pProduct;
- }
- ConcreteBuilder1::~ConcreteBuilder1()
- {
- delete this->m_pProduct;
- this->m_pProduct = NULL;
- }
- ConcreteBuilder2::ConcreteBuilder2()
- {
- this->m_pProduct = new Product();
- cout << endl << "Tworzenie spodni" << endl;
- }
- void ConcreteBuilder2::BuildPartName()
- {
- this->m_pProduct->setPartName("Spodnie");
- }
- void ConcreteBuilder2::BuildPartA()
- {
- string temp = "";
- cout << endl << "podaj rozmiar: ";
- cin >> temp;
- this->m_pProduct->setPartA(temp);
- cout << "Wprowadzono rozmiar: " << temp << endl;
- }
- void ConcreteBuilder2::BuildPartB()
- {
- int temp = 0;
- bool menu = true;
- while (menu)
- {
- cout << endl << "1 - bawelna" << endl << "2 - skora" << endl << "3 - powidla" << endl << "Wybierz material: ";
- cin >> temp;
- menu = false;
- switch (temp)
- {
- case 1:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Bawelna");
- cout << "bawelna" << endl;
- break;
- }
- case 2:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Skora");
- cout << "skora" << endl;
- break;
- }
- case 3:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Powidla");
- cout << "powidla" << endl;
- break;
- }
- default:
- {
- cout << "Nie ma takiej opcji!";
- menu = true;
- break;
- }
- }
- }
- }
- void ConcreteBuilder2::BuildPartC()
- {
- string temp = "";
- cout << endl << "podaj kolor: ";
- cin >> temp;
- this->m_pProduct->setPartC(temp);
- cout << "Wprowadzono kolor: " << temp << endl;
- }
- Product* ConcreteBuilder2::GetProduct()
- {
- return this->m_pProduct;
- }
- ConcreteBuilder2::~ConcreteBuilder2()
- {
- delete this->m_pProduct;
- this->m_pProduct = NULL;
- }
- ConcreteBuilder3::ConcreteBuilder3()
- {
- this->m_pProduct = new Product();
- cout << endl << "Tworzenie spodniczki" << endl;
- }
- void ConcreteBuilder3::BuildPartName()
- {
- this->m_pProduct->setPartName("Spodniczka");
- }
- void ConcreteBuilder3::BuildPartA()
- {
- string temp = "";
- cout << endl << "podaj rozmiar: ";
- cin >> temp;
- this->m_pProduct->setPartA(temp);
- cout << "Wprowadzono rozmiar: " << temp << endl;
- }
- void ConcreteBuilder3::BuildPartB()
- {
- int temp = 0;
- bool menu = true;
- while (menu)
- {
- cout << endl << "1 - bawelna" << endl << "2 - skora" << endl << "3 - powidla" << endl << "Wybierz material: ";
- cin >> temp;
- menu = false;
- switch (temp)
- {
- case 1:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Bawelna");
- cout << "bawelna" << endl;
- break;
- }
- case 2:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Skora");
- cout << "skora" << endl;
- break;
- }
- case 3:
- {
- cout << endl << "Wybrales material: ";
- this->m_pProduct->setPartB("Powidla");
- cout << "powidla" << endl;
- break;
- }
- default:
- {
- cout << "Nie ma takiej opcji!";
- menu = true;
- break;
- }
- }
- }
- }
- void ConcreteBuilder3::BuildPartC()
- {
- string temp = "";
- cout << endl << "podaj kolor: ";
- cin >> temp;
- this->m_pProduct->setPartC(temp);
- cout << "Wprowadzono kolor: " << temp << endl;
- }
- Product* ConcreteBuilder3::GetProduct()
- {
- return this->m_pProduct;
- }
- ConcreteBuilder3::~ConcreteBuilder3()
- {
- delete this->m_pProduct;
- this->m_pProduct = NULL;
- }
- Director::Director(Builder* pBuilder)
- {
- this->m_pBuilder = pBuilder;
- }
- void Director::Construct()
- {
- this->m_pBuilder->BuildPartName();
- this->m_pBuilder->BuildPartA();
- this->m_pBuilder->BuildPartB();
- this->m_pBuilder->BuildPartC();
- }
- Director::~Director()
- {
- delete this->m_pBuilder;
- this->m_pBuilder = NULL;
- }
- int main()
- {
- int produkt = 0;
- bool menu = true;
- /*_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
- _CrtDumpMemoryLeaks();
- system("pause");*/
- list <Product*> lista;
- //list <int> list1;
- /*_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
- _CrtDumpMemoryLeaks();
- system("pause");*/
- list <Product*>::iterator t;
- int indeks = 1;
- /*Director* pDirector1 = new Director(new ConcreteBuilder1());
- pDirector1->Construct();
- Director* pDirector2 = new Director(new ConcreteBuilder2());
- pDirector2->Construct();
- Director* pDirector3 = new Director(new ConcreteBuilder3());
- pDirector3->Construct();*/
- //delete pDirector1;
- //delete pDirector2;
- //delete pDirector3;
- Director *d;
- while (menu)
- {
- cout << endl << "Wybierz produkt:" << endl << "1: Marynarka" << endl << "2: Spodnie" << endl << "3: Spodniczka" << endl << "4: Wypisz liste produktow" << endl<< "5: Zamknij program"<< endl;
- cout << "1-5: ";
- cin >> produkt;
- /* try
- {
- //if (cin.fail()))
- cin >> produkt;
- }
- catch (cin.fail())
- {
- cerr << blad.what();
- }*/
- /* while(true)
- {
- cin >> produkt;
- try{
- if(cin.fail()){
- throw "error";
- }
- if(produkt>0){
- cout<<"number greater than 0"<<endl;
- }
- }
- catch( char* error){
- cout<<error<<endl;
- break;
- }
- }*/
- switch (produkt)
- {
- case 1:
- {
- //cout << endl << "Wybrales marynarke";
- //Director* pDirector1 = new Director(new ConcreteBuilder1());
- //pDirector1->Construct();
- //ConcreteBuilder1* b = new ConcreteBuilder1();
- //cout << "Tworzenie marynarki" << endl;
- d = new Director(new ConcreteBuilder1());
- break;
- }
- case 2:
- {
- //ConcreteBuilder2* b = new ConcreteBuilder2();
- d = new Director(new ConcreteBuilder2());
- break;
- }
- case 3:
- {
- //ConcreteBuilder3* b = new ConcreteBuilder3();
- d = new Director(new ConcreteBuilder3());
- break;
- }
- case 4:
- {
- //lista.push_back(b->GetProduct());
- // wypisz liste
- cout << endl << endl << "Lista produktow: " << endl;
- for (t = lista.begin(); t != lista.end(); ++t)
- {
- (*t)->Wypisz();//cout << "Nr. zamowienia: " << indeks << ": " << (*t)->Nazwa() << " - Rozmiar: " << (*t)->Rozmiar() << " Material: " << (*t)->Material() << " Kolor: " << (*t)->Kolor() << endl;
- indeks++;
- }
- break;
- }
- case 5:
- {
- menu = false;
- break;
- }
- default:
- {
- cout << "Nie ma takiej opcji!" << endl;
- //break;
- }
- }
- d->Construct();
- lista.push_back(d->Build()->GetProduct());
- delete d;
- }
- /*for (int i = 0; i < lista.max_size(); i++)
- {
- lista.clear;
- }*/
- list <Product*>::iterator temp;
- for (t = lista.begin(); t != lista.end();)
- {
- temp = t;
- t++;
- delete *temp;
- }
- //lista.clear();
- //delete d;
- /*_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
- _CrtDumpMemoryLeaks();
- system("pause");*/
- return 0;
- }
Add Comment
Please, Sign In to add comment