-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3.cpp
More file actions
72 lines (60 loc) · 1.52 KB
/
Task3.cpp
File metadata and controls
72 lines (60 loc) · 1.52 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
#include <iostream>
#include <vector>
using namespace std;
struct Product {
int id;
string name;
int quantity;
};
vector<Product> inventory;
void addProduct() {
Product p;
cout << "Enter Product ID: ";
cin >> p.id;
cout << "Enter Product Name: ";
cin >> p.name;
cout << "Enter Quantity: ";
cin >> p.quantity;
inventory.push_back(p);
cout << "✅ Product Added!\n";
}
void updateProduct() {
int id;
cout << "Enter Product ID to update: ";
cin >> id;
for (auto &p : inventory) {
if (p.id == id) {
cout << "Enter new quantity: ";
cin >> p.quantity;
cout << "✅ Updated!\n";
return;
}
}
cout << "❌ Product not found!\n";
}
void displayProducts() {
cout << "\n📦 Inventory:\n";
for (auto p : inventory) {
cout << "ID: " << p.id << " | Name: " << p.name << " | Qty: " << p.quantity << endl;
}
}
int main() {
int choice;
do {
cout << "\n--- Inventory Menu ---\n";
cout << "1. Add Product\n";
cout << "2. Update Product\n";
cout << "3. Display Products\n";
cout << "4. Exit\n";
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1: addProduct(); break;
case 2: updateProduct(); break;
case 3: displayProducts(); break;
case 4: cout << "Exiting...\n"; break;
default: cout << "Invalid choice!\n";
}
} while (choice != 4);
return 0;
}