-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPharmacy Management System project.cpp
75 lines (60 loc) · 1.78 KB
/
Pharmacy Management System project.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <vector>
class Medicine {
public:
Medicine(const std::string &name, int stock, double price)
: name(name), stock(stock), price(price) {}
void displayInfo() const {
std::cout << "Medicine Name: " << name << "\n";
std::cout << "Stock: " << stock << "\n";
std::cout << "Price: $" << price << "\n";
}
void sell(int quantity) {
if (quantity <= stock) {
stock -= quantity;
std::cout << "Sold " << quantity << " units of " << name << "\n";
} else {
std::cout << "Not enough stock for " << name << "\n";
}
}
private:
std::string name;
int stock;
double price;
};
class Pharmacy {
public:
void addMedicine(const Medicine &medicine) {
medicines.push_back(medicine);
}
void displayMedicines() const {
std::cout << "Medicine Inventory:\n";
for (const Medicine &medicine : medicines) {
medicine.displayInfo();
std::cout << "\n";
}
}
void sellMedicine(int index, int quantity) {
if (index >= 0 && index < medicines.size()) {
medicines[index].sell(quantity);
} else {
std::cout << "Invalid medicine index.\n";
}
}
private:
std::vector<Medicine> medicines;
};
int main() {
Pharmacy pharmacy;
Medicine medicine1("Aspirin", 100, 5.99);
Medicine medicine2("Antibiotic", 50, 10.99);
pharmacy.addMedicine(medicine1);
pharmacy.addMedicine(medicine2);
pharmacy.displayMedicines();
pharmacy.sellMedicine(0, 20);
pharmacy.sellMedicine(1, 10);
pharmacy.sellMedicine(0, 100);
pharmacy.displayMedicines();
return 0;
}