-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathProduct.cpp
43 lines (35 loc) · 1.29 KB
/
Product.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
#include "Product.hpp"
#include <iostream>
#include <iomanip>
Product::Product(std::string productId, std::string name, double price, int quantity)
: productId(productId), name(name), price(price), quantity(quantity), available(true) {}
std::string Product::getProductId() const { return productId; }
std::string Product::getName() const { return name; }
double Product::getPrice() const { return price; }
int Product::getQuantity() const { return quantity; }
bool Product::isAvailable() const { return available && quantity > 0; }
void Product::setPrice(double price) {
this->price = price;
}
void Product::setQuantity(int quantity) {
this->quantity = quantity;
}
void Product::setAvailable(bool status) {
available = status;
}
void Product::addQuantity(int amount) {
quantity += amount;
}
bool Product::removeQuantity(int amount) {
if (amount <= quantity) {
quantity -= amount;
return true;
}
return false;
}
void Product::displayInfo() const {
std::cout << "Product: " << name << " (ID: " << productId << ")" << std::endl;
std::cout << "Price: $" << std::fixed << std::setprecision(2) << price << std::endl;
std::cout << "Quantity: " << quantity << std::endl;
std::cout << "Status: " << (isAvailable() ? "Available" : "Not Available") << std::endl;
}