-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitial.cpp
More file actions
75 lines (59 loc) · 1.76 KB
/
Copy pathInitial.cpp
File metadata and controls
75 lines (59 loc) · 1.76 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
73
74
75
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
class Product {
public:
Product(const std::string& name, double price, int quantity)
: name(name), price(price), quantity(quantity) {}
double getValue() const {
return price * quantity;
}
void print() const {
std::cout << std::left << std::setw(15) << name
<< " | $" << std::fixed << std::setprecision(2) << price
<< " | " << quantity << " units"
<< " | $" << getValue()
<< '\n';
}
private:
std::string name;
double price;
int quantity;
};
class Warehouse {
public:
void addProduct(const std::string& name, double price, int quantity) {
products.emplace_back(name, price, quantity);
}
double totalValue() const {
double total = 0.0;
for (const auto& product : products) {
total += product.getValue();
}
return total;
}
void printReport() const {
std::cout << "Warehouse Report\n";
std::cout << "================\n";
for (const auto& product : products) {
product.print();
}
std::cout << "================\n";
std::cout << "Total Value: $"
<< std::fixed << std::setprecision(2)
<< totalValue()
<< '\n';
}
private:
std::vector<Product> products;
};
int main() {
Warehouse warehouse;
warehouse.addProduct("Laptop", 899.99, 6);
warehouse.addProduct("Keyboard", 74.50, 15);
warehouse.addProduct("Mouse", 35.99, 24);
warehouse.addProduct("Monitor", 249.99, 10);
warehouse.printReport();
return 0;
}