Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- class Consumable
- {
- protected:
- bool opened;
- public:
- virtual void readLabel()=0;
- virtual void consume()=0;
- virtual double quantity()=0;
- };
- class Eatable : public Consumable
- {
- protected:
- double massPerPiece;
- int pieces;
- public:
- Eatable(double _massPerPiece=-1,int _pieces=-1)
- {
- this->opened=0;
- this->massPerPiece=_massPerPiece;
- this->pieces=_pieces;
- }
- void readLabel()
- {
- cout<<"Opened: "<<this->opened<<endl;
- cout<<"Mass: "<<this->massPerPiece<<endl;
- cout<<"Pieces: "<<this->pieces<<endl;
- }
- void consume()
- {
- this->opened=1;
- this->pieces--;
- }
- double quantity()
- {
- return this->pieces;
- }
- };
- class Drinkable : public Consumable
- {
- protected:
- double volume;
- public:
- Drinkable(double _volume=-1)
- {
- opened=0;
- this->volume=_volume;
- }
- void readLabel()
- {
- cout<<"Opened: "<<opened<<endl;
- cout<<"Volume: "<<this->volume<<endl;
- }
- void consume()
- {
- opened=1;
- this->volume-=5;
- if(this->volume<0) this->volume = 0;
- }
- double quantity()
- {
- return this->volume;
- }
- };
- class Chocolate : public Eatable
- {
- double cocoa;
- int rows,cols;
- public:
- Chocolate(double _cocoa,int _rows,int _cols,double _massPerPiece,int _pieces)
- {
- this->cocoa=_cocoa;
- this->rows=_rows;
- this->cols=_cols;
- this->massPerPiece=_massPerPiece;
- this->pieces=_pieces;
- }
- void readLabel()
- {
- cout<<"Cocoa: "<<this->cocoa<<endl;
- cout<<"Rows: "<<this->rows<<endl;
- cout<<"Cols: "<<this->cols<<endl;
- cout<<"Mass per piece: "<<this->massPerPiece<<endl;
- cout<<"Pieces: "<<this->pieces<<endl;
- }
- void consume()
- {
- this->opened=1;
- this->pieces--;
- if(this->pieces<0) this->pieces=0;
- }
- double quantity()
- {
- return this->pieces;
- }
- };
- class Beer : public Drinkable
- {
- int alcohol;
- string brand;
- public:
- Beer(int _alcohol,string _brand,double _volume)
- {
- this->alcohol=_alcohol;
- this->brand=_brand;
- this->volume=_volume;
- }
- void readLabel()
- {
- cout<<"Alcohol: "<<this->alcohol<<endl;
- cout<<"Brand: "<<this->brand<<endl;
- cout<<"Volume: "<<this->volume<<endl;
- cout<<"Opened: "<<this->opened<<endl;
- }
- void consume()
- {
- this->opened=1;
- this->volume-=5;
- if(this->volume<0) this->volume=0;
- }
- double quantity()
- {
- return this->volume;
- }
- };
- template<class T>
- class VendingMacine
- {
- vector<vector<T*>> v;
- public:
- static int sn;
- VendingMacine(size_t sz)
- {
- v = vector<vector<T*>>(sz);
- sn++;
- }
- T operator [] (size_t idx)
- {
- if(idx<v.size())
- {
- T ans = v[idx].back();
- v[idx].pop_back();
- return ans;
- }
- }
- void put(size_t idx,T* Tptr)
- {
- if(idx<v.size())
- {
- v[idx].push_back(Tptr);
- }
- }
- bool empty(size_t idx)
- {
- return v[idx].empty();
- }
- };
- template<class T>
- int VendingMacine<T>::sn=0;
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement