Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Tree.h"
- #include <exception>
- using namespace std;
- class Band{
- public:
- Band(int bandID, int price, int votes=0): bandID(bandID), price(price), votes(votes){};
- ...
- private:
- ...
- };
- class Festival{
- public:
- Festival(int budget): budget(budget), minPrice(0), maxNeededBudget(0), priceOffset(0), bandCounter(0){};
- ~Festival();
- StatusType AddBand(int bandID, int price, int votes=0);
- ...
- private:
- Tree<Band> bandTree;
- ...
- };
- StatusType Festival::AddBand(int bandID, int price, int votes){
- if ((price<0)||(bandID<0)){
- return INVALID_INPUT;
- }
- Band* newBand=NULL;
- try{
- newBand=new Band(bandID,price-priceOffset,votes);
- }
- catch(bad_alloc&){return ALLOCATION_ERROR;}
- if (bandTree.find(*newBand)!=NULL){
- delete newBand;
- return FAILURE;
- }
- bandTree.add(*newBand);
- ....
- }
- template<class T>
- class Tree{
- public:
- Tree(T* initialData=NULL, Tree<T>* initialFather=NULL);
- void add(T& newData);
- ....
- private:
- ....
- };
- void Tree::add(T& newData)
- {
- newData.destroyEverything();
- }
- void Tree::add(int& newData)
- {
- newData.destroyEverything();
- }
- Band* newBand=NULL;
- try{
- newBand=new Band(bandID,price-priceOffset,votes);
- }
- catch(bad_alloc&){return ALLOCATION_ERROR;}
- Band * newBand = new Band ( bandID, price - priceOffset, votes );
- Band newBand( bandID, price - priceOffset, votes );
- priceTree.add(*newPriceNode);
- priceTree.add(newPriceNode); //no "*" before "newPriceNode"
Add Comment
Please, Sign In to add comment