-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.cpp
60 lines (45 loc) · 1.24 KB
/
Item.cpp
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
//Student Bshara Haj, 212590186.
//Student Obaeda Khatib, 201278066.
#pragma once
#include "Item.h"
int Item::nextId = 1;
Item::Item(int price, const std::string& manufacturer)
: id(nextId++), price(price), manufacturer(manufacturer) //Constructor for the Item class
{
}
Item::~Item() //Destructor for the Item class
{
std::cout << "Throwing away an item" << std::endl;
}
int Item::getId() const //to get Id
{
return this->id;
}
int Item::getPrice() const //to get price
{
return this->price;
}
void Item::setPrice(int price) //to set the price
{
this->price = price;
}
string Item::getManufacturer() const //to get manufacturer
{
return this->manufacturer;
}
void Item::setManufacturer(const string& manufacturer) //to set manufacturer
{
this->manufacturer = manufacturer;
}
string Item::toString() const //to get a string representation of the Item
{
return "id " + std::to_string(id) + ": " + manufacturer + " " + std::to_string(price) + "$, ";
}
Item::operator string() const //Overloaded operator to convert the item to a string
{
return toString();
}
bool Item::itemPtrCompare(const Item* a, const Item* b)
{
return a->getId() < b->getId();
}