Here's a simplified C program to manage a shopping mall's inventory and sales:
Shopping Mall Management System
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define structure for products
typedef struct {
int id;
char name[50];
float price;
int quantity;
} Product;
// Function to add products
void addProduct(Product *products, int *productCount) {
printf("Enter product ID: ");
scanf("%d", &products[*productCount].id);
printf("Enter product name: ");
scanf("%s", products[*productCount].name);
printf("Enter product price: ");
scanf("%f", &products[*productCount].price);
printf("Enter product quantity: ");
scanf("%d", &products[*productCount].quantity);
(*productCount)++;
}
// Function to display products
void displayProducts(Product *products, int productCount) {
printf("Product List:\n");
for (int i = 0; i < productCount; i++) {
printf("ID: %d, Name: %s, Price: %.2f, Quantity: %d\n",
products[i].id, products[i].name, products[i].price, products[i].quantity);
}
}
// Function to sell products
void sellProduct(Product *products, int productCount) {
int productId;
printf("Enter product ID to sell: ");
scanf("%d", &productId);
for (int i = 0; i < productCount; i++) {
if (products[i].id == productId) {
if (products[i].quantity > 0) {
products[i].quantity--;
printf("Product sold successfully!\n");
} else {
printf("Product out of stock!\n");
}
return;
}
}
printf("Product not found!\n");
}
int main() {
Product products[100];
int productCount = 0;
int choice;
while (1) {
printf("Shopping Mall Management System\n");
printf("1. Add Product\n");
printf("2. Display Products\n");
printf("3. Sell Product\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addProduct(products, &productCount);
break;
case 2:
displayProducts(products, productCount);
break;
case 3:
sellProduct(products, productCount);
break;
case 4:
exit(0);
default:
printf("Invalid choice!\n");
}
}
return 0;
}
This program allows users to:
1. Add products to the inventory
2. Display the list of products
3. Sell products (reduce quantity)
Note that this is a simplified program and doesn't include features like user authentication, data validation, or file persistence.
No comments:
Post a Comment