Guest User

Untitled

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include "Tree.h"
  2. #include <exception>
  3.  
  4. using namespace std;
  5.  
  6. class Band{
  7. public:
  8. Band(int bandID, int price, int votes=0): bandID(bandID), price(price), votes(votes){};
  9. ...
  10. private:
  11. ...
  12.  
  13. };
  14.  
  15. class Festival{
  16. public:
  17. Festival(int budget): budget(budget), minPrice(0), maxNeededBudget(0), priceOffset(0), bandCounter(0){};
  18. ~Festival();
  19. StatusType AddBand(int bandID, int price, int votes=0);
  20. ...
  21.  
  22. private:
  23. Tree<Band> bandTree;
  24. ...
  25.  
  26. };
  27.  
  28. StatusType Festival::AddBand(int bandID, int price, int votes){
  29. if ((price<0)||(bandID<0)){
  30. return INVALID_INPUT;
  31. }
  32. Band* newBand=NULL;
  33. try{
  34. newBand=new Band(bandID,price-priceOffset,votes);
  35. }
  36. catch(bad_alloc&){return ALLOCATION_ERROR;}
  37. if (bandTree.find(*newBand)!=NULL){
  38. delete newBand;
  39. return FAILURE;
  40. }
  41. bandTree.add(*newBand);
  42. ....
  43. }
  44.  
  45. template<class T>
  46. class Tree{
  47. public:
  48. Tree(T* initialData=NULL, Tree<T>* initialFather=NULL);
  49. void add(T& newData);
  50. ....
  51. private:
  52. ....
  53. };
  54.  
  55. void Tree::add(T& newData)
  56. {
  57. newData.destroyEverything();
  58. }
  59.  
  60. void Tree::add(int& newData)
  61. {
  62. newData.destroyEverything();
  63. }
  64.  
  65. Band* newBand=NULL;
  66. try{
  67. newBand=new Band(bandID,price-priceOffset,votes);
  68. }
  69. catch(bad_alloc&){return ALLOCATION_ERROR;}
  70.  
  71. Band * newBand = new Band ( bandID, price - priceOffset, votes );
  72.  
  73. Band newBand( bandID, price - priceOffset, votes );
  74.  
  75. priceTree.add(*newPriceNode);
  76.  
  77. priceTree.add(newPriceNode); //no "*" before "newPriceNode"
Add Comment
Please, Sign In to add comment