Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include<string.h>
- #include<string>
- using namespace std;
- class AlcoholicDrink
- {
- protected:
- char name[100];
- char country[100];
- float percent;
- float baseprice;
- public:
- static int discount;
- virtual float computePrice();
- AlcoholicDrink(){}
- AlcoholicDrink(float percent, char *name, char *country, float baseprice)
- {
- strcpy(this->name,name);
- strcpy(this->country, country);
- this->percent=percent;
- this->baseprice=baseprice;
- }
- ~AlcoholicDrink(){}
- static void total(AlcoholicDrink **ad, int n)
- {
- int totalp=0;
- int totald=0;
- /* for(int i=0;i<n;i++)
- {
- if(discount==0)
- {
- totalp+=ad[i]->computePrice();
- }
- else
- totald+=ad[i]->computePrice();
- }*/
- }
- static void changeDiscount(int d)
- {
- discount=d;
- }
- };
- int discount=5;
- class Beer : public AlcoholicDrink
- {
- private:
- bool ingridient;//BARLEY, WHEAT
- public:
- Beer(){}
- Beer(float percent, char *name, char *country, float baseprice, bool ingridient): AlcoholicDrink(percent,name,country, baseprice)
- {
- this->ingridient=ingridient;
- }
- ~Beer()
- {}
- friend ostream &operator<<(ostream &out, Beer &b)
- {
- out<<b.name<<" "<<b.country<<" "<<b.computePrice()<<endl;
- return out;
- }
- float computePrice()
- {
- float price=0;
- if(strcmp(country,"Germany")==0)
- {
- price+=baseprice*5/100;
- return price;
- }
- else
- return baseprice;
- }
- };
- class Wine: public AlcoholicDrink
- {
- private:
- int year;
- char gtype[20];
- public:
- Wine(float percent,char *name, char *country, float baseprice, int year, char *gtype)
- {
- this->year=year;
- strcpy(this->gtype,gtype);
- }
- ~Wine(){}
- float computePrice()
- {
- float price=0;
- if(strcmp(country,"Italy")==0)
- {
- price+=baseprice*5/100;
- }
- else if(year<2005)
- {
- price+=baseprice*15/100;
- }
- return price;
- }
- friend ostream &operator<<(ostream &out, Wine &w)
- {
- out<<w.name<<" "<<w.country<<" "<<w.computePrice()<<endl;
- return out;
- }
- };
- void lowestPrice(AlcoholicDrink **a, int n)
- {
- int minn=a[0]->computePrice();
- int index;
- for(int i=0;i<n;i++)
- {
- if(a[i]->computePrice()<minn)
- {
- minn=a[i]->computePrice();
- index=i;
- }
- // cout<<a[index]->AlcoholicDrink::name;
- cout<<minn;
- }
- }
- int main() {
- int testCase;
- cin >> testCase;
- float p;
- char name[100];
- char country[100];
- float price;
- bool mainI;
- int year;
- char grape [20];
- if(testCase == 1) {
- cout << "===== TESTING CONSTRUCTORS ======" << endl;
- cin >> p;
- cin >> name;
- cin >> country;
- cin >> price;
- cin >> mainI;
- Beer b(p, name, country, price, mainI);
- cout << b << endl;
- cin >> p;
- cin >> name;
- cin >> country;
- cin >> price;
- cin >> year;
- cin >> grape;
- Wine w(p, name, country, price, year, grape);
- cout << w << endl;
- } else if(testCase == 2) {
- cout << "===== TESTING LOWEST PRICE ======" << endl;
- int n;
- cin >> n;
- AlcoholicDrink** ad = new AlcoholicDrink*[n];
- for(int i = 0; i < n; ++i) {
- cin >> p;
- cin >> name;
- cin >> country;
- cin >> price;
- if(i % 2 == 1){
- cin >> mainI;
- ad[i] = new Beer(p, name, country, price, mainI);
- }
- else {
- cin >> year;
- cin >> grape;
- ad[i] = new Wine(p, name, country, price, year, grape);
- }
- }
- lowestPrice(ad, n);
- for(int i = 0; i < n; ++i) {
- delete ad[i];
- }
- delete [] ad;
- } else if(testCase == 3) {
- cout << "===== TESTING DISCOUNT STATIC ======" << endl;
- int n;
- cin >> n;
- AlcoholicDrink** ad = new AlcoholicDrink*[n];
- for(int i = 0; i < n; ++i) {
- cin >> p;
- cin >> name;
- cin >> country;
- cin >> price;
- if(i % 2 == 1){
- cin >> mainI;
- ad[i] = new Beer(p, name, country, price, mainI);
- }
- else {
- cin >> year;
- cin >> grape;
- ad[i] = new Wine(p, name, country, price, year, grape);
- }
- }
- AlcoholicDrink::total(ad, n);
- int d;
- cin >> d;
- AlcoholicDrink::changeDiscount(d);
- AlcoholicDrink::total(ad, n);
- for(int i = 0; i < n; ++i) {
- delete ad[i];
- }
- delete [] ad;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement