-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProduct.h
More file actions
72 lines (57 loc) · 1.37 KB
/
Product.h
File metadata and controls
72 lines (57 loc) · 1.37 KB
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
#ifndef Product_H
#define Product_H
#include <string>
#include <ostream>
class Product {
private:
int product_id;
int supplier_id;
std::string p_name;
std::string description;
float price;
int qty;
public:
// Default constructor
Product() : product_id(0), supplier_id(0), p_name(""), description(""), price(0.0f), qty(0) {}
Product(
int product_id,
int supplier_id,
std::string& p_name,
std::string& description,
float price,
int qty
) : product_id(product_id),
supplier_id(supplier_id),
p_name(p_name),
description(description),
price(price),
qty(qty) {}
const int getProductID() {
return product_id;
}
const int getSupplierID() {
return supplier_id;
}
const std::string& getName() {
return p_name;
}
const std::string& getDescription() {
return description;
}
const float getPrice() {
return price;
}
const int getQuantity() {
return qty;
}
friend std::ostream& operator<<(std::ostream& os, const Product& product) {
os << "<Product ID(" << product.product_id << "), supplier_id(" << product.supplier_id << "), name(" << product.p_name << "), Price(" << product.price << "), Qty in stock(" << product.qty << ")/>";
return os;
}
// product_id is always a positive integer for references that actually work
// so if it's zero, return true for if (!product)
bool operator!() const {
return product_id == 0;
}
};
#endif