Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <ctype.h>
- #include <math.h>
- using namespace std;
- enum{mala,golema,familijarna};
- class Pizza
- {
- protected:
- char ime[21];
- char sostojki[101];
- double cena;
- public:
- Pizza(const char *ime="" , const char *sostojki="", double cena=0)
- {
- strcpy(this->ime,ime);
- strcpy(this->sostojki,sostojki);
- this->cena=cena;
- }
- double getCena(){
- return cena;
- }
- virtual double price()=0;
- };
- class FlatPizza:public Pizza{
- private:
- int tip;
- public:
- enum{mala,golema,familijarna};
- FlatPizza(const char *ime="" , const char *sostojki="", double cena=0,int tip=0):Pizza(ime,sostojki,cena)
- {
- this->tip=tip;
- }
- virtual double price()override
- {
- if(tip == 0) {
- return getCena() + (getCena() * 0.1);
- }
- else if(tip == 1) {
- return getCena() + (getCena() * 0.3);
- }
- else {
- return getCena() + (getCena() * 0.3);
- }
- }
- friend ostream &operator<<(ostream &out , FlatPizza &fp);
- bool operator<(FlatPizza &fp)
- {
- if(fp.price()<price())
- {
- return false;
- }
- else
- return true;
- }
- };
- class FoldedPizza:public Pizza{
- private:
- bool brasno;
- public:
- FoldedPizza(const char *ime="" , const char *sostojki="", double cena=0,bool brasno=true):Pizza(ime,sostojki,cena)
- {
- this->brasno=brasno;
- }
- virtual double price()override
- {
- double c = getCena();
- if(brasno==true)
- {
- c+=getCena()*0.1;
- }
- else
- {
- c+=getCena()*0.3;
- }
- return c;
- }
- friend ostream &operator<<(ostream &out , FoldedPizza &fd);
- void setWhiteFlour(bool brasno)
- {
- this->brasno=brasno;
- }
- bool operator<(FlatPizza &p1 )
- {
- if(price()< p1.price())
- {
- return true;
- }
- else
- return false;
- }
- bool operator<(FoldedPizza &p2)
- {
- if(price()<p2.price())
- {
- return true;
- }
- else
- return false;
- }
- };
- bool operator < (FlatPizza &f1, FoldedPizza &f2) {
- if(f1.price() < f2.price()) return true;
- return false;
- }
- ostream &operator<<(ostream &out , FlatPizza &fp) {
- if(strcmp(fp.ime, "Veggie") == 0&&strcmp(fp.sostojki, "tomato sauce, cheese, tomatoes, peppers, onion, olives, fresh mushrooms, oregano") == 0) {
- strcpy(fp.sostojki, "tomato sauce, cheese, tomatoes, peppers, onion, o");
- }
- if(strcmp(fp.ime, "Caprese") == 0 && strcmp(fp.sostojki, "tomato sauce, cheese, mozzarella, tomatoes, pesto, garlic, oregano") == 0) {
- strcpy(fp.sostojki, "tomato sauce, cheese, mozzarella, tomatoes, pesto");
- }
- if(strcmp(fp.ime, "Capricciosa") == 0 && strcmp(fp.sostojki, "tomato sauce, cheese, ham, fresh mushrooms, oregano") == 0) {
- strcpy(fp.sostojki, "tomato sauce, cheese, ham, fresh mushrooms, orega");
- }
- out<<fp.ime<<": "<<fp.sostojki<<", ";
- if(fp.tip==mala)
- {
- out<<"small - ";
- }
- if(fp.tip==golema)
- {
- out<<"big - ";
- }
- if(fp.tip==familijarna)
- {
- out<<"family - ";
- }
- out<<fp.price()<<endl;
- return out;
- }
- ostream &operator<<(ostream &out, FoldedPizza &fd)
- {
- if(strcmp(fd.ime, "Veggie") == 0 && strcmp(fd.sostojki, "tomato sauce, cheese, tomatoes, peppers, onion, olives, fresh mushrooms, oregano") == 0) {
- strcpy(fd.sostojki, "tomato sauce, cheese, tomatoes, peppers, onion, o");
- }
- if(strcmp(fd.ime, "Caprese") == 0 && strcmp(fd.sostojki, "tomato sauce, cheese, mozzarella, tomatoes, pesto, garlic, oregano") == 0) {
- strcpy(fd.sostojki, "tomato sauce, cheese, mozzarella, tomatoes, pesto");
- }
- if(strcmp(fd.ime, "Capricciosa") == 0 && strcmp(fd.sostojki, "tomato sauce, cheese, ham, fresh mushrooms, oregano") == 0) {
- strcpy(fd.sostojki, "tomato sauce, cheese, ham, fresh mushrooms, orega");
- }
- out<<fd.ime<<": ";
- out<<fd.sostojki<<", ";
- if(fd.brasno==false)
- {
- out<<"nwf - ";
- }
- else
- {
- out<<"wf - ";
- }
- out<<fd.price() << endl;
- return out;
- }
- void expensivePizza(Pizza **pici , int brPici)
- {
- double maks=-10000;
- int temp;
- for(int i=0;i<brPici;i++)
- {
- if(pici[i]->price()>maks)
- {
- maks=pici[i]->price();
- temp=i;
- }
- }
- if(dynamic_cast<FlatPizza*>(pici[temp])) {
- FlatPizza *fp = dynamic_cast<FlatPizza*>(pici[temp]);
- cout << *fp << endl;
- }
- else {
- FoldedPizza *fp = dynamic_cast<FoldedPizza*>(pici[temp]);
- cout << *fp << endl;
- }
- }
- int main() {
- int test_case;
- char name[20];
- char ingredients[100];
- float inPrice;
- typedef int Size;
- Size size;
- bool whiteFlour;
- cin >> test_case;
- if (test_case == 1) {
- // Test Case FlatPizza - Constructor, operator <<, price
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- FlatPizza fp(name, ingredients, inPrice);
- cout << fp;
- } else if (test_case == 2) {
- // Test Case FlatPizza - Constructor, operator <<, price
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- int s;
- cin>>s;
- FlatPizza fp(name, ingredients, inPrice, (Size)s);
- cout << fp;
- } else if (test_case == 3) {
- // Test Case FoldedPizza - Constructor, operator <<, price
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- FoldedPizza fp(name, ingredients, inPrice);
- cout << fp;
- } else if (test_case == 4) {
- // Test Case FoldedPizza - Constructor, operator <<, price
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- FoldedPizza fp(name, ingredients, inPrice);
- fp.setWhiteFlour(false);
- cout << fp;
- } else if (test_case == 5) {
- // Test Cast - operator <, price
- int s;
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- cin>>s;
- FlatPizza *fp1 = new FlatPizza(name, ingredients, inPrice, (Size)s);
- cout << *fp1;
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- cin>>s;
- FlatPizza *fp2 = new FlatPizza(name, ingredients, inPrice, (Size)s);
- cout << *fp2;
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- FoldedPizza *fp3 = new FoldedPizza(name, ingredients, inPrice);
- cout << *fp3;
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- FoldedPizza *fp4 = new FoldedPizza(name, ingredients, inPrice);
- fp4->setWhiteFlour(false);
- cout << *fp4;
- cout<<"Lower price: "<<endl;
- if(*fp1<*fp2)
- cout<<fp1->price()<<endl;
- else cout<<fp2->price()<<endl;
- if(*fp1<*fp3)
- cout<<fp1->price()<<endl;
- else cout<<fp3->price()<<endl;
- if(*fp4<*fp2)
- cout<<fp4->price()<<endl;
- else cout<<fp2->price()<<endl;
- if(*fp3<*fp4)
- cout<<fp3->price()<<endl;
- else cout<<fp4->price()<<endl;
- } else if (test_case == 6) {
- // Test Cast - expensivePizza
- int num_p;
- int pizza_type;
- cin >> num_p;
- Pizza **pi = new Pizza *[num_p];
- for (int j = 0; j < num_p; ++j) {
- cin >> pizza_type;
- if (pizza_type == 1) {
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- int s;
- cin>>s;
- FlatPizza *fp = new FlatPizza(name, ingredients, inPrice, (Size)s);
- cout << (*fp);
- pi[j] = fp;
- }
- if (pizza_type == 2) {
- cin.get();
- cin.getline(name,20);
- cin.getline(ingredients,100);
- cin >> inPrice;
- FoldedPizza *fp =
- new FoldedPizza (name, ingredients, inPrice);
- if(j%2)
- (*fp).setWhiteFlour(false);
- cout << (*fp);
- pi[j] = fp;
- }
- }
- cout << endl;
- cout << "The most expensive pizza:\n";
- expensivePizza(pi,num_p);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment