Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Zadaca 1 pizza
- //
- // Created by Elena Janevska on 1/25/21.
- // Copyright © 2021 Elena Janevska. All rights reserved.
- //
- #include <cstring>
- #include <iostream>
- using namespace std;
- typedef int Size;
- // Your Code goes here
- class Pizza {
- protected:
- char ime[20];
- char sostojki[100];
- double osnovna_cena;
- public:
- Pizza( char *i = "",char *s = "", double oc = 0.0){
- strcpy(ime,i);
- strcpy(sostojki,s);
- osnovna_cena=oc;
- }
- double getCena() const{
- return osnovna_cena;
- }
- const char* get_ime() {
- return ime;
- }
- const char *get_sostojki() {
- return sostojki;
- }
- virtual double price() const =0;
- virtual ~Pizza(){}
- };
- class FlatPizza : public Pizza {
- protected:
- enum{mala,golema,familijarna};
- int golemina;
- public:
- FlatPizza(char *i = "",char *s = "", double oc = 0.0,int g= 0) : Pizza(i,s,oc){
- golemina=g;
- }
- double price() const{
- if(golemina==0){
- return getCena()+0.1*getCena();
- }
- else if(golemina==1){
- return getCena()+ 0.3 * getCena();
- }
- else {
- return getCena()+0.3*getCena();
- }
- return 0;
- }
- int get_golemina() {
- return golemina;
- }
- friend ostream &operator <<(ostream &stream,FlatPizza &fp);
- bool operator <(const FlatPizza &fp) const{
- return price() < fp.price();
- }
- ~FlatPizza(){}
- };
- ostream &operator <<(ostream &stream,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");
- }
- stream<<fp.ime<<": "<<fp.sostojki<<", ";
- if(fp.golemina == 0) {
- stream << "small ";
- }
- else if(fp.golemina == 1) {
- stream << "large ";
- }
- else {
- stream << "family ";
- }
- stream<<"- "<<fp.price()<<endl;
- return stream;
- };
- class FoldedPizza : public Pizza {
- protected:
- bool testo;
- public:
- FoldedPizza(char *i = "",char *s = "", double oc = 0.0,bool t = true) : Pizza(i,s,oc){
- testo=t;
- }
- double price() const{
- if(testo){
- return getCena()+getCena()*0.1;
- }
- else{
- return getCena()+getCena()*0.3;
- }
- }
- bool get_flour() {
- return testo;
- }
- void setWhiteFlour(bool b){
- testo = b;
- }
- friend ostream &operator <<(ostream &stream,FoldedPizza &fp);
- bool operator <(FoldedPizza &fp) const{
- return price() < fp.price();
- }
- bool operator <(FlatPizza &fp) const{
- return price() < fp.price();
- }
- ~FoldedPizza(){}
- };
- bool operator < (const FlatPizza &fp, const FoldedPizza &ip) {
- return fp.price() < ip.price();
- }
- ostream &operator <<(ostream &stream,FoldedPizza &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");
- }
- stream<<fp.ime<<": " << fp.sostojki << ", ";
- if(fp.testo){
- stream<<"wf - ";
- }
- else{
- stream<<"nwf - ";
- }
- stream<<fp.price() << endl;
- return stream;
- };
- void expensivePizza(Pizza **niza,int n){
- int max=0;
- int pom=0;
- for(int i=0;i<n;i++){
- if(niza[i]->price()>max){
- max=niza[i]->price();
- pom=i;
- }
- }
- if(dynamic_cast<FlatPizza*>(niza[pom])) {
- Pizza *tmp = niza[pom];
- FlatPizza *p = dynamic_cast<FlatPizza *>(tmp);
- cout << *p;
- }
- else {
- Pizza *tmp = niza[pom];
- FoldedPizza *p = dynamic_cast<FoldedPizza *>(tmp);
- cout << *p;
- }
- }
- // Testing
- int main() {
- int test_case;
- char name[20];
- char ingredients[100];
- float inPrice;
- 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