kristina7

Auditoriski Isklucoci

May 3rd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. class Discount
  6. {
  7. public:
  8.     static float euro;
  9.     static float dollar;
  10.     virtual float discount_price()=0;
  11.     virtual float price()=0;
  12.     virtual void print_rule()=0;
  13. };
  14. float Discount::euro=61.7;
  15. float Discount::dollar=44.5;
  16.  
  17. class Product
  18. {
  19. protected:
  20.     char name[20];
  21.     float price;
  22. public:
  23.     Product(const char *name="", const float price=0.0)
  24.     {
  25.         try
  26.         {
  27.             if(price < 0)
  28.             {
  29.                 throw 1;
  30.             }
  31.             strcpy(this->name,name);
  32.             this->price=price;
  33.         }
  34.         catch(int)
  35.         {
  36.             cout<<"Pogresno vnesena cena.Frlen e isklucok"<<endl;
  37.             this->price=0.0;
  38.         }
  39.     }
  40.     float getPrice()
  41.     {
  42.         return this->price;
  43.     }
  44. };
  45. class Cosmetics: public Product, public Discount
  46. {
  47. private:
  48.     int weight;
  49. public:
  50.     Cosmetics(char *name="", float price=0.0,int weight=0):Product(name,price)
  51.     {
  52.         this->weight=weight;
  53.     }
  54.     float discount_price()
  55.     {
  56.         if(5*Discount::euro < getPrice())
  57.             return getPrice()*0.88;
  58.         if(20*Discount::dollar < getPrice())
  59.             return getPrice()*0.86;
  60.         return getPrice();
  61.     }
  62.     float price()
  63.     {
  64.         return getPrice();
  65.     }
  66.     void print_rule()
  67.     {
  68.         cout<<"Popust na kozmetika"<<endl;
  69.     }
  70. };
  71.  
  72. class FoodProduct: public Product,public Discount
  73. {
  74. private:
  75.     float callories;
  76. public:
  77.     FoodProduct(char *name="", float price=0.0,float callories=0.0):Product(name,price)
  78.     {
  79.         this->callories=callories;
  80.     }
  81.     float discount_price()
  82.     {
  83.         return getPrice();
  84.     }
  85.     float price()
  86.     {
  87.         return getPrice();
  88.     }
  89.     void print_rule()
  90.     {
  91.         cout<<"Nema popoust na hrana"<<endl;
  92.     }
  93. };
  94.  
  95. class Drinks:public Discount,public Product
  96. {
  97. private:
  98.     bool alcoholic;
  99.     char brand[100];
  100. public:
  101.     Drinks(char *name="", float price=0.0,char *brand="",bool alcoholic=false):Product(name,price)
  102.     {
  103.         this->alcoholic=alcoholic;
  104.         strcpy(this->brand,brand);
  105.     }
  106.     float discount_price()
  107.     {
  108.         if(alcoholic)
  109.         {
  110.             if(20*Discount::euro < getPrice())
  111.                 return getPrice()*0.95;
  112.         }
  113.         else
  114.         {
  115.             if(strcmp(this->brand,"Coca-Cola")==0)
  116.                 return getPrice()*0.9;
  117.         }
  118.         return getPrice();
  119.     }
  120.     float price()
  121.     {
  122.         return getPrice();
  123.     }
  124.     void print_rule()
  125.     {
  126.         cout<<"Popust na pijaloci"<<endl;
  127.     }
  128. };
  129. float total_discount(Discount **d,int n)
  130. {
  131.     float total=0.0;
  132.     for(int i=0; i<n; i++)
  133.     {
  134.         total+=d[i]->discount_price();
  135.         cout<<"Prvicna cena: "<<d[i]->price()<<endl;
  136.         cout<<"So popust: "<<d[i]->discount_price()<<endl;
  137.         d[i]->print_rule();
  138.     }
  139.     return total;
  140. }
  141. int main()
  142. {
  143.     int n=7;
  144.     Discount **d=new Discount*[n];
  145.     d[0]=new FoodProduct("leb",-30);
  146.     d[1]=new Drinks("viski",1350,"Jack Daniel's", true);
  147.     d[2]=new FoodProduct("sirenje",390,105);
  148.     d[3]=new Drinks("votka",850,"Finlandia",true);
  149.     d[4]=new Cosmetics("krema",72,100);
  150.     d[5]=new Drinks("sok",50,"Coca-Cola",false);
  151.     d[6]=new Cosmetics("parfem",3500,50);
  152.     cout << "Vkupnata cena na site proizvodi e: "<<total_discount(d, n)<< endl;
  153.          for(int i = 0; i < n; ++i) {
  154.          delete d[i];
  155.      }
  156.          delete [] d;
  157.          return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment