Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstring>
- using namespace std;
- class Discount
- {
- public:
- static float euro;
- static float dollar;
- virtual float discount_price()=0;
- virtual float price()=0;
- virtual void print_rule()=0;
- };
- float Discount::euro=61.7;
- float Discount::dollar=44.5;
- class Product
- {
- protected:
- char name[20];
- float price;
- public:
- Product(const char *name="", const float price=0.0)
- {
- try
- {
- if(price < 0)
- {
- throw 1;
- }
- strcpy(this->name,name);
- this->price=price;
- }
- catch(int)
- {
- cout<<"Pogresno vnesena cena.Frlen e isklucok"<<endl;
- this->price=0.0;
- }
- }
- float getPrice()
- {
- return this->price;
- }
- };
- class Cosmetics: public Product, public Discount
- {
- private:
- int weight;
- public:
- Cosmetics(char *name="", float price=0.0,int weight=0):Product(name,price)
- {
- this->weight=weight;
- }
- float discount_price()
- {
- if(5*Discount::euro < getPrice())
- return getPrice()*0.88;
- if(20*Discount::dollar < getPrice())
- return getPrice()*0.86;
- return getPrice();
- }
- float price()
- {
- return getPrice();
- }
- void print_rule()
- {
- cout<<"Popust na kozmetika"<<endl;
- }
- };
- class FoodProduct: public Product,public Discount
- {
- private:
- float callories;
- public:
- FoodProduct(char *name="", float price=0.0,float callories=0.0):Product(name,price)
- {
- this->callories=callories;
- }
- float discount_price()
- {
- return getPrice();
- }
- float price()
- {
- return getPrice();
- }
- void print_rule()
- {
- cout<<"Nema popoust na hrana"<<endl;
- }
- };
- class Drinks:public Discount,public Product
- {
- private:
- bool alcoholic;
- char brand[100];
- public:
- Drinks(char *name="", float price=0.0,char *brand="",bool alcoholic=false):Product(name,price)
- {
- this->alcoholic=alcoholic;
- strcpy(this->brand,brand);
- }
- float discount_price()
- {
- if(alcoholic)
- {
- if(20*Discount::euro < getPrice())
- return getPrice()*0.95;
- }
- else
- {
- if(strcmp(this->brand,"Coca-Cola")==0)
- return getPrice()*0.9;
- }
- return getPrice();
- }
- float price()
- {
- return getPrice();
- }
- void print_rule()
- {
- cout<<"Popust na pijaloci"<<endl;
- }
- };
- float total_discount(Discount **d,int n)
- {
- float total=0.0;
- for(int i=0; i<n; i++)
- {
- total+=d[i]->discount_price();
- cout<<"Prvicna cena: "<<d[i]->price()<<endl;
- cout<<"So popust: "<<d[i]->discount_price()<<endl;
- d[i]->print_rule();
- }
- return total;
- }
- int main()
- {
- int n=7;
- Discount **d=new Discount*[n];
- d[0]=new FoodProduct("leb",-30);
- d[1]=new Drinks("viski",1350,"Jack Daniel's", true);
- d[2]=new FoodProduct("sirenje",390,105);
- d[3]=new Drinks("votka",850,"Finlandia",true);
- d[4]=new Cosmetics("krema",72,100);
- d[5]=new Drinks("sok",50,"Coca-Cola",false);
- d[6]=new Cosmetics("parfem",3500,50);
- cout << "Vkupnata cena na site proizvodi e: "<<total_discount(d, n)<< endl;
- for(int i = 0; i < n; ++i) {
- delete d[i];
- }
- delete [] d;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment