-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBranch.h
88 lines (78 loc) · 2.01 KB
/
Branch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//Student Bshara Haj, 212590186.
//Student Obaeda Khatib, 201278066.
#pragma once
#include "Item.h"
#include "HWExceptions.h"
#include "Computer.h"
#include <vector>
#include <algorithm>
#define BRANCH_SIZE 10
//Branch class
class Branch
{
std::vector<Item*> catalog; //An Array of Item pointers, the store's item catalog
int capacity; //integer to keep track of the current quantity of items in the catalog
string location;
std::vector<Computer*> computers; //An Array of Computers pointers
public:
Branch(std::string location, int capacity); //Constructor
Branch(); // Default constructor
~Branch(); //Destructor
Branch(const Branch& other); //Copy constructor
std::vector<Item*> getCatalog() const; //to get the catalog of items in the branch
string getLocation() const; //get the loaction of teh branch
void addItem(Item* item); //add an item to the catalog
Item* removeItem(int id); //remove item by id
template<class T>
T* giveMeFinest(T* item) const
{
int highPrice = 0;
T* highItem = NULL;
for (int i = 0; i < catalog.size(); i++)
{
if (typeid(*catalog[i]) == typeid(*item))
{
if (catalog[i]->getPrice() > highPrice)
{
highPrice = catalog[i]->getPrice();
(highItem) = (dynamic_cast<T*>(catalog[i]));
}
}
}
if (highItem)
{
if (dynamic_cast<T*>(highItem))
return highItem;
}
else
{
throw NoneExistingItemTypeError();
}
}
/*
template<class T>
T* giveMeFinest(T* item) const
{
int highPrice = 0;
T* highItem = NULL;
std::vector<Item*>::iterator i;
for (i = catalog.begin(); i != catalog.end(); ++i)
{
if (typeid(*i) == typeid(*item))
if ((*i)->getPrice() > highPrice)
{
highPrice = (*i)->getPrice();
(highItem) = (dynamic_cast<T*>(*i));
}
}
if (highItem)
{
if (dynamic_cast<T*>(highItem))
return highItem;
}
else
throw NoneExistingItemTypeError();
}
*/
int getItemsSum() const;
};