-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup8-Inventory_Management_System.c
More file actions
149 lines (119 loc) · 3.65 KB
/
Group8-Inventory_Management_System.c
File metadata and controls
149 lines (119 loc) · 3.65 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Product {
int id;
char name[100];
int quantity;
float price;
};
void addProduct(struct Product *inventory, int *count) {
if (*count >= 100) {
printf("Inventory is full. Cannot add more products.\n");
return;
}
struct Product newProduct;
printf("Enter product details:\n");
printf("Product ID: ");
scanf("%d", &newProduct.id);
printf("Product Name: ");
scanf(" %[^\n]", newProduct.name);
printf("Quantity: ");
scanf("%d", &newProduct.quantity);
printf("Price: ");
scanf("%f", &newProduct.price);
inventory[*count] = newProduct;
(*count)++;
printf("Product added successfully.\n");
}
void updateProduct(struct Product *inventory, int count) {
int productId;
int found = 0;
printf("Enter the product ID to update: ");
scanf("%d", &productId);
for (int i = 0; i < count; i++) {
if (inventory[i].id == productId) {
printf("Enter new details for the product:\n");
printf("Product Name: ");
scanf(" %[^\n]", inventory[i].name);
printf("Quantity: ");
scanf("%d", &inventory[i].quantity);
printf("Price: ");
scanf("%f", &inventory[i].price);
printf("Product details updated successfully.\n");
found = 1;
break;
}
}
if (!found) {
printf("Product not found.\n");
}
}
void deleteProduct(struct Product *inventory, int *count) {
int productId;
int found = 0;
printf("Enter the product ID to delete: ");
scanf("%d", &productId);
for (int i = 0; i < *count; i++) {
if (inventory[i].id == productId) {
for (int j = i; j < *count - 1; j++) {
inventory[j] = inventory[j + 1];
}
(*count)--;
printf("Product deleted successfully.\n");
found = 1;
break;
}
}
if (!found) {
printf("Product not found.\n");
}
}
void displayInventory(struct Product *inventory, int count) {
if (count == 0) {
printf("Inventory is empty.\n");
return;
}
printf("Product Inventory:\n");
printf("ID\tName\tQuantity\tPrice\n");
for (int i = 0; i < count; i++) {
printf("%d\t%s\t%d\t\t%.2f\n", inventory[i].id, inventory[i].name, inventory[i].quantity, inventory[i].price);
}
}
int main() {
struct Product inventory[100];
int count = 0;
int choice;
printf("Inventory Management System\n");
while (1) {
printf("\nSelect an option:\n");
printf("1. Add a product\n");
printf("2. Update a product\n");
printf("3. Delete a product\n");
printf("4. Display inventory\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addProduct(inventory, &count);
break;
case 2:
updateProduct(inventory, count);
break;
case 3:
deleteProduct(inventory, &count);
break;
case 4:
displayInventory(inventory, count);
break;
case 5:
printf("Exiting the program...\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
break;
}
}
return 0;
}